LearnNewsExamplesServices
Frontmatter
id17954
titleDestroyed grids and editors never release their native ResizeObserver
stateClosed
labels
bugaiperformancegrid
assigneesneo-opus-grace
createdAtAug 31, 2026, 5:14 PM
updatedAtAug 31, 2026, 7:14 PM
githubUrlhttps://github.com/neomjs/neo/issues/17954
authorneo-opus-grace
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtAug 31, 2026, 7:14 PM

Destroyed grids and editors never release their native ResizeObserver

Closed v13.2.0/archive-v13-2-0-chunk-17 bugaiperformancegrid
neo-opus-grace
neo-opus-grace commented on Aug 31, 2026, 5:14 PM

Context

#17579 fixed list.Buffered by naming the component on both sides of the addon contract — ResizeObserver[mounted ? 'register' : 'unregister']({componentId: id, id, windowId}) (src/list/Buffered.mjs:167). Its Out of Scope deferred exactly one thing: "A repo-wide rewrite of other ResizeObserver consumers." This is that follow-up, and the remaining consumers turn out to fail on the teardown side rather than the delivery side — which is why nothing surfaced when #17579 closed.

The lane arrived from a different direction. @neo-opus-vega found grid/Container.mjs#addResizeObserver registering without componentId and asked whether it was a latent gap. It is not the same gap she fixed in #17928: grid's delivery works, because DomEvent registers grid's target correctly on its own path. Both of us then read the four sites as dead calls and converged on deleting them. That was wrong, and the disposition inverted on measurement: three of the four are cleanup that silently does nothing.

The Problem

src/main/addon/ResizeObserver.mjs#unregister is refcounted by componentId, because one DOM target may be observed by several components:

me.#targetToComponents[id] = componentIds.filter(cid => cid !== data.componentId);

if (me.#targetToComponents[id].length === 0) {
    delete me.#targetToComponents[id];
    me.#lastDispatchedSize.delete(id);
    node && me.instance.unobserve(node);
    me.syncPollState()
}

Every remaining consumer calls it as unregister({id, windowId}). data.componentId is undefined, so the filter removes only undefined entries and leaves every real one. The array never empties, so the guarded block never runs:

  • instance.unobserve(node) never fires — the native observer keeps the detached node alive.
  • #lastDispatchedSize keeps its entry.
  • syncPollState() is never re-evaluated, so the hidden-document poll stays armed for a target nobody is watching.

For a live grid the array is [gridId, undefined]: DomEvent.addResizeObserver (src/manager/DomEvent.mjs:131) contributes the real id, and grid/Container.mjs:343 contributes the undefined. Destroy strips the undefined and leaves [gridId] — length 1, not 0.

Nothing else picks up the slack. DomEvent.unregister (src/manager/DomEvent.mjs:512) is a // todo stub that console.logs and returns above its own body, and no unmount path calls the addon. These four call sites are the entire teardown surface for native ResizeObservers outside list.Buffered.

Consequence: every grid.Container and every MonacoEditor that is destroyed or unmounted leaves a native observer entry behind for the life of the document. Long-lived dashboards that create and drop grids accumulate them.

The Architectural Reality

componentId is the App-Worker delivery identity; id is the DOM target. The addon keys observation by target and refcounts by component, which is what lets two components observe one node without either one's teardown blinding the other. A call that omits componentId is therefore not "the same call with less detail" — on register it adds an anonymous holder, and on unregister it asks to remove the anonymous holder specifically. #17579 established this for delivery; the same asymmetry governs teardown.

Complete census of addon consumers (grep -rn "addon.ResizeObserver\|getAddon('ResizeObserver')" src/ apps/):

site call componentId status
src/manager/DomEvent.mjs:131 register ✅ correct — the auto path for any resize domListener
src/list/Buffered.mjs:167 register + unregister ✅ correct — the #17579 fix
src/grid/Container.mjs:343 register ❌ adds an anonymous holder
src/grid/Container.mjs:346 unregister (unmount) ❌ never releases
src/grid/Container.mjs:1038 unregister (destroy) ❌ never releases
src/component/wrapper/MonacoEditor.mjs:386 unregister (destroy) ❌ never releases

component/Canvas.mjs and container/Viewport.mjs name the addon only in config JSDoc; both ride the domListeners path and are already covered by DomEvent.

The Fix

Name the component on all four calls, matching src/list/Buffered.mjs:167:

  1. src/grid/Container.mjs#addResizeObserver — resizeParams becomes {componentId: me.id, id: me.id, windowId}, covering both the register and unregister arms.
  2. src/grid/Container.mjs destroy (:1038) — add componentId: me.id.
  3. src/component/wrapper/MonacoEditor.mjs destroy (:386) — add componentId: me.id.

Both components' vdom roots carry no explicit id, so the DOM target is the component id and the addon's includes check collapses the manual register and DomEvent's into one entry. Teardown then empties the array and reaches unobserve.

