Context
In the engine Workstation (apps/workstation, dev b52fd886e6), press a tab in one tabs node, then a tab in another node. About 100 ms later, focus is back on the first tab.
Measured in Chromium at 1600×1000. The page logged focusin; revertFocus and Reconciler.reconcileProjection were wrapped in the App worker over CDP.
- 926 ms: press
activity in heavy-tabs. Focus enters its tab button.
- 1,759 ms: press
audit in right-top-tabs. Focus enters its button.
- 1,855 ms: focus is back on
activity's button. In between, the dock refresh that the second press committed destroyed three containers that still held containsFocus. Each one's revertFocus() focused its focusEnterData.relatedTarget: the first tab.
Both presses committed full rebuilds: reconcileProjection ran with retainTopology and geometryOnly false, and returned landedInPlace: false.
The Problem
- The user's choice is taken back. The pressed tab loses focus to the one pressed before it.
- The focus-gated header actions leave with it. A tab header's pop-out, maximize and close are focus-gated.
contextualActionsVisible follows the tab container's containsFocus (src/toolbar/Base.mjs:568). After the revert, the second node's actions leave the DOM again: a pointer user loses the action they were about to press, and a keyboard user loses their place.
- The window is short, so it reads as flakiness. The actions appear for about 100 ms after the press, then withdraw. A test that polls every 25–100 ms usually catches them; one that waits longer, or runs while the App worker is busy, does not.
The Architectural Reality
Component#revertFocus (src/component/Base.mjs:1944) focuses focusEnterData.relatedTarget through that component's own focus() while containsFocus is true. It runs on destroy (:1436), on unmount (:847) and on show (:605).
focus() is routed by three overrides: form/field/Select and form/field/Text focus their input element, and list/Base navigates through main.addon.Navigator.
Workspace#refreshDockWorkspace (src/dashboard/dock/Workspace.mjs:2675) runs Reconciler.reconcileProjection (src/dashboard/dock/projection/Reconciler.mjs:463). That call moves the surviving tab container into a new shell and destroys the old containers through container.remove (:678). The destroyed containers were ancestors of the pressed tab.
- Order:
destroy() reverts first and its DOM removal follows in a later delta. So when the focus request reaches the main thread, the departing containers still contain the new focus. A guard that reads the DOM at that moment cannot tell this case from a real loss.
- Design authority: "A worker decides focus one round trip late, so a choice the user made in between, such as a picked list item, would otherwise be taken back." (
DomAccess#focus, the unlessFocusWithin JSDoc, src/main/DomAccess.mjs:369–371). #18927 holds the same rule for a reprojected editor.
The Fix
- Decide after the departure.
revertFocus() asks the main thread to settle first. Once the departing element has left the document, or a short bound has passed, focus counts as lost only if it fell to the body. Only then does the revert call the target component's focus(), so the three overrides still route it. A focus the user moved elsewhere stays where it is.
- Keep the revert where it belongs. A component destroyed with the focused element inside still hands focus back. These are the cases of #18847 and #18850.
- The show path (
afterSetHidden, :605) reverts when a component becomes visible. The PR states whether it shares the settle, since nothing departs there.
Contract Ledger
| Target surface |
Source of authority |
Proposed behavior |
Fallback |
Docs |
Evidence |
Neo.main.DomAccess, a new settle read |
the unlessFocusWithin JSDoc of focus() |
resolves once a given element has left the document (or a bound passes) and reports whether focus fell to the body |
element already gone: decide at once |
the method's JSDoc |
a unit arm per branch |
Component#revertFocus |
its call sites in src/component/Base.mjs |
focuses relatedTarget only when the settle reports a loss |
none |
its JSDoc |
the e2e below |
Acceptance Criteria
Out of Scope
- Why an active-tab change commits a full rebuild (
retainTopology: false). It costs a shell per press, and it is the dock's call; I asked its owner separately.
Avoided Traps
- Checking
containsFocus in the worker before reverting: it lags the DOM by a round trip. #18927 measured the same lag.
- A guard that reads the DOM when the request arrives: the departing container still holds the new focus then (see Order).
- Restoring focus to
relatedTarget's DOM id directly: it bypasses the overrides that route a field's or a list's focus.
- Dropping
revertFocus() from destroy: a destroyed component that held focus must still hand it back.
- Waiting in tests: that hides a defect users hit.
Related
#18927, #18850, #18847, #20046, #19983
Live latest-open + closed sweep:
- Open: the latest 20 (47 open, orange band). No owning ticket or epic.
- Closed: searches for
revertFocus, "focus tab back dock refresh" and "focus-gated header action tab press", at 17:11Z Nov 14. No equivalent. I read the same-surface hits: #18927 (Fix, AC-1), #18850 (Fix, Out of Scope, Avoided Traps), #20046 (Out of Scope), and #19186, which concerns a parked vessel. None covers the destroyed ancestors of a reprojection.
- A2A claims (all read states, to 17:07Z): none on dock or tab focus.
- Memory Core: adjacent prior work only (the overflow tab-press hold).
- My own assignments: #20911, #20884 and #20790 do not touch focus.
Body corrected (author, 17:2xZ): the first Fix had the guard read the DOM when the request arrives. The Order line above shows why that cannot work.
Retrieval Hint: "tab press focus returns to previous tab dock refresh revertFocus destroyed ancestor containsFocus focus-gated header actions settle after departure"
Context
In the engine Workstation (
apps/workstation,devb52fd886e6), press a tab in one tabs node, then a tab in another node. About 100 ms later, focus is back on the first tab.Measured in Chromium at 1600×1000. The page logged
focusin;revertFocusandReconciler.reconcileProjectionwere wrapped in the App worker over CDP.activityinheavy-tabs. Focus enters its tab button.auditinright-top-tabs. Focus enters its button.activity's button. In between, the dock refresh that the second press committed destroyed three containers that still heldcontainsFocus. Each one'srevertFocus()focused itsfocusEnterData.relatedTarget: the first tab.Both presses committed full rebuilds:
reconcileProjectionran withretainTopologyandgeometryOnlyfalse, and returnedlandedInPlace: false.The Problem
contextualActionsVisiblefollows the tab container'scontainsFocus(src/toolbar/Base.mjs:568). After the revert, the second node's actions leave the DOM again: a pointer user loses the action they were about to press, and a keyboard user loses their place.The Architectural Reality
Component#revertFocus(src/component/Base.mjs:1944) focusesfocusEnterData.relatedTargetthrough that component's ownfocus()whilecontainsFocusis true. It runs on destroy (:1436), on unmount (:847) and on show (:605).focus()is routed by three overrides:form/field/Selectandform/field/Textfocus their input element, andlist/Basenavigates throughmain.addon.Navigator.Workspace#refreshDockWorkspace(src/dashboard/dock/Workspace.mjs:2675) runsReconciler.reconcileProjection(src/dashboard/dock/projection/Reconciler.mjs:463). That call moves the surviving tab container into a new shell and destroys the old containers throughcontainer.remove(:678). The destroyed containers were ancestors of the pressed tab.destroy()reverts first and its DOM removal follows in a later delta. So when the focus request reaches the main thread, the departing containers still contain the new focus. A guard that reads the DOM at that moment cannot tell this case from a real loss.DomAccess#focus, theunlessFocusWithinJSDoc,src/main/DomAccess.mjs:369–371). #18927 holds the same rule for a reprojected editor.The Fix
revertFocus()asks the main thread to settle first. Once the departing element has left the document, or a short bound has passed, focus counts as lost only if it fell to the body. Only then does the revert call the target component'sfocus(), so the three overrides still route it. A focus the user moved elsewhere stays where it is.afterSetHidden,:605) reverts when a component becomes visible. The PR states whether it shares the settle, since nothing departs there.Contract Ledger
Neo.main.DomAccess, a new settle readunlessFocusWithinJSDoc offocus()Component#revertFocussrc/component/Base.mjsrelatedTargetonly when the settle reports a lossAcceptance Criteria
devfirst.relatedTarget, through the target's ownfocus().Out of Scope
retainTopology: false). It costs a shell per press, and it is the dock's call; I asked its owner separately.Avoided Traps
containsFocusin the worker before reverting: it lags the DOM by a round trip. #18927 measured the same lag.relatedTarget's DOM id directly: it bypasses the overrides that route a field's or a list's focus.revertFocus()from destroy: a destroyed component that held focus must still hand it back.Related
#18927, #18850, #18847, #20046, #19983
Live latest-open + closed sweep:
revertFocus, "focus tab back dock refresh" and "focus-gated header action tab press", at 17:11Z Nov 14. No equivalent. I read the same-surface hits: #18927 (Fix, AC-1), #18850 (Fix, Out of Scope, Avoided Traps), #20046 (Out of Scope), and #19186, which concerns a parked vessel. None covers the destroyed ancestors of a reprojection.Body corrected (author, 17:2xZ): the first Fix had the guard read the DOM when the request arrives. The Order line above shows why that cannot work.
Retrieval Hint: "tab press focus returns to previous tab dock refresh revertFocus destroyed ancestor containsFocus focus-gated header actions settle after departure"