Repository navigation
Description
Problem
A TranscriptText(stream:) that is empty when a LazyVStack lays it out never shows the text that arrives later. Its TranscriptTextView is never added to the window, so the row stays empty.
A likely cause, not proven: the stream sends its text straight to the UIView, without a SwiftUI update. If the lazy stack has not created that view, nothing tells SwiftUI that the row grew.
Repro 1: an empty row
struct EmptyStreamRepro: View {
@State private var stream = TranscriptStream()
var body: some View {
ScrollView {
LazyVStack(alignment: .leading) {
TranscriptText(stream: stream)
}
.padding()
}
.task {
try? await Task.sleep(for: .seconds(1))
stream.append("Hello **world**. This text arrives one second after the view.")
stream.finish()
}
}
}Result: no text shows. No TranscriptTextView is in the window, and the scroll content is 32 pt tall, which is only the padding.
These variants show the text:
VStackinstead ofLazyVStack..frame(minHeight: 1)on theTranscriptText.TranscriptText(document)with an empty@Statedocument that gets its document a second later.
Repro 2: an answer row added at the end of a long list
struct InsertedAnswerRepro: View {
@State private var answering = false
@State private var stream = TranscriptStream()
var body: some View {
ScrollView {
LazyVStack(alignment: .leading, spacing: 16) {
ForEach(0..<50, id: \.self) { _ in
Color.gray.opacity(0.2).frame(height: 2432)
}
if answering {
TranscriptText(stream: stream)
.frame(minHeight: 20, alignment: .top)
.onAppear { print("answer row appeared") }
}
}
.padding(16)
}
.defaultScrollAnchor(.bottom)
.task {
try? await Task.sleep(for: .seconds(2))
answering = true
for _ in 0..<40 {
stream.append("More of the answer arrives, with **bold** text and a [link](https://example.com). ")
try? await Task.sleep(for: .milliseconds(100))
}
stream.finish()
}
}
}Result: the list is scrolled to the bottom, but the answer row never appears. onAppear never runs, and the screen stays blank. Here .frame(minHeight: 20) does not help.
The result is the same with rows 1,400 pt tall. It is also the same with 50 TranscriptText rows from the benchmark's rich corpus (Corpus.history(messages: 50, rich: true)) in place of the gray rows. With the plain corpus (Corpus.history(messages: 50)), the answer row appears.
These variants show the answer:
Textinstead ofTranscriptText(stream:), with the text in@State.TranscriptText(document), with the document in@Stateand parsed again for each chunk.
Environment
iPhone 17 Pro, iOS 27.0.1, Xcode 27.2, TranscriptKit 73bc58b, optimised build. Each case ran 1 to 3 times, with the same result every time.
Possible fixes
- Give an empty
TranscriptText(stream:)the height of one line, asText("")has. This fixes repro 1 only. - Tell SwiftUI when the streamed text's height changes, also when the view is not in the window. For example,
TranscriptTextcould observe the stream's height and update the row's size through SwiftUI.
Activity
Measure streamed text in views that SwiftUI has not placed
Measure streamed text in views that SwiftUI has not placed (#15)
servercimen commentedon Nov 20, 2026
Status after #15, checked on an iPhone 12 mini with
mainat 1afd010:TranscriptTextrows from the rich corpusLazyVStackThe open case is the one that #15 describes. The lazy stack estimates the height of the new row and keeps the scroll offset at that estimate. The real row is then above the visible area, and SwiftUI does not update it. The failed run with rich rows had a different content height, so it is probably the same cause.
Workaround: put the streaming row after the
LazyVStack, not inside it.servercimen commentedon Nov 24, 2026
A correction to my comment above. A trace on an iPhone 12 mini with iOS 27.0 shows a different cause. The lazy stack makes the answer row but does not place it. While the row is not placed, the view changes its own
@Stateto ask SwiftUI to measure it again (#15). In the 1,400-point case, SwiftUI did not update or measure the row after it made it, while the text grew to 1,197 points.TranscriptText(document)with the document in the parent's@Stateshowed the answer, because each parent update made SwiftUI update and measure the row.#30 makes the view that builds
TranscriptText(stream:)update while the row is not placed. With #30, the 1,400-point case and the rich case each show the answer in 7 of 7 runs.One case stays open. When a row view of its own builds
TranscriptText(stream:)in itsbody, the row can stay empty. SwiftUITextthat reads an observable model also stays empty in that layout. For that case, build the view in theForEachclosure, or put the streaming row after theLazyVStack.servercimen commentedon Nov 24, 2026
Fixed by #30. The README says where to build
TranscriptText(stream:)in aLazyVStack.