🤖 perf: fix forced layout in ResizeObserver callbacks #1262
+156
−72
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
Chrome trace analysis (Dec 20, 2025) revealed 110ms+ layout thrashing from synchronous
scrollHeight/clientHeightreads in ResizeObserver callbacks during React's commit phase.Verified Performance Improvements
Changes
New
useOverflowDetectionhook (+72 lines)Reusable, well-documented hook for detecting content overflow with RAF-throttled layout reads:
Fixed
useAutoScroll.tsrequestAnimationFrameImproved
useResizeObserver.tsdocumentationuseOverflowDetectionfor overflow detection use caseExtracted
calculateLineNumberWidthsutilityDiffRendererandSelectableDiffRendererWhy RAF Fixes the Issue
When ResizeObserver fires during React's commit phase, reading layout properties like
scrollHeightforces the browser to complete a full synchronous layout before returning. With ~18,515 DOM objects in the trace, this blocked the main thread for 100ms+.By deferring to
requestAnimationFrame:Generated with
mux• Model:anthropic:claude-opus-4-5• Thinking:high