Use key as main identity for st.chat_input widget#12725
Merged
lukasmasuch merged 7 commits intodevelopfrom Oct 15, 2025
Merged
Conversation
Contributor
✅ 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. |
Contributor
✅ PR preview is ready!
|
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR modifies the st.chat_input widget to use a custom key as the main identity when provided, allowing dynamic parameter changes without recreating the widget in the frontend. This addresses the issue where changing parameters like placeholder text or callbacks would cause the widget to lose its state.
Key changes:
- Modified the identity computation logic to treat custom keys as main identity with selective parameter whitelisting
- Added comprehensive test coverage for both stable and dynamic behavior
- Updated E2E tests to verify the dynamic behavior works end-to-end
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/streamlit/elements/widgets/chat.py | Updated chat_input to use key_as_main_identity with whitelisted parameters that affect widget state |
| lib/tests/streamlit/elements/chat_test.py | Added unit tests for widget ID stability and parameter change behavior |
| e2e_playwright/st_chat_input.py | Added dynamic chat input example with parameter toggling |
| e2e_playwright/st_chat_input_test.py | Added E2E test to verify dynamic parameter updates work correctly |
key as main identity for st.chat_input widgetkey as main identity for st.chat_input widget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your changes
If a custom
keyis passed to ast.chat_inputwidget it will be used as the main identity. This allows for dynamically changing other parameters in between reruns without causing the widgets to be recreated in the frontend.GitHub Issue Link (if applicable)
Testing Plan
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.