Skip to content

Conversation

@lukasmasuch
Copy link
Collaborator

@lukasmasuch lukasmasuch commented Aug 29, 2025

Describe your changes

If a custom key is passed to any of the st.checkbox / st.toggle widgets 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 e2e and unit 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.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 29, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-12372/streamlit-1.49.1-py3-none-any.whl
🕹️ Preview app pr-12372.streamlit.app (☁️ Deploy here if not accessible)
@snyk-io
Copy link
Contributor

snyk-io bot commented Aug 29, 2025

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

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@lukasmasuch lukasmasuch requested a review from Copilot August 29, 2025 16:49
@lukasmasuch lukasmasuch added security-assessment-completed Security assessment has been completed for PR change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users labels Aug 29, 2025
@lukasmasuch lukasmasuch marked this pull request as ready for review August 29, 2025 16:49
Copy link
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 identity computation for st.checkbox and st.toggle widgets to use the custom key parameter as the main identity when provided. This change allows dynamic parameter updates between reruns without widget recreation in the frontend, improving user experience by maintaining widget state when other properties change.

Key changes:

  • Sets key_as_main_identity=True for checkbox and toggle widgets when computing element IDs
  • Adds comprehensive unit tests to verify stable widget IDs with dynamic parameters
  • Implements E2E tests demonstrating dynamic property updates while preserving widget state

Reviewed Changes

Copilot reviewed 6 out of 18 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/streamlit/elements/widgets/checkbox.py Changes identity computation to use key as main identity
lib/tests/streamlit/elements/checkbox_test.py Adds unit tests for stable ID behavior with key parameter
e2e_playwright/st_checkbox.py Adds dynamic checkbox test scenario with property updates
e2e_playwright/st_checkbox_test.py Implements E2E tests for dynamic checkbox behavior
e2e_playwright/st_toggle.py Adds dynamic toggle test scenario with property updates
e2e_playwright/st_toggle_test.py Implements E2E tests for dynamic toggle behavior
@lukasmasuch lukasmasuch changed the title Use key as main identity for checkbox & toggle Use key as main identity for st.checkbox & st.toggle Aug 30, 2025
@sfc-gh-lmasuch sfc-gh-lmasuch added the change:breaking PR contains breaking change that affects backwards compatibility label Sep 1, 2025
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
@lukasmasuch lukasmasuch merged commit 6a533c9 into develop Sep 2, 2025
37 checks passed
@lukasmasuch lukasmasuch deleted the stable-key-identity-for-checkbox-widgets branch September 2, 2025 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:breaking PR contains breaking change that affects backwards compatibility change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

4 participants