forked from streamlit/streamlit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ghost tabs issue in fragments (streamlit#9186)
## Describe your changes Closes streamlit#9158 So far we seemed to have missed the case where we can have stale widgets in the same fragment we are currently running which stem from a previous run. This PR closes this gap by removing widget nodes that belong to the current fragment but an old run. It looks like the reason why this is happening for tabs (and probably other containers) and not for other elements is that in for a tab delta, the `scriptRunId` is updated to the current run, so the existing pruning logic does not work; the new approach also considers the child's `scriptRunId`! ## GitHub Issue Link (if applicable) ## Testing Plan - Explanation of why no additional tests are needed - Unit Tests (JS and/or Python) - Extended unit test to simulate this issue - E2E Tests - Add e2e test with example app from streamlit#9158 - Any manual testing needed? --- **Contribution License Agreement** By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
- Loading branch information
Showing
4 changed files
with
125 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import streamlit as st | ||
|
||
|
||
@st.fragment | ||
def show_page(): | ||
checkmark = st.checkbox("Yes or No") | ||
|
||
if checkmark: | ||
st.tabs(["Tab A", "Tab B", "Tab C"]) | ||
else: | ||
st.tabs(["Tab 1", "Tab 2"]) | ||
|
||
|
||
show_page() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from playwright.sync_api import Page, expect | ||
|
||
from e2e_playwright.shared.app_utils import click_checkbox | ||
|
||
|
||
def _expect_numeric_tabs(app: Page): | ||
tabs = app.get_by_test_id("stTabs") | ||
expect(tabs).to_have_count(1) | ||
tab_buttons = tabs.locator("button") | ||
expect(tab_buttons).to_have_count(2) | ||
expect(tab_buttons.nth(0)).to_have_text("Tab 1") | ||
expect(tab_buttons.nth(1)).to_have_text("Tab 2") | ||
|
||
|
||
def _expect_letter_tabs(app: Page): | ||
tabs = app.get_by_test_id("stTabs") | ||
expect(tabs).to_have_count(1) | ||
tab_buttons = tabs.locator("button") | ||
expect(tab_buttons).to_have_count(3) | ||
expect(tab_buttons.nth(0)).to_have_text("Tab A") | ||
expect(tab_buttons.nth(1)).to_have_text("Tab B") | ||
expect(tab_buttons.nth(2)).to_have_text("Tab C") | ||
|
||
|
||
def test_correct_tabs_are_shown_and_no_ghost_tabs(app: Page): | ||
"""When we render a different amount of tabs, we want the | ||
correct tabs to show and no tabs from the previous fragment | ||
run (see issue https://github.com/streamlit/streamlit/issues/9158). | ||
""" | ||
_expect_numeric_tabs(app) | ||
|
||
# Ensure that this works for multiple runs | ||
for _ in range(10): | ||
click_checkbox(app, "Yes or No") | ||
_expect_letter_tabs(app) | ||
|
||
click_checkbox(app, "Yes or No") | ||
_expect_numeric_tabs(app) |
This file contains 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
This file contains 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