Repository navigation
Show streamed text in a lazy stack row that SwiftUI has not placed - #30
Merged
Merged
Conversation
A `TranscriptText(stream:)` added to a `LazyVStack` could stay empty. After 50 rows of 1,400 points, the answer row never showed. The lazy stack added the row without placing it. The view asked SwiftUI to measure it again through its own state, but in this layout SwiftUI ignored changes inside the row. Now the stream has an observable revision. `TranscriptText(stream:)` reads it and keeps it when it is made. While the row is not placed, each new height changes the revision. The view whose body made the `TranscriptText` then runs again and gets a different value, and SwiftUI updates, measures and places the row. This works when `TranscriptText(stream:)` is made in the `ForEach` closure or in the view that holds the stack. In the body of a row view of its own, the change stays inside the row, and the row can stay empty. In the same layout, SwiftUI `Text` that reads an observable model in a row view of its own also stayed empty. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
TranscriptText(stream:)added to aLazyVStackcould stay empty (#12). After 50 rows of 1,400 points, the answer row never showed.@State(Measure streamed text in views that SwiftUI has not placed #15). In this layout, SwiftUI did not act on that state. A trace on the phone shows no update and no measure of the row after SwiftUI made it, while the text grew to 1,197 points.TranscriptText(document)with the document in the parent's@Stateshowed the answer: each parent update made SwiftUI update and measure the row.TranscriptText(stream:)reads it and keeps it when it is made, so the revision is a dependency of the view whose body makes theTranscriptText. While the row is not placed, each new height changes the revision. That view then runs again and gets a differentTranscriptTextvalue, and SwiftUI updates, measures and places the row. The public API does not change.TranscriptText(stream:)is made in theForEachclosure or in the view that holds the stack. In thebodyof a row view of its own, the change stays inside the row, and the row can stay empty. In the same layout, SwiftUITextthat reads an observable model in a row view of its own also stayed empty. The README says where to make the view.Refs #12.
Tests
swift test: 179 tests pass, with 1 new test. It checks only that the revision is observable. The device repros below cover the rest of the path. The package builds for iOS with no warnings.mainTranscriptTextrowsForEachrowLazyVStackinvalidateIntrinsicContentSize, as before.main. The tile draws (70 to 71), the memory peak (48 MB) and the dropped frames (0) do not change. That answer row is placed, so the bench does not run the new path. It shows that the usual path did not change.🤖 Generated with Claude Code