Skip to content

refactor(ccv2): rename BidiComponentResult to ComponentResult#14253

Merged
sfc-gh-bnisco merged 1 commit intodevelopfrom
03-06-refactor_ccv2_rename_bidicomponentresult_to_componentresult
Mar 9, 2026
Merged

refactor(ccv2): rename BidiComponentResult to ComponentResult#14253
sfc-gh-bnisco merged 1 commit intodevelopfrom
03-06-refactor_ccv2_rename_bidicomponentresult_to_componentresult

Conversation

@sfc-gh-bnisco
Copy link
Copy Markdown
Collaborator

@sfc-gh-bnisco sfc-gh-bnisco commented Mar 6, 2026

Describe your changes

  • Promote ComponentResult as the canonical CCV2 result type across the public API, internal type hints, and docstrings to align naming with the rest of the v2 surface.
  • Keep BidiComponentResult as a backward-compatible alias to avoid breaking existing imports and user code. Update tests and e2e typing annotations to use ComponentResult, and add explicit compatibility coverage for the alias.

Screenshot or video (only for visual changes)

GitHub Issue Link (if applicable)

Testing Plan

  • Adds a backwards compat test

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 6, 2026

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-14253/streamlit-1.55.0-py3-none-any.whl
📦 @streamlit/component-v2-lib Download from artifacts
🕹️ Preview app pr-14253.streamlit.app (☁️ Deploy here if not accessible)

@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Mar 6, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@sfc-gh-bnisco sfc-gh-bnisco added change:refactor PR contains code refactoring without behavior change impact:users PR changes affect end users labels Mar 6, 2026 — with Graphite App
@sfc-gh-bnisco sfc-gh-bnisco requested a review from Copilot March 6, 2026 23:27
@sfc-gh-bnisco sfc-gh-bnisco added the ai-review If applied to PR or issue will run AI review workflow label Mar 6, 2026
@github-actions github-actions bot removed the ai-review If applied to PR or issue will run AI review workflow label Mar 6, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 6, 2026

Summary

This PR renames BidiComponentResult to ComponentResult as the canonical result type for Custom Components v2 (CCV2). The rename is applied across the public API, internal type hints, docstrings, unit tests, and e2e test annotations (10 files changed). BidiComponentResult is retained as a backward-compatible alias (BidiComponentResult = ComponentResult) to avoid breaking existing user imports. There are zero runtime behavioral changes.

Code Quality

Reviewers unanimously agree the refactoring is clean, consistent, and low-risk:

  • The rename is applied uniformly across all internal usage sites (imports, type hints, docstrings, instantiations).
  • The backward-compatible alias in lib/streamlit/components/v2/bidi_component/state.py is implemented as a simple class assignment, which correctly preserves isinstance() checks and identity.
  • The __init__.py at lib/streamlit/components/v2/bidi_component/__init__.py properly exports both BidiComponentResult and ComponentResult, ensuring both import paths remain valid.
  • Docstrings in state.py, main.py, types.py, and __init__.py are all updated to reference ComponentResult.
  • The code follows existing patterns and conventions in the codebase.

No issues identified.

Test Coverage

Reviewers unanimously agree test coverage is adequate for this rename-with-alias refactor:

  • Unit tests updated: test_state.py and test_bidi_component.py now use ComponentResult throughout.
  • Backward-compatibility test added: test_bidi_component_result_alias_remains_supported() explicitly asserts identity (BidiComponentResult is ComponentResult), isinstance() compatibility, and construction via the old name.
  • E2E test annotations updated: basics.py and session_state_interactions.py use the new name in type hints.
  • The existing comprehensive test suite for CCV2 provides strong implicit coverage since behavior is unchanged.

Backwards Compatibility

Reviewers unanimously agree there are no breaking changes:

  1. BidiComponentResult remains importable from streamlit.components.v2.bidi_component (both the package __init__.py and the state module).
  2. The alias means isinstance(), type(), and identity checks all work transparently.
  3. Existing user code using the old import paths will continue to work without modification.
  4. ComponentResult is not (and BidiComponentResult was not) exported from the top-level streamlit namespace, so this is a submodule-level rename with a compat alias.

Security & Risk

Reviewers unanimously agree there are no security concerns. This is a pure naming refactoring with no changes to WebSocket handling, authentication, file serving, or any security-sensitive code paths. Regression risk is minimal and limited to type-name/documentation consistency, which is covered by updated tests.

