Bind widgets to query params - FE hooks & color_picker support#13845
Bind widgets to query params - FE hooks & color_picker support#13845mayagbarnes merged 6 commits intodevelopfrom
color_picker support#13845Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
✅ PR preview is ready!
|
color_picker support
There was a problem hiding this comment.
Pull request overview
This PR adds URL query-parameter binding support for widgets by introducing a reusable frontend hook for registering query-param bindings, extending the ColorPicker protobuf + widget implementation to carry a query-param key, and adjusting session-state URL seeding/validation behavior for bound widgets.
Changes:
- Add
query_param_keyto the ColorPicker protobuf and plumbbind="query-params"throughst.color_pickerto the frontend. - Introduce
useQueryParamBindingand integrate optional query-param binding registration intouseBasicWidgetState. - Extend backend session-state URL seeding logic and add unit/E2E coverage for bind validation and URL seeding/sync.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| proto/streamlit/proto/ColorPicker.proto | Adds a proto field to send the query-param binding key to the frontend. |
| lib/streamlit/elements/widgets/color_picker.py | Adds bind param support, query-param key plumbing, and updated color deserialization/validation. |
| lib/streamlit/runtime/state/widgets.py | Validates bind values and enforces binding preconditions (including clearable). |
| lib/streamlit/runtime/state/session_state.py | Updates URL seeding behavior for bound widgets, including new invalid-value clearing heuristics. |
| lib/streamlit/runtime/state/common.py | Adds consistent empty-key validation via require_valid_user_key. |
| lib/streamlit/elements/lib/policies.py | Enforces key validity at widget policy-check time. |
| lib/streamlit/errors.py | Introduces a dedicated exception for invalid bind values. |
| lib/tests/streamlit/runtime/state/widgets_test.py | Adds tests for invalid bind values and widget binding policy behavior. |
| lib/tests/streamlit/runtime/state/session_state_test.py | Adds coverage for URL seeding behavior when invalid URL values are encountered. |
| lib/tests/streamlit/elements/color_picker_test.py | Adds coverage for bind behavior and ColorPicker serde normalization behavior. |
| frontend/lib/src/hooks/useQueryParamBinding.ts | New hook to register/unregister widget query-param bindings. |
| frontend/lib/src/hooks/useQueryParamBinding.test.ts | Unit tests for the new binding hook. |
| frontend/lib/src/hooks/useBasicWidgetState.ts | Integrates optional query-param binding registration and memoization to reduce reruns. |
| frontend/lib/src/hooks/useBasicWidgetState.test.ts | Adds tests for query-param binding integration in useBasicWidgetState. |
| frontend/lib/src/components/widgets/ColorPicker/ColorPicker.tsx | Wires proto queryParamKey into query-param binding registration. |
| frontend/lib/src/components/widgets/ColorPicker/ColorPicker.test.tsx | Adds tests for ColorPicker query-param binding registration/unregistration. |
| e2e_playwright/st_color_picker.py | Adds bound ColorPicker examples used by E2E tests. |
| e2e_playwright/st_color_picker_test.py | Adds E2E coverage for seeding, URL updates, default cleanup, and invalid URL handling. |
SummaryThis PR introduces a reusable frontend Key changes:
Code QualityFrontend — Well-structured and idiomatic React:
Potential issue — removed eslint-disable comment: In - // eslint-disable-next-line react-hooks/immutability -- TODO: Update to match React best practices
element.setValue = false // Clear "event".This may introduce a new lint warning/error. Please verify this doesn't break the lint step, or restore the disable comment if the rule is still active. Backend Python — Clean and follows conventions:
Proto change — Backward compatible:
Test CoverageTest coverage is excellent across all layers: E2E Tests (5 new tests):
All tests use Frontend Unit Tests:
Python Unit Tests:
Minor suggestions for additional coverage:
Backwards CompatibilityLow risk overall, but two changes affect all widgets:
The Security & Risk
AccessibilityNo accessibility concerns. The color picker's UI is unchanged — only the data binding layer is modified. The widget continues to use the same Recommendations
VerdictAPPROVED: This is a well-structured, thoroughly tested PR that introduces clean infrastructure for query param binding and applies it to This is an automated AI review using |
af48a00 to
c2e8aa5
Compare
SummaryAdds query-param binding for Code QualityOverall structure is clean and consistent with existing widget patterns. One style issue: new Python tests added without Test CoverageCoverage is solid across backend, frontend hooks, and e2e scenarios (seeding, URL updates, invalid values, defaults). One e2e test does not include a negative “must NOT happen” assertion as recommended in the e2e guide ( Backwards Compatibility
Security & RiskNo security concerns identified. URL normalization/cleanup is localized to query-param binding and appears low risk. AccessibilityNo UI or interaction changes beyond URL syncing; accessibility behavior should be unchanged. Recommendations
VerdictAPPROVED: Feature is well-implemented and tested; only minor best-practice nits remain. This is an automated AI review using |
Describe your changes
This PR introduces a reusable frontend hook for query‑param binding and adds the
bindparameter tost.color_pickerto enable two-way sync between widget values and URL query parameters.useQueryParamBindinghook - Extracted reusable hook for registering/unregistering query param bindingsst.color_picker:Also, for hardening:
key=""to any widgetwas silently accepted (though non-functional). This PR adds validation that raises
StreamlitAPIExceptionif an empty string is provided as a widget key. This is adefensive hardening to catch likely user errors early.
Testing Plan