fix(web-shell): read the parked focus node from its own root (C2)

In shadow-DOM portal mode document.activeElement retargets to the shadow
host, so the page's parked-focus comparisons to body/sessions nav/discard
node were always false and the composer latch treated a click inside the
pane as a real move. Resolve the active element from the page wrapper's
own root, as App and the other focus users already do.
This commit is contained in:
yiliang114 committed 2026-11-07 21:10:58 +08:00
1 parent 4ff6673101
commit a0e9a089d6
1 file changed
+5 -2
@@ -88,6 +88,7 @@ import { ManagedChildSessionView } from './ManagedChildSessionView';
import { useManagedTaskCancel } from './use-managed-task-cancel';
import { TodoFullList } from '../messages/TodoView';
import { getLatestSuccessfulTodos } from '../../utils/todos';
import { getShadowAwareActiveElement } from '../../utils/dom';
import type {
ManagedAgentProvider,
ManagedAgentSessionSummary,
@@ -862,7 +863,9 @@ function ManagedSessionsContent({
const composer = composerContainerRef.current?.querySelector(
'[contenteditable="true"], textarea:not([disabled])',
);
const parked = document.activeElement;
// document.activeElement retargets to the shadow host in portal mode; read
// the focused node from the page wrapper's own root instead.
const parked = getShadowAwareActiveElement(pageRef.current);
// hostSessionOnly renders no list, so the fallback below parks focus on the
// page wrapper; the latch accepts the node it parked on itself, so a user
// who merely clicked inside that pane is still recognised as having moved
@@ -2916,7 +2919,7 @@ function ManagedSessionsContent({
clientId,
root: sessionId,
child,
trigger: document.activeElement,
trigger: getShadowAwareActiveElement(pageRef.current),
})
}
cancel={taskCancel}