External test recommendation

  • Recommend external_test: No
  • Triggered categories: None
  • Confidence: High — all changes are limited to renaming a Python class and updating type annotations/docstrings. No behavioral changes to the component rendering pipeline, frontend communication, or state management.

Accessibility

Not applicable. No frontend UI/component implementation files were changed; no DOM interaction behavior changed. Accessibility impact is neutral.

Recommendations

No blocking issues. Two minor non-blocking suggestions:

  1. Alias comment wording (non-blocking): The comment at lib/streamlit/components/v2/bidi_component/state.py says "Deprecated alias" while the PR description frames it as a "backward-compatible alias." If the intent is to eventually remove BidiComponentResult, "deprecated" is correct and a DeprecationWarning could be considered in a future PR. If it's intended to remain indefinitely, consider softening the comment to "Legacy alias kept for backwards compatibility." (Raised by opus-4.6-thinking)

  2. Optional typing test (non-blocking): Consider adding a typing test in lib/tests/streamlit/typing/ that asserts the return type of CCV2 callables remains compatible with ComponentResult (and optionally alias import compatibility), to lock in public typing guarantees. (Raised by gpt-5.3-codex-high)

Reviewer Agreement

Aspect gpt-5.3-codex-high opus-4.6-thinking
Verdict APPROVED APPROVED
Code Quality Clean, no issues Clean, no issues
Test Coverage Adequate Adequate
Backwards Compat Preserved Preserved
Security No concerns No concerns
External Tests Not needed Not needed
Accessibility Neutral N/A

All expected reviewers completed their reviews. Both reviewers are in full agreement on all substantive points. The only differences are in which optional, non-blocking suggestions each reviewer offered.

Verdict

APPROVED: Both reviewers approve unanimously. The refactor is clean, well-executed, backward-compatible, comprehensively tested, and introduces zero behavioral changes. No blocking quality or security concerns were identified by any reviewer.


This is a consolidated AI review by opus-4.6-thinking.


📋 Review by `gpt-5.3-codex-high`

Summary

This PR is a focused refactor that promotes ComponentResult as the canonical CCv2 result type while preserving BidiComponentResult as a backward-compatible alias. The implementation updates internal/public type hints and docstrings, plus unit tests to validate alias compatibility.

Code Quality

The changes are clean, consistent, and low-risk:

  • Runtime behavior remains effectively unchanged; only class/type naming is updated in lib/streamlit/components/v2/bidi_component/state.py and call sites.
  • Public import ergonomics are preserved by exporting both names in lib/streamlit/components/v2/bidi_component/__init__.py.
  • API docs/type protocol text in lib/streamlit/components/v2/__init__.py and lib/streamlit/components/v2/types.py are aligned with the new canonical name.
  • No maintainability concerns found.

Test Coverage

Coverage is appropriate for a rename-with-alias refactor:

  • lib/tests/streamlit/components/v2/bidi_component/test_state.py now validates both canonical behavior (ComponentResult) and backward compatibility (BidiComponentResult is ComponentResult).
  • Related unit tests were updated to assert the canonical type (lib/tests/streamlit/components/v2/test_bidi_component.py).
  • E2E app scripts under e2e_playwright/bidi_components/ were updated for typing/name consistency; no behavior changes were introduced that would require new E2E scenarios.

Overall, test updates are sufficient for the scope of change.

Backwards Compatibility

Backwards compatibility is preserved:

  • Existing imports/usages of BidiComponentResult continue to work via explicit aliasing in lib/streamlit/components/v2/bidi_component/state.py.
  • Both names are exported from lib/streamlit/components/v2/bidi_component/__init__.py.
  • Existing runtime semantics of the returned mapping-like result object are unchanged.

Security & Risk

No security-sensitive surfaces were modified (no routing, auth/session transport, cookies/XSRF, file serving, iframe/postMessage, external networking, or dynamic code execution changes).
Regression risk is low and mainly limited to type-name/documentation consistency, which is covered by updated tests.

External test recommendation

  • Recommend external_test: No
  • Triggered categories: None
  • Evidence:
    • lib/streamlit/components/v2/bidi_component/state.py: Type/class naming refactor plus alias; no external-hosting or cross-origin behavior changes.
    • lib/streamlit/components/v2/bidi_component/main.py: Return type annotation/name updates only; no websocket/session/auth/routing logic changes.
    • e2e_playwright/bidi_components/basics.py: Type annotation updates only in test app script.
  • Suggested external_test focus areas:
    • None required for this PR; existing external scenarios are not materially affected.
    • If desired, a lightweight smoke check can confirm CCv2 result access (attribute/mapping) remains identical under external hosting.
  • Confidence: High
  • Assumptions and gaps: Assessment assumes no additional unreviewed commits beyond the PR diff and that runtime behavior changes are limited to naming/aliasing.

