One Modal, and close-on-Escape that actually fires #173

Merged
lz merged 2 commits from feat/shared-modal into main 2026-09-17 15:18:19 +02:00
Owner

Now targets main directly — #170 and #172 merged while this was being written, and Forgejo retargeted it. One commit, six files.

Came out of the /simplify pass on #172.

The CSS was the symptom

Five components each declared their own backdrop: NewWorkerModal, LogsModal, InstallSkillModal, PassphraseRotationModal, and the MCP panel's remove dialog. Two of them were near byte-identical. #171 adds more dialogs to Settings → MCP, so the next one would have been a sixth.

Deduplicating that was the stated finding. It is not the part that mattered.

Close-on-Escape was hand-copied, and dead in three of the five

The keydown handler sits on the backdrop. Opening a dialog leaves focus on the button that opened it — outside the dialog — so the event bubbles up a different branch and never arrives.

Measured with each dialog open, on shipped code:

Dialog document.activeElement Escape
PassphraseRotationModal BUTTON.btn dead
MCP panel remove BUTTON.btn sm dead
InstallSkillModal BUTTON.btn sm primary dead
NewWorkerModal its own search INPUT worked
LogsModal — no handler at all

InstallSkillModal was doubly dead: its box also called stopPropagation() on keydown, so even a focused box could not have reached the handler.

It reads as working code in every one of them. That is how it survived review in three shipped components, and four review agents on the fourth — all of them read the handler, none pressed the key.

Modal takes focus on mount. That is what makes Escape fire, and it is the right thing for a modal regardless.

Modal owns behaviour, not appearance

The caller renders its own box as children.

This is the design decision worth reviewing. A box element rendered inside Modal could not be styled by its caller at all — Svelte scoping only reaches a component's own template — so anything carrying a media query (NewWorkerModal's full-screen mobile sheet, its max-height: 90vh) would have had to become a prop, and Modal would have grown a prop per caller. Owning only the backdrop keeps the shared part genuinely shared and leaves the varying part where it varies. Three callers use app.css's global .overlay-box; NewWorkerModal keeps its own head/body/foot sheet.

The one exception is sheetOnMobile, which drops the backdrop's centring and padding below 600px. That rule targets the element Modal itself renders, so it cannot live in the caller.

Two behaviour changes beyond the fix

  • LogsModal gains close-on-Escape. It previously had no handler, so the key simply did nothing.
  • NewWorkerModal's Escape now also works with no provider connected. Its search input was the only thing focused, and that input does not render in that state — so the one dialog that worked had a hole in it too.

Verification

Gates run separately: typecheck 0 errors · 2190 tests · lint clean · pnpm build 0.

