fix(stapp): claim external container before first fragment write (closes #752) - #763
Open
Kailigithub wants to merge 1 commit into
Open
Conversation
…efine#752) On Streamlit >=1.60, _tick()'s first write into _stream_fh raises "A fragment tried to write to a container created outside the fragment" because the container position is never reserved by a full-app run. Claim the container once on the first expander write via a single empty st.markdown("") inside with _stream_fh:; gate subsequent writes with a module-scope _stream_claimed flag so the claim is not re-emitted on every 1s refresh. Adds tests/test_stapp_fragment_container_claim.py with 4 cases that exercise the live _tick via AST-source extraction plus a behavioural pin of the old claim-less code. Pre-fix source: 2/4 fail (the fix detection); post-fix: 4/4 pass. Fixes lsdefine#752.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Streamlit >=1.60,
_tick()'s first write into_stream_fhraises"A fragment tried to write to a container created outside the fragment"
because the container position is never reserved by a full-app run. Claim
the container once on the first expander write via a single empty
st.markdown("")insidewith _stream_fh:; gate subsequent writes witha module-scope
_stream_claimedflag so the claim is not re-emitted onevery 1s refresh.
Adds
tests/test_stapp_fragment_container_claim.pywith 4 cases thatexercise the live
_tickvia AST-source extraction plus a behavioural pinof the old claim-less code.
Parent-commit proof gate:
The 2 failing cases on the pre-fix source are exactly the fix-detection
cases; the pre-fix pin and the skip-when-
_stream_fh-is-None case passeither way (the pin copies the OLD code body verbatim and confirms it
WOULD NOT have emitted the claim).
Fixes #752.