From e72d364ef8fa282838d5656bcfff693eb17f9aac Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 1 May 2026 05:37:54 +0000 Subject: [PATCH] Fix: suppress didSet observer during incremental token merge MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In mergeTokensByRowId, each tokensByRowId[rowId] = tokens assignment triggered the didSet observer (Swift Dictionary is a value type), causing tokenAttributedStringsByRowId.removeAll(), clampHorizontalOffsets(), and setNeedsDisplayForVisibleBounds() to fire N times — once per patched row. This defeated the incremental cache invalidation the method intended and multiplied layout work for large token patches. Add a _suppressTokensByRowIdDidSet flag so the didSet observer is skipped during the merge loop. The method already performs its own targeted cache invalidation (removeValue per row) and calls clampHorizontalOffsets() and setNeedsDisplayForVisibleBounds() once at the end. --- apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffView.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffView.swift b/apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffView.swift index 678932d5ee..bc0a3b6650 100644 --- a/apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffView.swift +++ b/apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffView.swift @@ -689,8 +689,10 @@ private final class ReviewDiffContentView: UIView, UIGestureRecognizerDelegate { setNeedsDisplayForVisibleBounds() } } + private var _suppressTokensByRowIdDidSet = false var tokensByRowId: [String: [ReviewDiffNativeToken]] = [:] { didSet { + guard !_suppressTokensByRowIdDidSet else { return } tokenAttributedStringsByRowId.removeAll() clampHorizontalOffsets() setNeedsDisplayForVisibleBounds() @@ -698,10 +700,12 @@ private final class ReviewDiffContentView: UIView, UIGestureRecognizerDelegate { } func mergeTokensByRowId(_ tokensPatch: [String: [ReviewDiffNativeToken]]) { + _suppressTokensByRowIdDidSet = true tokensPatch.forEach { rowId, tokens in tokensByRowId[rowId] = tokens tokenAttributedStringsByRowId.removeValue(forKey: rowId) } + _suppressTokensByRowIdDidSet = false clampHorizontalOffsets() setNeedsDisplayForVisibleBounds() }