From 45e56bc844adfb2b74a045276bee556744eb469b Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Thu, 6 Aug 2026 03:34:12 -0700 Subject: [PATCH] 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 --- .../Features/Chat/MarkdownMessageView.swift | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/swift-ios/Features/Chat/MarkdownMessageView.swift b/apps/swift-ios/Features/Chat/MarkdownMessageView.swift index 730977af9f..3af24bcfad 100644 --- a/apps/swift-ios/Features/Chat/MarkdownMessageView.swift +++ b/apps/swift-ios/Features/Chat/MarkdownMessageView.swift @@ -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) } }