Parent: #21367 (Dialogs & Overlays: the dialog's defect is fixed before its card is renewed). Promotes defect-note ed66cef6.
Context
examples/dialog promises: "Hide it by pressing the ESCAPE key. The button will be refocused". It breaks that promise on every close path, and on its default path it leaves the page unusable. Measured on dev267eb2336f (the dialog files last changed in ccf172411c), headless Chromium, a fresh page per run:
Path (Animated and Modal checked, the defaults)
Focus after the close
Modal mask
Create Dialog
Click Create Dialog, Escape
BODY
stays, display: block
enabled
Focus Create Dialog, Enter, Escape
BODY
stays
enabled
Click Create Dialog, the header's close button
BODY
stays
enabled
Animated unchecked: click, Escape
BODY
removed
stays disabled
With no dialog left, the grey mask still covers the whole page and takes every click (the next mousedown lands on .neo-dialog-modal-mask) until a reload. Focus trace of the first row, from main-thread capture listeners: focusin #neo-button-1 on mousedown, focusout to BODY 24 ms later, focusin on the dialog's maximize action with relatedTarget: null, Escape, focusout to BODY.
The Problem
The mask outlives the dialog. Every animated close ends in animateHide() → closeOrHide(false) → close(false) → destroy(true). closeOrHide() then awaits me.timeout(30) before it syncs the mask (src/dialog/Base.mjs:534-540). The dialog is destroyed by then, and core.Base#timeout rejects for a destroyed instance (since 07b6933fd0), so the sync never runs. The sync in unmount() (#20448) skips a destroyed dialog too (:896). A non-animated Escape only hides the dialog, and that path does sync: hence the fourth row.
Focus has nothing to return to.revertFocus() and revertFocusOnDeparture() hand focus back only to focusEnterData.relatedTarget (src/component/Base.mjs:1950-1974). The example disables Create Dialog in its handler (examples/dialog/MainContainer.mjs:99); the browser blurs the disabled button, and the dialog takes focus from BODY with relatedTarget: null. A browser that does not focus a clicked button gets the same null without any disabling. Yet the dialog knows its opener: animateTargetId names the button it grows out of.
Escape depends on the animation.onKeyDownEscape() writes hidden = true (:809). An animated hide ends in closeOrHide(false) (:424), so a closeAction: 'close' dialog is destroyed and fires close; a non-animated hide keeps it alive and fires nothing. The example re-enables its button on close, so with Animated unchecked, Escape leaves it disabled for good.
The Architectural Reality
Design authority:
"If we are hidden, or unmounted while we still contain focus, we have to revert focus to where it came from if possible" — component.Base#onFocusEnter (src/component/Base.mjs:1858).
"Otherwise, the mask needs to be below the next topmost modal dialog if possible, or hidden" — Neo.main.DomAccess#syncModalMask (src/main/DomAccess.mjs:1672).
"the close button, Escape and an animated hide all hide the dialog, where a stock dialog would destroy itself" — Neo.desktop.WindowManager (src/desktop/WindowManager.mjs:13).
The mask is one main-thread node. DomAccess#syncModalMask({id, modal}) puts it under id when that node is in the DOM, displayed and modal; else under the last .neo-modal in the DOM; else it removes the mask (:1664-1683). A departing dialog still in the DOM is that last .neo-modal, so a sync that arrives before the removal keeps the mask under it.
component.Abstract#destroy removes a body-rooted component with Neo.applyDeltas(windowId, {action: 'removeNode'}) (src/component/Abstract.mjs:369). As #18850 measured, removals and later calls do not land in a fixed order: the reason for the 30 ms.
DomAccess#focus with restoreFrom (:390) already waits for a departure and focuses only a lost focus.
The three engine dialogs (Neo.desktop.WindowManager's windows, Neo.board.CardEditor, Neo.timeline.EventEditor) use closeAction: 'hide'.
The Fix
DomAccess#syncModalMask: a sync for an id that does not hold the mask (gone, hidden, or modal: false) leaves id out of the topmost-modal search, so the result no longer depends on whether its removal has landed.
dialog.Base#close: sync the mask with modal: false before destroy(true). closeOrHide() loses its timer and its sync; close() and hide() each own theirs.
A departing dialog.Base hands focus back to its opener: the component focus came from, else animateTarget, through the existing restoreFrom hand-back, so a focus the user has moved elsewhere stays.
Escape runs closeOrHide(), the close button's path, so it honors closeAction with or without the animation.
examples/dialog: Create Dialog stays enabled, since a disabled opener cannot take focus back. A click while its dialog is open does nothing.
Acceptance Criteria
Closing a modal dialog takes the mask along: after Escape or the close button, animated or not, the mask is gone, or sits under the next open modal dialog when there is one, and the page takes clicks again. A unit arm on DomAccess#syncModalMask skips a departing modal still in the DOM.
A departing dialog hands focus back to its opener (the component focus came from, else its animateTarget); a focus the user moved elsewhere meanwhile stays. Unit arms on dialog.Base.
Escape honors closeAction with and without the animation: a 'close' dialog fires close and is destroyed, a 'hide' dialog hides. Unit arm.
examples/dialog keeps its promise in all four rows of the Context table: focus is on Create Dialog after the close, the mask is gone, and Create Dialog opens a dialog again. A new e2e spec under test/playwright/e2e/dialog/.
The desktop windows, the board's card editor and the timeline's event editor behave as before (their e2e specs pass), and the whole unit suite is green.
Out of Scope
The dialog card's cover and the Dialogs & Overlays renewal: #21367's renewal leaf.
The popover's placement: its own leaf under #21367.
A longer timer in closeOrHide(): removal and call order is not fixed (#18850), so the sync must be right whichever lands first.
Re-enabling the opener from inside the engine before handing focus back: the opener's state is the app's. The example stops disabling it instead.
Focusing animateTarget unconditionally: a focus the user moved during the close must stay where it is.
Related
#21367 · defect-note ed66cef6 · #20448 (the hide path's mask sync) · #18850 (removal and call order) · 07b6933fd0 (a destroyed instance's timeout() rejects) · #21066.
Live latest-open + closed sweep: checked the latest 20 open plus open and closed search ("dialog mask", "dialog focus", "modal mask", "dialog Escape") at 2026-11-19T02:10Z; #4547, #4548 and #18850 read, none governs the close path's mask or the opener. 74 open, red band: folds under #21367.
A2A in-flight sweep: latest 30 messages in all read-states, newest 02:07:15Z; no claim on the dialog or the popover.
MC sweep: "dialog close Escape restores focus to the opening button", "modal mask stays on the page after the dialog closes": 10 results; the one prior decision is #20448's sync for the hide path.
Own-assignment sweep: 7 open, none overlapping.
Retrieval Hint: "dialog close leaves the modal mask up and focus on body; closeOrHide timeout after destroy; opener animateTarget focus return"
tobiu referenced in commit 5a3cb4d - "feat(dialog): a closing dialog takes its modal mask along and hands focus back to its opener (#21415) (#21417) on Nov 19, 2026, 4:37 AM
Parent: #21367 (Dialogs & Overlays: the dialog's defect is fixed before its card is renewed). Promotes defect-note
ed66cef6.Context
examples/dialogpromises: "Hide it by pressing the ESCAPE key. The button will be refocused". It breaks that promise on every close path, and on its default path it leaves the page unusable. Measured ondev267eb2336f(the dialog files last changed inccf172411c), headless Chromium, a fresh page per run:display: blockWith no dialog left, the grey mask still covers the whole page and takes every click (the next
mousedownlands on.neo-dialog-modal-mask) until a reload. Focus trace of the first row, from main-thread capture listeners:focusin #neo-button-1on mousedown,focusoutto BODY 24 ms later,focusinon the dialog's maximize action withrelatedTarget: null, Escape,focusoutto BODY.The Problem
animateHide()→closeOrHide(false)→close(false)→destroy(true).closeOrHide()then awaitsme.timeout(30)before it syncs the mask (src/dialog/Base.mjs:534-540). The dialog is destroyed by then, andcore.Base#timeoutrejects for a destroyed instance (since07b6933fd0), so the sync never runs. The sync inunmount()(#20448) skips a destroyed dialog too (:896). A non-animated Escape only hides the dialog, and that path does sync: hence the fourth row.revertFocus()andrevertFocusOnDeparture()hand focus back only tofocusEnterData.relatedTarget(src/component/Base.mjs:1950-1974). The example disables Create Dialog in its handler (examples/dialog/MainContainer.mjs:99); the browser blurs the disabled button, and the dialog takes focus from BODY withrelatedTarget: null. A browser that does not focus a clicked button gets the same null without any disabling. Yet the dialog knows its opener:animateTargetIdnames the button it grows out of.onKeyDownEscape()writeshidden = true(:809). An animated hide ends incloseOrHide(false)(:424), so acloseAction: 'close'dialog is destroyed and firesclose; a non-animated hide keeps it alive and fires nothing. The example re-enables its button onclose, so with Animated unchecked, Escape leaves it disabled for good.The Architectural Reality
Design authority:
"If we are hidden, or unmounted while we still contain focus, we have to revert focus to where it came from if possible" —
component.Base#onFocusEnter(src/component/Base.mjs:1858)."Otherwise, the mask needs to be below the next topmost modal dialog if possible, or hidden" —
Neo.main.DomAccess#syncModalMask(src/main/DomAccess.mjs:1672)."the close button, Escape and an animated hide all hide the dialog, where a stock dialog would destroy itself" —
Neo.desktop.WindowManager(src/desktop/WindowManager.mjs:13).The mask is one main-thread node.
DomAccess#syncModalMask({id, modal})puts it underidwhen that node is in the DOM, displayed and modal; else under the last.neo-modalin the DOM; else it removes the mask (:1664-1683). A departing dialog still in the DOM is that last.neo-modal, so a sync that arrives before the removal keeps the mask under it.component.Abstract#destroyremoves a body-rooted component withNeo.applyDeltas(windowId, {action: 'removeNode'})(src/component/Abstract.mjs:369). As #18850 measured, removals and later calls do not land in a fixed order: the reason for the 30 ms.DomAccess#focuswithrestoreFrom(:390) already waits for a departure and focuses only a lost focus.The three engine dialogs (
Neo.desktop.WindowManager's windows,Neo.board.CardEditor,Neo.timeline.EventEditor) usecloseAction: 'hide'.The Fix
DomAccess#syncModalMask: a sync for anidthat does not hold the mask (gone, hidden, ormodal: false) leavesidout of the topmost-modal search, so the result no longer depends on whether its removal has landed.dialog.Base#close: sync the mask withmodal: falsebeforedestroy(true).closeOrHide()loses its timer and its sync;close()andhide()each own theirs.dialog.Basehands focus back to its opener: the component focus came from, elseanimateTarget, through the existingrestoreFromhand-back, so a focus the user has moved elsewhere stays.closeOrHide(), the close button's path, so it honorscloseActionwith or without the animation.examples/dialog: Create Dialog stays enabled, since a disabled opener cannot take focus back. A click while its dialog is open does nothing.Acceptance Criteria
DomAccess#syncModalMaskskips a departing modal still in the DOM.animateTarget); a focus the user moved elsewhere meanwhile stays. Unit arms ondialog.Base.closeActionwith and without the animation: a'close'dialog firescloseand is destroyed, a'hide'dialog hides. Unit arm.examples/dialogkeeps its promise in all four rows of the Context table: focus is on Create Dialog after the close, the mask is gone, and Create Dialog opens a dialog again. A new e2e spec undertest/playwright/e2e/dialog/.Out of Scope
Avoided Traps
closeOrHide(): removal and call order is not fixed (#18850), so the sync must be right whichever lands first.animateTargetunconditionally: a focus the user moved during the close must stay where it is.Related
#21367 · defect-note
ed66cef6· #20448 (the hide path's mask sync) · #18850 (removal and call order) ·07b6933fd0(a destroyed instance'stimeout()rejects) · #21066.Live latest-open + closed sweep: checked the latest 20 open plus open and closed search ("dialog mask", "dialog focus", "modal mask", "dialog Escape") at 2026-11-19T02:10Z; #4547, #4548 and #18850 read, none governs the close path's mask or the opener. 74 open, red band: folds under #21367. A2A in-flight sweep: latest 30 messages in all read-states, newest 02:07:15Z; no claim on the dialog or the popover. MC sweep: "dialog close Escape restores focus to the opening button", "modal mask stays on the page after the dialog closes": 10 results; the one prior decision is #20448's sync for the hide path. Own-assignment sweep: 7 open, none overlapping.
Retrieval Hint: "dialog close leaves the modal mask up and focus on body; closeOrHide timeout after destroy; opener animateTarget focus return"