fix(chat): defer scroller resize correction off the ResizeObserver callback#624
Draft
posthog[bot] wants to merge 1 commit into
Draft
fix(chat): defer scroller resize correction off the ResizeObserver callback#624posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
The message scroller's ResizeObserver callback wrote viewport.scrollTop synchronously (via scrollToEnd / reanchorToAnchoredMessage), mutating layout inside the same observer delivery. Browsers report this as "ResizeObserver loop completed with undelivered notifications" — benign, but it fires on every frame of a streaming reply and one session logged it hundreds of times. Coalesce the resize-driven scroll correction onto a requestAnimationFrame so the scrollTop write lands outside the observer callback, breaking the loop. The frame is cancelled on unmount for StrictMode safety, matching the existing state-commit frame handling. Also drop the known-benign ResizeObserver warnings in the PostHog global error handler so a stray occurrence no longer pollutes error tracking. Generated-By: PostHog Code Task-Id: 230c0026-2cbc-41ca-9911-b2b86dfd746b
|
React Doctor found no new issues. 🎉 Reviewed by React Doctor for commit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
A single chat session logged the browser warning "ResizeObserver loop completed with undelivered notifications" hundreds of times, and it was also being forwarded into error tracking as a real exception.
Two changes:
ResizeObservercallback (handleResize) wroteviewport.scrollTopsynchronously (viascrollToEnd/reanchorToAnchoredMessage), mutating layout inside the same observer delivery — the classic trigger for that warning. The resize-driven scroll correction is now coalesced onto arequestAnimationFrame, so the write lands outside the observer callback. The frame is cancelled on unmount for StrictMode safety, matching the existing state-commit frame handling.ResizeObserver loop*warnings, so a stray occurrence can't bury genuine errors in error tracking.An earlier scroll-stabilization pass didn't stop the loop; deferring the mutation off the observer callback is the direct fix.
Why
One user hit this loop repeatedly in a single chat session while using web access; session replay flagged it a
blocking_exception, and the unfiltered global handler was logging every occurrence as an error-tracking issue. It's both a real UX degradation for affected users and clutter that can hide genuine errors.Testing notes
pnpm check(format, lint, types) — passespnpm test— 14 passedThe symptom is a browser layout-timing warning surfaced through error tracking rather than a rendered visual glitch; reproducing it live needs a streaming chat session against the backend, which wasn't available in this environment. The
requestAnimationFramedeferral is the established mitigation for this specific warning and preserves the existing follow-bottom / anchor behavior (the append/anchor path via the content mutation observer is unchanged).Created with PostHog Code from an inbox report.
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.