Files
deepseek-harness/apps
imccyu 7b4340ecd9 fix(client): adopt document portal hooks and realm-independent DOM checks in business plugins (#9170)
* fix(ui-renderer): let shell body-layer rules reach document portal content

The document portal wraps its children in a box-less `display: contents`
element, so the web shell's macOS `body > :not(#root)` window-drag
subtraction landed on that wrapper and no longer reached the portaled
layer. Mark the wrapper `data-document-portal` and subtract its children
in base.css, and document the wrapper and the portal's mount timing.

* fix(client): adopt document hooks and realm-independent DOM checks in plugins

Script-isolated plugins run in a hidden iframe whose `document`, `Node`,
and `Element` belong to that frame while React renders into the page.

- Replace `createPortal(..., document.body)` in business plugins with the
  mounted Slot's `useDocumentPortal()` and move Escape listeners that only
  serve that portaled content onto the portal's `onKeyDown[Capture]`.
- Drop or replace DOM `instanceof` checks on page objects with checks that
  do not depend on the realm and behave the same without isolation.
- Recognize a pending context-menu answer by its `then` method instead of
  `instanceof Promise`, so providers and the menu can sit in different realms.

* fix(client): keep the skips of replaced DOM checks for other targets

Several `instanceof` replacements asserted that an event target is an
element or a node and then called `closest()` or `contains()` on it. The
original checks skipped other targets, such as a text node, the document,
or a window, and a spec that right-clicks a text node now threw. Check
`nodeType`, `namespaceURI`, or `localName` instead, so every site keeps its
original skip while still recognizing the page's nodes from an isolated realm.

* fix(client): satisfy CI gates for the document hook adoption

- Re-record the ui-renderer README translation pair after the business
  plugin section gained the portal wrapper and timing sentences.
- Drop an apostrophe from a JSX attribute comment in the plugin manager;
  the app-region markup scan reads it as a string opener and misses the
  `.moreHead` chrome row.
- Write the context-menu and subagent switcher outside-pointer checks as
  node guards inside the condition, as the original `instanceof Node`
  checks were, so no unreachable early return remains uncovered.

* refactor(client): use page DOM targets through optional calls instead of node guards

The realm-independent DOM checks wrapped event targets and focused
elements in `isNode`, `isElement`, and `isHtmlElement` helpers or inline
`nodeType`, `namespaceURI`, and `localName` tests. Treat a target as the
element it almost always is instead:

- Pass targets of document and element listeners straight to
  `contains()`, which accepts any node, and treat `activeElement` as an
  HTML element.
- Read element methods through `Partial<Element>` with optional calls, so
  a text node or the document, which lacks the method, counts as no match,
  as the original `instanceof` checks skipped it.
- Resolve "the element or its parent" lookups by falling back from
  `closest?.()` to `parentElement.closest()`.
- Compare the model menu's key target with its search field, and test
  inputs and iframes with `matches()`.

Two checks stay: the type filter's window-level listener skips the window
itself, which `contains()` rejects, by comparing the target with
`currentTarget`; the selected-text projection keeps its node-kind test, so
comments still project nothing and own no offsets.

Tests that fed impossible targets to the removed skips (a non-node
pointer target, a keydown from an unfocusable icon) are dropped, and the
platform overlay test now covers a focus origin removed while the overlay
is open instead of a focused SVG element.

* revert(client): keep ui-schedule and the ui-chat stat dialogs on their body portals

Restore packages/client/ui-schedule and the ui-chat stat dialogs
(stat-dialog.ts, StatsPills.tsx, TurnUsagePanel.tsx, and the
TurnTailNodeView wiring) to their master versions, together with their
unit tests and the Schedule catalog e2e assertion on the body child.
These plugins adopt the document portal in a later change.

* fix(ui-renderer): mount document portal content in the portal's own commit

The document portal renders into a wrapper element it owns. The wrapper
joins the body and takes the source's package marker from a ref on the
preceding template, so the children are attached and scoped before
their layout effects run, and the caller's effects receive mounted
nodes. Unmounting removes the wrapper; StrictMode replay appends it
again.

Callers render the portal together with the content it shows instead of
keeping an empty portal mounted: the context meter, model menu, install
registry options, font notice, Session inspector type filter, and
desktop onboarding entry.
2026-11-25 18:04:18 +08:00
..
2026-11-22 15:27:28 +08:00