fix(swift-ios): reject recycled-cell documents in streaming fallback

The stale-document fallback kept any revision-mismatched render while
streaming, so a reused transcript cell whose @State survived recycling
could briefly show another message's markdown. Only accept a stale
document whose source is a prefix of the current message.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
Theo BrowneandClaude Fable 5 committed 2026-08-09 20:53:11 -07:00
1 parent 07e4e3108a
commit 45e56bc844
1 file changed
+12 -2
@@ -96,8 +96,18 @@ struct MarkdownMessageView: View {
return renderedDocument
}
// While streaming, a slightly stale document is better than flashing
// back to plain text between renders; streamed content only appends.
if isStreaming { return renderedDocument }
// back to plain text between renders. Streamed content only appends,
// so require the stale document to be a prefix of the current source:
// that accepts earlier snapshots of this message and rejects leftovers
// from a recycled cell showing a different message.
if isStreaming {
if let renderedDocument,
renderedDocument.revision.utf8Count <= revision.utf8Count,
source.utf8.starts(with: renderedDocument.revision.source.utf8) {
return renderedDocument
}
return nil
}
return MarkdownRenderCache.shared.documentImmediately(for: revision)
}
}