Accessibility

No frontend UI/component implementation files were changed, and no DOM interaction behavior changed. Accessibility impact is neutral.

Recommendations

  1. Optional: Add a typing test in lib/tests/streamlit/typing/ that asserts the return type of st.components.v2.component(...)-mounted callables remains compatible with ComponentResult (and optionally alias import compatibility), to lock in public typing guarantees.

Verdict

APPROVED: The refactor is coherent, backward-compatible, and sufficiently covered for its scope, with no blocking quality or security concerns identified.


This is an automated AI review by gpt-5.3-codex-high. Please verify the feedback and use your judgment.

📋 Review by `opus-4.6-thinking`

Summary

This PR renames BidiComponentResult to ComponentResult as the canonical result type for Custom Components v2 (CCV2). The change is applied across the public API, internal type hints, docstrings, unit tests, and e2e test annotations. BidiComponentResult is retained as a backward-compatible alias (BidiComponentResult = ComponentResult) to avoid breaking existing user imports.

Files changed (10): The core rename happens in state.py, with all other changes being import/annotation updates and docstring adjustments. A dedicated backward-compatibility test is added.

Code Quality

The refactoring is clean and consistent:

  • The rename is applied uniformly across all internal usage sites (imports, type hints, docstrings, instantiations).
  • The backward-compatible alias in lib/streamlit/components/v2/bidi_component/state.py:85-86 is implemented as a simple class assignment, which correctly preserves isinstance() checks and identity.
  • The __init__.py at lib/streamlit/components/v2/bidi_component/__init__.py properly exports both BidiComponentResult and ComponentResult, ensuring both import paths remain valid.
  • Docstrings in state.py, main.py, types.py, and __init__.py are all updated to reference ComponentResult.
  • The code follows existing patterns and conventions in the codebase.

No issues identified.

Test Coverage

Test coverage is adequate for this refactoring:

  • Unit tests updated: test_state.py and test_bidi_component.py now use ComponentResult throughout, verifying the new canonical name works in all existing test scenarios.
  • Backward-compatibility test added: test_bidi_component_result_alias_remains_supported() in test_state.py explicitly asserts:
    • BidiComponentResult is ComponentResult (identity check)
    • isinstance(result, ComponentResult) (type check)
    • That constructing via BidiComponentResult(state_vals=...) still works
  • E2E test annotations updated: basics.py and session_state_interactions.py use the new name in type hints, ensuring e2e scripts stay aligned.
  • Comment-only update: test_presentation.py has a docstring fix with no behavioral change.

Since this is a pure rename with no behavioral changes, the existing comprehensive test suite for CCV2 provides strong coverage.

Backwards Compatibility

No breaking changes. The backward compatibility strategy is sound:

  1. BidiComponentResult remains importable from streamlit.components.v2.bidi_component (both the package __init__.py and the state module).
  2. The alias BidiComponentResult = ComponentResult means isinstance(), type(), and identity checks all work transparently.
  3. Existing user code using from streamlit.components.v2.bidi_component import BidiComponentResult will continue to work without modification.
  4. ComponentResult is not (and BidiComponentResult was not) exported from the top-level streamlit namespace, so this is a submodule-level rename with a compat alias.

Security & Risk

No security concerns. This is a pure naming refactoring:

  • No new dependencies added.
  • No changes to WebSocket handling, authentication, file serving, or any security-sensitive code paths.
  • No runtime behavioral changes whatsoever — the class itself is unchanged; only its name at the definition site changed.
  • No new external requests, no eval/exec, no HTML/JS rendering changes.

External test recommendation

Recommendation: No@pytest.mark.external_test coverage is not needed.

  • Triggered categories: None.
  • Key evidence: All changes are limited to renaming a Python class and updating type annotations/docstrings. There are zero behavioral changes to the component rendering pipeline, frontend communication, or state management. No new API surface is introduced.
  • Confidence: High. This is a straightforward symbol rename with a backward-compatible alias. The existing e2e tests in e2e_playwright/bidi_components/ already cover CCV2 behavior end-to-end, and the rename does not affect any externally observable behavior.

