-
Notifications
You must be signed in to change notification settings - Fork 4k
Prevent st.dialog from showing elements from previous dialog
#13297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ 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!
|
|
@cursor review |
There was a problem hiding this 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 fixes issue #10907 where stale elements from a previously opened dialog would briefly appear when opening a different dialog. The fix introduces a stable dialog identity computed from the dialog's attributes (title, dismissible, width, on_dismiss) and uses this identity to determine whether to preserve children when replacing a dialog block.
Key Changes:
- Dialog IDs are now always computed and set on the block proto, not just when
on_dismissis activated - Frontend logic now checks dialog identity before inheriting children from a previous dialog block
- Added comprehensive unit and E2E tests to verify the fix
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
lib/streamlit/elements/lib/dialog.py |
Refactored to always compute and set dialog element_id on block_proto.id, moving it outside the on_dismiss conditional block |
frontend/lib/src/render-tree/AppRoot.ts |
Added logic to prevent inheriting children when replacing a dialog with a different identity |
frontend/lib/src/render-tree/AppRoot.test.ts |
Added unit tests verifying that dialogs with different identities don't inherit children, while same-identity dialogs do |
e2e_playwright/st_dialog_test.py |
Added E2E test reproducing issue #10907 and verifying the fix prevents stale content |
e2e_playwright/st_dialog.py |
Added test dialogs (fast and slow) to support the new E2E test case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Bugbot reviewed your changes and found no bugs!
SummaryThis PR fixes issue #10907 where elements from previous dialogs were showing up as stale content in different dialogs. The bug occurred when:
The fix introduces a dialog identity check that prevents the frontend from inheriting children from an existing dialog block when replacing it with a different dialog. Changes:
Code QualityPython Changes (dialog.py)The refactoring is clean and follows good practices:
TypeScript Changes (AppRoot.ts)The fix is minimal and targeted: const isDialogWithDifferentIdentity =
block.dialog &&
existingNode.deltaBlock.dialog &&
block.id !== existingNode.deltaBlock.id
if (!isDialogWithDifferentIdentity) {
children = existingNode.children
}Strengths:
Test CoverageFrontend Unit Tests (AppRoot.test.ts)Two comprehensive tests added:
Both tests follow the existing patterns in the test file and provide good coverage of the new behavior. E2E Test (st_dialog_test.py)Test: The test accurately reproduces the issue:
Best practices followed:
Backwards Compatibility✅ Fully backwards compatible
Security & Risk✅ No security concerns
Risk Assessment: Low
RecommendationsNo changes are required. The implementation is clean, well-tested, and addresses the issue appropriately. Minor observations (not blocking):
VerdictAPPROVED: This is a well-implemented, properly tested bug fix that addresses issue #10907 with minimal, targeted changes. The fix is backwards compatible and poses no security or regression risks. Both the frontend and backend changes are clean and follow existing code patterns in the repository. This is an automated AI review. Please verify the feedback and use your judgment. |
|
That's amazing, thanks for fixing this, Lukas!! |
lib/streamlit/elements/lib/dialog.py
Outdated
| # Compute a stable identity for the dialog based on its attributes. | ||
| # This ID is used in the frontend to distinguish between different dialogs | ||
| # and prevent showing stale content from a previous dialog (issue #10907). | ||
| # It's also used for widget registration when on_dismiss is activated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be good to add that we don't want this to be a widget in the default case because it would affect the usage in fragments and caching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added more comments 👍
Describe your changes
Fixes and issues where elements from previous dialogs were still showing up in a different dialog as stale elements. This was fixed by always calculating the dialog ID and only keeping the existing children in case it's the same dialog -> which expects the same type of children.
Before:
Screen.Recording.2025-12-10.at.20.36.38.mov
After:
Screen.Recording.2025-12-10.at.20.37.27.mov
GitHub Issue Link (if applicable)
st.dialogshows stale elements from previous dialog #10907Testing 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.