Witness before fix. test/playwright/unit/main/addon/ResizeObserver.spec.mjs already stands up the addon against a stubbed DOM. The arm drives a real component through mount and destroy and asserts the target is no longer observed — red on the current tree, green after. The addon itself is not modified: its refcount semantics are the correct contract, and asserting them directly would pass both before and after.

Contract Ledger Matrix

Target Surface Source of Authority Behavior Fallback Docs Evidence
Neo.main.addon.ResizeObserver#unregister #17579, unchanged here removes the calling component from the target's holder list; unobserves when the list empties a target with other holders stays observed, which is the point of the refcount addon JSDoc not modified by this ticket; the witness pins it from the caller side
Neo.grid.Container#addResizeObserver this ticket register and unregister both name componentId: me.id an unmounted grid unregisters through the same params object method JSDoc states why the id is named twice destroy leaves zero observed targets
Neo.component.wrapper.MonacoEditor#destroy this ticket unregister names componentId: me.id me.mounted guard unchanged inline comment destroy leaves zero observed targets
Neo.manager.DomEvent#unregister #17579 era, untouched still a // todo stub none — named here so the next reader does not assume teardown is centralized

Decision Record impact

none. This restores an existing contract established by #17579; it does not amend one.

Acceptance Criteria

  • A unit arm drives a mounted component's destroy and asserts the native target is unobserved afterwards; it fails on the pre-fix tree.
  • src/grid/Container.mjs names componentId on its register and unregister calls (:343, :346) and on destroy (:1038).
  • src/component/wrapper/MonacoEditor.mjs:386 names componentId.
  • A census assertion or test comment records that DomEvent.mjs:131 and list/Buffered.mjs:167 are the two already-correct sites, so a later reader can tell coverage from omission.
  • npm run test-unit green.

Out of Scope

  • Implementing DomEvent.unregister. The stub is named above so it is not mistaken for working teardown, but giving DomEvent a real unregister path is its own design question — it would centralize teardown and make the per-component calls redundant, which is a different ticket with a different blast radius.
  • The auto path's own teardown. DomEvent.addResizeObserver registers and nothing ever unregisters that entry independently. Here the targets coincide with the components', so the fix drains them; a target registered only through a delegate: '#other-id' listener is not covered and is left as a known gap.
  • Removing the redundant register at :343. With DomEvent already registering grid's target, grid's own register adds nothing once componentId is present — the addon dedups it. Deleting it is a simplification, not a correctness requirement, and keeping teardown self-contained is worth more than the line.
  • The dynamic-addDomListeners asymmetry. Reading updateDomListeners says the auto path is deferred ~50ms on a mounted component rather than skipped. @neo-opus-vega then measured the opposite at the dock-maximize call site: reverting only the componentId on that register left resizeEventCount: 0 across a 10s poll with real viewport resizes, so no auto registration reached that target at all. The gate that stops it there is unmeasured. Reading lost to measurement, and this ticket does not depend on the outcome — naming componentId on both of grid's own calls makes its holder self-contained, so teardown drains whether or not DomEvent also registered. #17928 owns that seam; reproducer is the resize arm of test/playwright/component/dashboard/DockMaximize.spec.mjs plus the one-line revert.

Avoided Traps

  • Deleting the four calls as dead code. This was the working disposition until the refcount filter was read. A no-op teardown looks exactly like dead code from the call site and is the opposite: deleting it is the one edit that makes the leak permanent and unrecoverable by any later caller-side fix.
  • Arguing from symmetry with #17928. Those sites do not share its premise — grid's delivery works. Symmetry would have produced the right edit for the wrong reason, and the wrong reason is what ends up in the next reader's head.
  • Fixing the addon instead of the callers. componentId-keyed refcounting is deliberate; making unregister treat a missing componentId as "remove everything" would let one component blind another observing the same node.

Related

  • #17579 — established the both-sides contract for list.Buffered; its Out of Scope defers exactly these consumers
  • #17928 — @neo-opus-vega's delivery-side fix on the same missing argument; different failure mode, same root shape

Live latest-open sweep: checked latest 20 open issues at 2026-08-31T15:13:51Z; no equivalent found (#17579 is the closed precedent whose Out of Scope defers this work). A2A in-flight sweep: checked latest 30 all-state messages at 2026-08-31T15:14Z; no overlapping claim — @neo-opus-vega's message on this scope is a disposition to me, and the lane is answered back to her. Local corpus sweep: resources/content/issues/** for ResizeObserver + componentId/unregister; #17579 and #14911 reviewed, neither equivalent.

Origin Session ID: 56bc214a-5b55-41a2-848a-cdfa372abbcd

Retrieval Hint: query_raw_memories("ResizeObserver componentId refcount unregister never unobserves") · #17579 → this ticket → #17928