Skip to content

Commit 0ff2621

Browse files
committed
fix(octane): retire hosts in deferRootUnmount, portalSlotSlot, and batchClearItems
deferRootUnmount's commit callback reconnects saved nodes and runs unmountBlock without stamping them first, so a focusout during cleanup or removeChild can start a handler on an already-disposed scope. The portalSlotSlot branch in unmountSlot calls unmountBlock on the portal block directly; because the portal's DOM lives in a foreign target, no enclosing deletion's retirement covers it. batchClearItems' non-parkable path (the fallback when rows cannot park) disposes items and clears the DOM range without retiring the focused row, so the synchronous focusout can deliver to a disposed handler. Add retireEventHostTree / retireHostRange at each site, matching the pattern already used by deferRootRange, teardownPortalState, and deferRootOwnedListClear respectively.
1 parent bc9ad49 commit 0ff2621

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎packages/octane/src/runtime.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4107,6 +4107,8 @@ function deferRootUnmount(block: Block, detachDom: boolean): boolean {
41074107
if ((STAGED_DOM?.view(node) ?? node).parentNode !== parent)
41084108
(STAGED_DOM?.view(parent) ?? parent).insertBefore(node, anchor);
41094109
}
4110+
// Retire the outgoing nodes before any cleanup can move focus off them.
4111+
nodes.forEach(retireEventHostTree);
41104112
const previousSuppression = REF_DETACH_SUPPRESSION;
41114113
REF_DETACH_SUPPRESSION = suppressedRefs;
41124114
try {
@@ -12367,6 +12369,8 @@ function unmountSlot(val: any, detachDom: boolean): void {
1236712369
// Portal DOM lives in a FOREIGN target — the root-level batched clear
1236812370
// never reaches it, so portals must always self-detach individually.
1236912371
const childDetach = k === 'portalSlotSlot' ? true : detachDom;
12372+
// Its DOM lies outside every enclosing deletion's range: retire it here.
12373+
if (k === 'portalSlotSlot' && val.block) retireHostRange(val.start, val.end);
1237012374
if (val.block) unmountBlock(val.block, childDetach);
1237112375
if (k === 'portalSlotSlot' && val.target) {
1237212376
unregisterPortalEventRange(val.target, val);
@@ -46516,6 +46520,12 @@ function batchClearItems(
4651646520
}
4651746521
TEARDOWN_DEPTH++;
4651846522
try {
46523+
// Retire the focused row before any cleanup can blur it: only removing a
46524+
// focused row dispatches focusout during a synchronous batch clear.
46525+
const p = domNode(state.start).parentNode!;
46526+
let row: Node | null | undefined = (renderingFocus as FocusSelectionSnapshot | null)?.focused;
46527+
while (row != null && row.parentNode !== p) row = row.parentNode ?? (row as ShadowRoot).host;
46528+
if (row != null) retireEventHostTree(row);
4651946529
// Dispose the items before their DOM leaves, like every other deletion:
4652046530
// cleanups observe attached hosts. Walk the intrusive item chain (head →
4652146531
// nextSibling) rather than the Map's iterator: zero allocation and a
@@ -46534,7 +46544,6 @@ function batchClearItems(
4653446544
b.disposed = true;
4653546545
}
4653646546
}
46537-
const p = domNode(state.start).parentNode!;
4653846547
if (domNode(state.start).previousSibling === null && getNextSibling(state.end) === null) {
4653946548
// forBlock owns the parent — nuke everything in one DOM op, then re-add markers.
4654046549
(STAGED_DOM?.view(p as Element) ?? (p as Element)).textContent = '';

0 commit comments

Comments
 (0)