One Modal, and close-on-Escape that actually fires #173
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/shared-modal"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Now targets
maindirectly — #170 and #172 merged while this was being written, and Forgejo retargeted it. One commit, six files.Came out of the
/simplifypass 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:
document.activeElementPassphraseRotationModalBUTTON.btnBUTTON.btn smInstallSkillModalBUTTON.btn sm primaryNewWorkerModalINPUTLogsModalInstallSkillModalwas doubly dead: its box also calledstopPropagation()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.
Modaltakes 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
Modalcould 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, itsmax-height: 90vh) would have had to become a prop, andModalwould 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 useapp.css's global.overlay-box;NewWorkerModalkeeps 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 elementModalitself renders, so it cannot live in the caller.Two behaviour changes beyond the fix
LogsModalgains 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 build0.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):PassphraseRotationModalInstallSkillModalNewWorkerModalLogsModalBackdrop-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.
901c18acace9f1ab7279e9f1ab7279ffecc147e0