Driven in a browser against a real instance, every dialog, after the final API (the first two were re-checked, because Modal's shape changed after their first pass):

Dialog focus on open Escape renders as before
MCP panel remove overlay closes ✓
PassphraseRotationModal overlay closes ✓
InstallSkillModal overlay closes ✓
NewWorkerModal its search input closes ✓
LogsModal overlay closes ✓

Backdrop-click was checked too and still closes. None of this is reachable from vitest — it runs node with no DOM, which is why the bug lived this long.

Now targets `main` directly — #170 and #172 merged while this was being written, and Forgejo retargeted it. One commit, six files. Came out of the `/simplify` pass on #172. ## The CSS was the symptom Five components each declared their own backdrop: `NewWorkerModal`, `LogsModal`, `InstallSkillModal`, `PassphraseRotationModal`, and the MCP panel's remove dialog. Two of them were near byte-identical. #171 adds more dialogs to Settings → MCP, so the next one would have been a sixth. Deduplicating that was the stated finding. It is not the part that mattered. ## Close-on-Escape was hand-copied, and dead in three of the five The keydown handler sits on the backdrop. Opening a dialog leaves focus on **the button that opened it** — outside the dialog — so the event bubbles up a different branch and never arrives. Measured with each dialog open, on shipped code: | Dialog | `document.activeElement` | Escape | |---|---|---| | `PassphraseRotationModal` | `BUTTON.btn` | dead | | MCP panel remove | `BUTTON.btn sm` | dead | | `InstallSkillModal` | `BUTTON.btn sm primary` | dead | | `NewWorkerModal` | its own search `INPUT` | worked | | `LogsModal` | — | no handler at all | `InstallSkillModal` was **doubly** dead: its box also called `stopPropagation()` on keydown, so even a focused box could not have reached the handler. It reads as working code in every one of them. That is how it survived review in three shipped components, and four review agents on the fourth — all of them read the handler, none pressed the key. `Modal` takes focus on mount. That is what makes Escape fire, and it is the right thing for a modal regardless. ## Modal owns behaviour, not appearance The caller renders its own box as children. This is the design decision worth reviewing. A box element rendered *inside* `Modal` could not be styled by its caller at all — Svelte scoping only reaches a component's own template — so anything carrying a media query (`NewWorkerModal`'s full-screen mobile sheet, its `max-height: 90vh`) would have had to become a prop, and `Modal` would have grown a prop per caller. Owning only the backdrop keeps the shared part genuinely shared and leaves the varying part where it varies. Three callers use `app.css`'s global `.overlay-box`; `NewWorkerModal` keeps its own head/body/foot sheet. The one exception is `sheetOnMobile`, which drops the backdrop's centring and padding below 600px. That rule targets the element `Modal` itself renders, so it cannot live in the caller. ## Two behaviour changes beyond the fix - **`LogsModal` gains close-on-Escape.** It previously had no handler, so the key simply did nothing. - **`NewWorkerModal`'s Escape now also works with no provider connected.** Its search input was the only thing focused, and that input does not render in that state — so the one dialog that worked had a hole in it too. ## Verification Gates run separately: typecheck 0 errors · **2190 tests** · lint clean · `pnpm build` 0. Driven in a browser against a real instance, **every dialog, after the final API** (the first two were re-checked, because `Modal`'s shape changed after their first pass): | Dialog | focus on open | Escape | renders as before | |---|---|---|---| | MCP panel remove | overlay | closes | ✓ | | `PassphraseRotationModal` | overlay | closes | ✓ | | `InstallSkillModal` | overlay | closes | ✓ | | `NewWorkerModal` | its search input | closes | ✓ | | `LogsModal` | overlay | closes | ✓ | Backdrop-click was checked too and still closes. None of this is reachable from vitest — it runs node with no DOM, which is why the bug lived this long.
refactor(ui): one Modal, and close-on-Escape that actually fires
Some checks failed
ci / nexus (pull_request) Successful in 12m44s
ci / images (pull_request) Has been cancelled
901c18acac
There were three independent implementations of "backdrop + centred box +
Escape/click-outside" under components/ — NewWorkerModal,
PassphraseRotationModal, and the MCP panel's remove dialog — two of them near
byte-identical. #171 adds more dialogs to Settings → MCP, so the next one
would have been a fourth.

The duplication that mattered was not the CSS. It was close-on-Escape, which
was hand-copied and BROKEN IN EVERY COPY: the keydown handler sits on the
dialog, but opening a dialog leaves focus on the button that opened it —
outside the dialog — so the event bubbles up a different branch and the
handler never fires. Measured on main before this change: with the passphrase
dialog open, document.activeElement was `BUTTON.btn` and Escape did nothing.
It reads as working code, which is how it survived review in two components
and four review agents on the third.

Modal takes focus on mount, which is what makes Escape work and is the right
thing for a modal regardless. Chrome comes from app.css's .overlay/.overlay-box
— the shared vocabulary its own SCOPE header declares, already used by
LogsModal and InstallSkillModal — rather than a private copy.

Verified in a browser, both dialogs, both close paths: focus lands on
`DIV.overlay show`, Escape closes, a real backdrop click closes, and each
renders as it did before. None of this is reachable from vitest — it runs node
with no DOM.

NewWorkerModal is deliberately left alone: its chrome is a distinct
header/body/scroll drawer, not this shape, and folding it in would mean
reworking it rather than adopting a component.
lz changed target branch from feat/oauth-settings to main 2026-09-17 13:58:53 +02:00
lz force-pushed feat/shared-modal from 901c18acac
Some checks failed
ci / nexus (pull_request) Successful in 12m44s
ci / images (pull_request) Has been cancelled
to e9f1ab7279
Some checks failed
ci / images (pull_request) Has been cancelled
ci / nexus (pull_request) Has been cancelled
2026-09-17 14:08:51 +02:00
Compare
lz force-pushed feat/shared-modal from e9f1ab7279
Some checks failed
ci / images (pull_request) Has been cancelled
ci / nexus (pull_request) Has been cancelled
to ffecc147e0
Some checks failed
ci / images (pull_request) Has been cancelled
ci / nexus (pull_request) Has been cancelled
2026-09-17 14:28:15 +02:00
Compare
test(ui): pin that only Modal declares a dialog backdrop
All checks were successful
ci / nexus (pull_request) Successful in 10m9s
ci / images (pull_request) Successful in 12m58s
pr-image-cleanup / delete-pr-images (pull_request) Successful in 17s
3592767511
The behaviour cannot be unit tested here: environment is 'node' and .svelte
components have no DOM (vitest.config.ts says as much). Extracting the handler
would not help either — every broken copy already read
`if (e.key === 'Escape') onClose()`. The predicate was never wrong; the event
never arrived. A unit test of it passes on all three broken versions.

So this pins the invariant that keeps the fix in force: exactly one component
declares a backdrop. Behaviour is proven once, in a browser, against Modal;
this is what stops the next dialog growing its own backdrop and its own dead
Escape handler, which is how three of them got there. #171 adds more dialogs.

Both halves proven to fail. Reverting LogsModal to its own backdrop names it;
renaming the class inside Modal is caught by the second test, which exists
because that mutation makes the first one pass vacuously.

The negative control earned its keep immediately: the first version filtered
the owner with `f.endsWith('Modal.svelte')`, which also matches LogsModal,
NewWorkerModal, InstallSkillModal and PassphraseRotationModal — four of the
five files silently excluded, and the mutation SURVIVED. Compares basename now.
lz merged commit 08ff33073c into main 2026-09-17 15:18:19 +02:00
lz deleted branch feat/shared-modal 2026-09-17 15:18:20 +02:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lz/agent-nexus!173
No description provided.