Skip to content

Use key as main identity for st.chat_input widget#12725

Merged
lukasmasuch merged 7 commits intodevelopfrom
stable-key-identity-for-chat-input
Oct 15, 2025
Merged

Use key as main identity for st.chat_input widget#12725
lukasmasuch merged 7 commits intodevelopfrom
stable-key-identity-for-chat-input

Conversation

@lukasmasuch
Copy link
Copy Markdown
Collaborator

@lukasmasuch lukasmasuch commented Oct 8, 2025

Describe your changes

If a custom key is passed to a st.chat_input widget 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

  • Added unit and e2e tests.

Contribution License Agreement

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

@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Oct 8, 2025

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

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

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

@lukasmasuch lukasmasuch marked this pull request as ready for review October 8, 2025 20:04
@lukasmasuch lukasmasuch marked this pull request as draft October 8, 2025 20:05
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Oct 8, 2025

✅ PR preview is ready!

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

@lukasmasuch lukasmasuch added security-assessment-completed change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users labels Oct 8, 2025
@lukasmasuch lukasmasuch requested a review from Copilot October 8, 2025 20:06
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 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

@lukasmasuch lukasmasuch changed the title Use key as main identity for st.chat_input widget Use key as main identity for st.chat_input widget Oct 13, 2025
@lukasmasuch lukasmasuch marked this pull request as ready for review October 13, 2025 18:23
@lukasmasuch lukasmasuch marked this pull request as draft October 13, 2025 18:41
@lukasmasuch lukasmasuch marked this pull request as ready for review October 13, 2025 18:42
Copy link
Copy Markdown
Collaborator

@sfc-gh-lwilby sfc-gh-lwilby left a comment

Choose a reason for hiding this comment

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

LGTM

@lukasmasuch lukasmasuch merged commit f2be3ed into develop Oct 15, 2025
39 checks passed
@lukasmasuch lukasmasuch deleted the stable-key-identity-for-chat-input branch October 15, 2025 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

st.chat_input drops submission after placeholder text change

3 participants