Accessibility

Not applicable. This PR contains no frontend changes — only Python backend type annotations, docstrings, and class naming. No UI, ARIA, or DOM changes are involved.

Recommendations

No blocking issues. One minor suggestion:

  1. Alias comment wording (non-blocking): The comment at lib/streamlit/components/v2/bidi_component/state.py:85 says "Deprecated alias" while the PR description frames it as a "backward-compatible alias." If the intent is to eventually remove BidiComponentResult, "deprecated" is correct and a DeprecationWarning could be considered in a future PR to guide users toward ComponentResult. If it's intended to remain indefinitely, consider softening the comment to "Legacy alias kept for backwards compatibility." This is purely a documentation clarity point.

Verdict

APPROVED: Clean, well-executed rename from BidiComponentResult to ComponentResult with a proper backward-compatible alias, comprehensive test updates, and zero behavioral changes.


This is an automated AI review by opus-4.6-thinking.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR standardizes the CCV2 bidirectional component return type name by promoting ComponentResult as the canonical result type across the public API surface, while keeping BidiComponentResult as a backward-compatible alias.

Changes:

  • Renames BidiComponentResultComponentResult in the implementation, public typing surface, and docstrings.
  • Keeps BidiComponentResult as an alias for backward compatibility and adds an explicit compatibility test.
  • Updates unit tests and e2e app scripts to use ComponentResult in type annotations and assertions.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lib/tests/streamlit/runtime/state/test_presentation.py Updates docstring reference to the new canonical result type name.
lib/tests/streamlit/components/v2/test_bidi_component.py Updates tests to construct/assert ComponentResult instead of BidiComponentResult.
lib/tests/streamlit/components/v2/bidi_component/test_state.py Switches tests to ComponentResult and adds alias compatibility coverage.
lib/streamlit/components/v2/types.py Updates the public ComponentRenderer protocol return type and docstrings to ComponentResult.
lib/streamlit/components/v2/bidi_component/state.py Renames the concrete result class to ComponentResult and adds BidiComponentResult alias.
lib/streamlit/components/v2/bidi_component/main.py Updates return type annotations and returned value construction to ComponentResult.
lib/streamlit/components/v2/bidi_component/init.py Exports ComponentResult while keeping BidiComponentResult in __all__.
lib/streamlit/components/v2/init.py Updates TYPE_CHECKING imports + return type annotations/docstrings to ComponentResult.
e2e_playwright/bidi_components/session_state_interactions.py Updates e2e app typing to use ComponentResult.
e2e_playwright/bidi_components/basics.py Updates e2e app typing to use ComponentResult.

Promote `ComponentResult` as the canonical CCV2 result type across the
public API, internal type hints, and docstrings to align naming with the
rest of the v2 surface.

Keep `BidiComponentResult` as a backward-compatible alias to avoid breaking
existing imports and user code. Update tests and e2e typing annotations to
use `ComponentResult`, and add explicit compatibility coverage for the alias.
@sfc-gh-bnisco sfc-gh-bnisco force-pushed the 03-06-refactor_ccv2_rename_bidicomponentresult_to_componentresult branch from 334cf8b to ccb44aa Compare March 6, 2026 23:41
@sfc-gh-bnisco sfc-gh-bnisco marked this pull request as ready for review March 9, 2026 17:15
Copy link
Copy Markdown
Contributor

@sfc-gh-nbellante sfc-gh-nbellante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RIP Bidi 🫡

@sfc-gh-bnisco sfc-gh-bnisco merged commit 289ea7e into develop Mar 9, 2026
45 checks passed
@sfc-gh-bnisco sfc-gh-bnisco deleted the 03-06-refactor_ccv2_rename_bidicomponentresult_to_componentresult branch March 9, 2026 21:43
lukasmasuch pushed a commit that referenced this pull request Mar 10, 2026
## Describe your changes

- Promote `ComponentResult` as the canonical CCV2 result type across the
public API, internal type hints, and docstrings to align naming with the
rest of the v2 surface.
- Keep `BidiComponentResult` as a backward-compatible alias to avoid
breaking existing imports and user code. Update tests and e2e typing
annotations to use `ComponentResult`, and add explicit compatibility
coverage for the alias.

## Screenshot or video (only for visual changes)

## GitHub Issue Link (if applicable)

## Testing Plan

- Adds a backwards compat test

---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:refactor PR contains code refactoring without behavior change impact:users PR changes affect end users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants