Repository navigation
dom: attribute ResizeObserver loop telemetry to DisposableResizeObserver name - #314411
Conversation
Wrap the user callback of DisposableResizeObserver with scheduleAtNextAnimationFrame so layout writes done by the callback (scanDomNode, KaTeX layout, height assignments, ...) land in the next layout pass instead of re-entering the current one. Also coalesce multiple deliveries within a frame into a single callback invocation. This fixes the root cause of the "ResizeObserver loop completed with undelivered notifications" warning that has been the top error bucket since v1.106 (#293359 - 54M hits / 2.5M users). The warning is benign on its own (Chromium just defers the leftover entries to the next frame), but every occurrence costs an extra layout pass per frame on the affected element. With chat streaming UI (thinking, tool confirmations, plan review, KaTeX) all observing simultaneously, this adds up to several extra layout passes per streamed token on slow machines. Also accept an optional targetWindow so observers created for elements in an auxiliary window use that window's ResizeObserver constructor and animation-frame timer. Convert the three remaining raw `new ResizeObserver(...)` sites to use the wrapper so they inherit the batching + disposable lifetime: - chatMarkdownContentPart (KaTeX layout participants) - chatTerminalToolProgressPart (terminal output resize) - browserEditorFindFeature (find widget height tracking - now passes getWindow(container) to preserve aux-window correctness) Refs #293359
|
Base:
|
There was a problem hiding this comment.
Pull request overview
This PR updates the shared browser DOM resize-observer wrapper to defer callbacks to the next animation frame, then migrates a few chat/browser-view call sites to that wrapper so resize-driven layout work no longer runs inside the native ResizeObserver delivery phase.
Changes:
- Reworks
DisposableResizeObserverinsrc/vs/base/browser/dom.tsto batch deliveries per frame, defer callbacks withscheduleAtNextAnimationFrame, and support an explicit target window. - Converts chat markdown, chat terminal tool progress, and browser find-widget resize handling to use the shared disposable wrapper.
- Aligns the browser find widget with auxiliary-window handling by passing the container window into the wrapper.
Show a summary per file
| File | Description |
|---|---|
src/vs/base/browser/dom.ts |
Adds deferred/batched DisposableResizeObserver behavior and target-window support. |
src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatMarkdownContentPart.ts |
Switches KaTeX/layout participant resize handling to the shared wrapper. |
src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatTerminalToolProgressPart.ts |
Switches terminal output section resize handling to the shared wrapper. |
src/vs/workbench/contrib/browserView/electron-browser/features/browserEditorFindFeature.ts |
Replaces the raw observer with the shared wrapper and preserves the container window realm. |
Copilot's findings
Comments suppressed due to low confidence (1)
src/vs/base/browser/dom.ts:2084
- Concatenating every native delivery into one
batchchanges the callback contract in a breaking way: existingDisposableResizeObserverconsumers still assumeentries[0]is the current size for the target (for examplechatListRenderer.ts:639-642andchatThinkingContentPart.ts:566-571). If the same element resizes twice before the rAF runs,entries[0]stays the oldest record, so we can cache/fire a stale height and never observe the final one. The coalescing here needs to keep the latest entry per target instead of appending historical entries.
if (this.pendingEntries) {
this.pendingEntries.push(...entries);
return;
}
this.pendingEntries = entries.slice();
- Files reviewed: 4/4 changed files
- Comments generated: 1
Addresses Copilot review feedback on #314411 — covers rAF deferral, per-frame coalescing, cancel-on-dispose, and reschedule-after-frame.
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: Kyle Cutler (@kycutler)Matched files:
Joaquín Ruales (@jruales)Matched files:
|
|
The change in Integrated Browser related file browserEditorFindFeature.ts looks good to me |
Matt Bierner (mjbvz)
left a comment
There was a problem hiding this comment.
Change looks ok but the tests shouldn't be adding more any casts or needing to modify global objects
Addresses @mjbvz review on #314411 — drops the global mutation and any-casts in the DisposableResizeObserver test suite by adding an optional resizeObserverCtor parameter (DI). Also addresses Copilot's coalescing finding: per-target latest-wins so consumers reading entries[0] always see the freshest size.
…tions Records the rule that arose from review on #314411: don't mutate globals or use any-casts to install fakes in tests; inject the dependency via an optional constructor parameter.
…ution
Reverts the rAF deferral and per-frame coalescing introduced earlier in this PR. Behavior is now identical to the pre-PR sync wrapper, plus:
- targetWindow parameter (preserved) for aux-window correctness.
- try/catch around the user callback so a single bad consumer cannot kill delivery for every other observer in the realm.
- name + creationStack capture, plus a one-shot window 'error' listener that prints which DisposableResizeObservers' callbacks ran in the same task whenever the 'ResizeObserver loop completed with undelivered notifications' warning fires. The browser dispatches that warning as an ErrorEvent (not a thrown exception, error is null), so a try/catch around the callback cannot capture it; we use addEventListener('error', ...).
- resizeObserverCtor option for tests (DI seam, replaces global mutation in the test suite).
…r name Replace the previous suspect-set + window error listener attribution with a simpler design: - DisposableResizeObserver now takes a required `name: string` as its first constructor parameter. Drop the per-instance creation stack capture (callstacks change across releases and bloat telemetry). - Track the most recently invoked observer in a module-level slot and expose `getRecentDisposableResizeObserverAttributionForLoopError(msg)` which, for the stackless `ResizeObserver loop completed with undelivered notifications` warning, returns `[DisposableResizeObserver(<name>)] <msg>`. - Browser ErrorTelemetry uses the helper to prefix both `msg` and `callstack` so the telemetry bucket carries the offending observer's name instead of just the generic warning. - Name all 17 production sites with `<ClassName>.<purpose>` (e.g. ChatListItemRenderer.itemHeight, ChatInputPart.containerHeight). Refs #293359.
634b089 to
0c4d442
Compare
…microtask The slot is set just before the user callback runs and cleared by a microtask in the same step, so the attribution helper only returns a name when the loop warning fires in the same task as the offending observer's callback. Unrelated errors fired later in the renderer no longer inherit a stale observer name.
…setTimeout(0) queueMicrotask clears the slot too eagerly: Chromium runs a microtask checkpoint after each ResizeObserver callback returns, which is *before* the synthetic 'ResizeObserver loop completed with undelivered notifications' error fires at the end of the observation phase. A 0-ms timer runs after the entire current task (callbacks + loop-error dispatch) completes, so the slot is still set when window.onerror picks it up, while still being cleared before any unrelated error in the next task can inherit a stale name. Verified by hand in Code-OSS DevTools.
roblourens
left a comment
There was a problem hiding this comment.
Good idea, seems fine. I just wonder whether there's a chance that multiple observers would run within that window though. Seems like it would be usually correct though.
updated the tests
Summary
Attribute
ResizeObserver loop completed with undelivered notifications.telemetry to the specificDisposableResizeObserverthat most recently ran. EveryDisposableResizeObservernow requires a stablename("<ClassName>.<purpose>"); on the telemetry side, when the loop warning surfaces we prefix bothmsgandcallstackwith that name so the bucket splits by offender instead of pooling everything into one opaque bucket.Motivation
ResizeObserver loop completed with undelivered notifications.has been the #1 error bucket since v1.106 (#293359). Chromium fires it onwindow.onerrorwhenever anyResizeObservercallback writes to layout in a way the browser couldn't fully drain in the same frame.Because the warning carries no useful stack (
<no error message>from a syntheticErrorEvent), every offender — chat row height, KaTeX, find-widget, terminal tool progress, plan review, etc. — collapses into one bucket. We can't tell which observer is the dominant source, so we can't fix it.What changed
DisposableResizeObserver(src/vs/base/browser/dom.ts)name: stringfirst constructor parameter. Convention:"<ClassName>.<purpose>". Stable across releases (does not embed line numbers or call-site stacks)._lastInvokedDisposableResizeObserver = thisimmediately before invoking the user callback, inside a try/catch that routes thrown errors toonUnexpectedError(so one bad consumer can't break delivery for every other observer in the realm).getRecentDisposableResizeObserverAttributionForLoopError(message)returns[DisposableResizeObserver(<name>)] <message>when the message matches the loop warning, otherwiseundefined.targetWindow+{ resizeObserverCtor }constructor options preserved (the latter exists for tests).BrowserErrorTelemetry(src/vs/platform/telemetry/browser/errorTelemetry.ts)In
_onUncaughtError, after the existingerr.stackhandling, call the helper above. If it returns a string we overwrite bothdata.msganddata.callstackwith the prefixed value so the telemetry bucket key carries the offending observer's name.Convert remaining raw
new ResizeObserver(...)sitesSo every observer gets a stable name and the same attribution path:
chatMarkdownContentPart(KaTeX layout participants) →ChatMarkdownContentPart.mathLayoutchatTerminalToolProgressPart→ChatTerminalToolProgressPart.handleResizebrowserEditorFindFeature→BrowserEditorFindFeature.heightChange(passesgetWindow(container)to preserve aux-window realm)Name every existing call site
All 17 production
DisposableResizeObserverconstructions now pass a stable name:chatCompositeBar.tsChatCompositeBar.activeTabRevealbrowserEditorFindFeature.tsBrowserEditorFindFeature.heightChangeaiCustomizationWelcomePagePromptLaunchers.tsAICustomizationWelcomePagePromptLaunchers.scrollablechatListRenderer.tsChatListItemRenderer.itemHeightchatInputPart.tsChatInputPart.containerHeight,ChatInputPart.compactToolbarschatConfirmationWidget.tsBaseSimpleChatConfirmationWidget.message(+3 siblings)chatMarkdownContentPart.tsChatMarkdownContentPart.mathLayoutchatPlanReviewPart.tsChatPlanReviewPart.messageScrollablechatQuestionCarouselPart.tsChatQuestionCarouselPart.inputScrollablechatSubagentContentPart.tsChatSubagentContentPart.layoutchatThinkingContentPart.tsChatThinkingContentPart.child,ChatThinkingContentPart.wrapperchatToolConfirmationCarouselPart.tsChatToolConfirmationCarouselPart.contentExpansionchatTerminalToolProgressPart.tsChatTerminalToolProgressPart.handleResizeWhy this approach
Earlier iterations explored capturing a creation stack and matching it to the loop warning. Two problems:
A stable, hand-assigned name is small, version-stable, and grouped by intent. Recording
_lastInvokedDisposableResizeObserverright before invoking the callback gives us a precise "who fired most recently" pointer that survives into the synchronouswindow.onerrorhandler.This is a diagnostic change, not a behavioural fix — it does not by itself reduce the loop-warning rate. It unblocks the next step: with attribution per observer we can see which one dominates the bucket and target that fix specifically (the chat-row height feedback loop is the prime suspect).
Refs
#293359 (top error bucket since v1.106)
Test plan
src/vs/base/test/browser/dom.test.tscover constructor, dispose, throwing-callback routing, name exposure, and the attribution helper for both matching and non-matching messages.ResizeObserver loopin chat; telemetry payload now contains[DisposableResizeObserver(<name>)] ResizeObserver loop completed with undelivered notifications.in bothmsgandcallstack.