-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set ctx.current_fragment_id in both full script and fragment runs (#8931
) We previously used `ctx.current_fragment_id` to determine whether a script runner execution is a full script run or a fragment rerun. We later switched to using `ctx.fragment_ids_this_run` to support multiple fragments being run from a single script runner but still had the script runner be responsible for setting `ctx.current_fragment_id` outside of the fragment's outer function. It turns out that having the fragment's outer function be reponsible for this fixes the issue we were having with nested fragments not working correctly, so this PR makes the simple required change to fix nested fragments/dialogs. Closes #8635
- Loading branch information
Showing
5 changed files
with
118 additions
and
11 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,37 @@ | ||
# 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 uuid import uuid4 | ||
|
||
import streamlit as st | ||
|
||
|
||
@st.experimental_fragment | ||
def outer_fragment(): | ||
with st.container(border=True): | ||
st.write(f"outer fragment: {uuid4()}") | ||
st.button("rerun outer fragment") | ||
inner_fragment() | ||
|
||
|
||
@st.experimental_fragment | ||
def inner_fragment(): | ||
with st.container(border=True): | ||
st.write(f"inner fragment: {uuid4()}") | ||
st.button("rerun inner fragment") | ||
|
||
|
||
st.write(f"outside all fragments: {uuid4()}") | ||
st.button("rerun whole app") | ||
outer_fragment() |
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,67 @@ | ||
# 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_button | ||
|
||
|
||
def get_uuids(app: Page): | ||
expect(app.get_by_test_id("stMarkdown")).to_have_count(3) | ||
|
||
outside_fragment_text = app.get_by_test_id("stMarkdown").first.text_content() | ||
inner_fragment_text = app.get_by_test_id("stMarkdown").nth(1).text_content() | ||
outer_fragment_text = app.get_by_test_id("stMarkdown").last.text_content() | ||
|
||
return outside_fragment_text, inner_fragment_text, outer_fragment_text | ||
|
||
|
||
def test_full_app_rerun(app: Page): | ||
outside_fragment_text, inner_fragment_text, outer_fragment_text = get_uuids(app) | ||
|
||
click_button(app, "rerun whole app") | ||
|
||
# The full app reran, so all of the UUIDs in the app should have changed. | ||
expect(app.get_by_test_id("stMarkdown").first).not_to_have_text( | ||
outside_fragment_text | ||
) | ||
expect(app.get_by_test_id("stMarkdown").nth(1)).not_to_have_text( | ||
inner_fragment_text | ||
) | ||
expect(app.get_by_test_id("stMarkdown").last).not_to_have_text(outer_fragment_text) | ||
|
||
|
||
def test_outer_fragment_rerun(app: Page): | ||
outside_fragment_text, inner_fragment_text, outer_fragment_text = get_uuids(app) | ||
|
||
click_button(app, "rerun outer fragment") | ||
|
||
# We reran the outer fragment, so the UUID outside of the fragments should stay | ||
# constant, but the other two should have changed. | ||
expect(app.get_by_test_id("stMarkdown").first).to_have_text(outside_fragment_text) | ||
expect(app.get_by_test_id("stMarkdown").nth(1)).not_to_have_text( | ||
inner_fragment_text | ||
) | ||
expect(app.get_by_test_id("stMarkdown").last).not_to_have_text(outer_fragment_text) | ||
|
||
|
||
def test_inner_fragment_rerun(app: Page): | ||
outside_fragment_text, inner_fragment_text, outer_fragment_text = get_uuids(app) | ||
|
||
click_button(app, "rerun inner fragment") | ||
|
||
# We reran the inner fragment. Only that corresponding UUID should have changed. | ||
expect(app.get_by_test_id("stMarkdown").first).to_have_text(outside_fragment_text) | ||
expect(app.get_by_test_id("stMarkdown").nth(1)).to_have_text(inner_fragment_text) | ||
expect(app.get_by_test_id("stMarkdown").last).not_to_have_text(outer_fragment_text) |
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
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