Skip to content
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

Handle out of order blocks when parsing element tree #7923

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/streamlit/testing/v1/element_tree.py
Expand Up @@ -1915,6 +1915,13 @@ def parse_tree_from_messages(messages: list[ForwardMsg]) -> ElementTree:
children[idx] = child
assert isinstance(child, Block)
current_node = child

# Handle a block when we already have a placeholder for that location
if isinstance(new_node, Block):
placeholder_block = current_node.children.get(delta_path[-1])
if placeholder_block is not None:
new_node.children = placeholder_block.children

current_node.children[delta_path[-1]] = new_node

return root
24 changes: 24 additions & 0 deletions lib/tests/streamlit/testing/app_test_test.py
Expand Up @@ -181,3 +181,27 @@ def script():
assert len(at.text) == 4
# querying elements via a block only returns the elements in that block
assert len(at.get("expandable")[0].text) == 2


def test_out_of_order_blocks() -> None:
# Regression test for #7711
def script():
import streamlit as st

container = st.container()
with container:
st.markdown("BarFoo")

def button_one_clicked(cont):
cont.info("Hi!")
cont.markdown("FooBar")

st.button("one", on_click=button_one_clicked, args=[container])

at = AppTest.from_function(script).run()

at.button[0].click().run()

assert at.markdown.len == 2
assert at.info[0].value == "Hi!"
assert at.markdown.values == ["FooBar", "BarFoo"]