Repository navigation
Measure streamed text in views that SwiftUI has not placed - #15
Merged
Merged
Conversation
A lazy stack measures a TranscriptText(stream:) row of zero height but does not place it. The view then has no width, so the engine does not lay out the text that arrives, and SwiftUI never measures the view again. While the view has no width of its own, the engine now lays out new text at the width of the last sizeThatFits. When that changes the height, the view tells TranscriptText, which changes a state value that its update reads, so SwiftUI measures the view again. Once the view has a width, the normal path takes over. Refs #12. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
servercimen
force-pushed
the
fix/stream-in-lazy-stack
branch
from
November 20, 2026 18:50
e8fa64f to
593c9d1
Compare
This was referenced Nov 20, 2026
TranscriptText(stream:) in a LazyVStack never shows text that arrives after the row starts empty
#12
Closed
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.
Summary
A lazy stack measures a
TranscriptText(stream:)row of zero height but does not place it. The view then has no width, so the engine does not lay out the text that arrives, andinvalidateIntrinsicContentSize()reaches no one. The row stays empty.With this change, while the view has no width of its own:
sizeThatFitskeeps the proposed width and asks the engine to lay out new text at that width (LayoutEngine.layOutUntilPlaced).onHeightChangeWhileUnsized.TranscriptTextthen changes a@Statevalue that its update reads, so SwiftUI measures the view again.When the view gets a width, the normal path takes over. Views that already have a width, and
TranscriptTextViews used directly from UIKit, do not use this path.Refs #12.
Results
The repros from #12 on an iPhone 17 Pro, iOS 27.0.1:
LazyVStack, text a second laterTranscriptTextrows from the rich corpusWhat this does not fix
In the last case, the lazy stack estimates the new row at about the average row height and keeps the scroll offset at that estimated bottom. The real row is above the visible area, and SwiftUI does not update it:
updateUIViewandsizeThatFitsare not called again, so the state change does not reach the view.A workaround in the app is to put the streaming row after the
LazyVStack, not inside it. That works with and without this change. #12 stays open for this case.Tests
swift test: all 122 tests pass on macOS. After the rebase ontomainwith Add CI: package tests and iOS builds #16 to Add LaTeX math, drawn by a renderer that the app provides #25, all 162 tests pass, and the package builds for iOS.single, 1.01 → 1.03 s inhistory, 0.77 → 0.78 s inrealistic. No dropped frames.🤖 Generated with Claude Code