feat(devtools): add openAsModal to use the panel over app modal dialogs #550
- packages/devtools/src/hooks/use-modal-host.ts line 48Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +26,21 @@26+ // out against the viewport.27+ host.style.cssText =28+ 'position:fixed;inset:0;width:0;height:0;max-width:none;max-height:none;margin:0;padding:0;border:0;overflow:visible;background:transparent'29+ // Escape closes the panel through the devtools' own keydown handler, which30+ // also closes this dialog. Without preventDefault the browser then sends31+ // the same Escape to the app dialog and closes it too. The capture phase32+ // on the window sees the key wherever the focus is.33+ const onKeyDown = (event: KeyboardEvent) => {34+ if (host.open && event.key === 'Escape') event.preventDefault()35+ }36+ doc.defaultView?.addEventListener('keydown', onKeyDown, true)37+ // The dialog must never close by itself, or the root stays hidden in it.38+ host.addEventListener('cancel', (event) => event.preventDefault())39+ let home: Node | null = null40+41+ const sync = () => {42+ const appModalOpen = Array.from(doc.querySelectorAll('dialog')).some(43+ (dialog) => dialog !== host && dialog.matches(':modal'),44+ )45+ if (isOpen() && appModalOpen) {46+ if (host.open) returnpackages/devtools/src/hooks/use-modal-host.ts lines 78 to 82Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +43,21 @@43+ (dialog) => dialog !== host && dialog.matches(':modal'),44+ )45+ if (isOpen() && appModalOpen) {46+ if (host.open) return47+ home = element.parentNode48+ host.append(element)49+ doc.body.append(host)50+ host.showModal()51+ } else if (host.open) {52+ host.close()53+ home?.appendChild(element)54+ host.remove()55+ }56+ }57+58+ // `showModal()` and `close()` toggle the `open` attribute.59+ const observer = new MutationObserver(sync)60+ observer.observe(doc.documentElement, {61+ subtree: true,62+ attributeFilter: ['open'],63+ })
- @@ -0,0 +25,21 @@25+ // A zero-size box: the devtools are `position: fixed`, so they still lay26+ // out against the viewport.27+ host.style.cssText =28+ 'position:fixed;inset:0;width:0;height:0;max-width:none;max-height:none;margin:0;padding:0;border:0;overflow:visible;background:transparent'29+ // Escape closes the panel through the devtools' own keydown handler, which30+ // also closes this dialog. Without preventDefault the browser then sends31+ // the same Escape to the app dialog and closes it too. The capture phase32+ // on the window sees the key wherever the focus is.33+ const onKeyDown = (event: KeyboardEvent) => {34+ if (host.open && event.key === 'Escape') event.preventDefault()35+ }36+ doc.defaultView?.addEventListener('keydown', onKeyDown, true)37+ // The dialog must never close by itself, or the root stays hidden in it.38+ host.addEventListener('cancel', (event) => event.preventDefault())39+ let home: Node | null = null40+41+ const sync = () => {42+ const wanted =43+ isOpen() &&44+ Array.from(doc.querySelectorAll('dialog')).some(45+ (dialog) => dialog !== host && dialog.matches(':modal'),
AlemTuzlak merged this7b5f1ee
AlemTuzlak closed this
Sign in to join this conversation.
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
📝 Walkthrough
Walkthrough#
The change adds an
openAsModalsetting for Devtools. When enabled, Devtools can appear above an application modal dialog. The change also adds configuration documentation, a demo setup, and Playwright coverage.Changes#
Devtools modal dialog support
packages/devtools/src/context/devtools-store.ts,packages/devtools/src/devtools.tsx,docs/configuration.md,.changeset/open-as-modal.mdopenAsModal, defaulting tofalse.DevToolspasses the setting, root element, and open state tocreateModalHost. The documentation and changeset describe the option.packages/devtools/src/hooks/use-modal-host.tscreateModalHostcreates a dialog host when enabled. When Devtools is open and another dialog is modal, it moves the Devtools root into the host and opens it modally. It restores the root when hosting ends and cleans up its listeners and observer.e2e/apps/react-vite/src/main.tsx,e2e/apps/react-vite/tests/open-as-modal.spec.tsPriority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Feature · Severity of issue fixed: Medium
Sequence Diagram(s)#
Merge Risk: 🟡 Moderate · up to
17321Devtools can remain inaccessible while an app dialog is open, including when an input has focus or the dialog is inside a shadow root. Resolve these gaps before merging unless those limitations are explicitly accepted.
Security Architecture Review#
Security architecture risk: 🔵 Low · up to
17321The change is disabled by default and its effects are limited to interaction within the application document. No introduced security vulnerability was established. Focus restoration and exceptional cleanup states remain incompletely verified.
Retained concerns No architecture-level concerns identified.
Security review details
Security Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
#369requires usable Devtools interaction when an HTML modal dialog blocks the page. The PR addsopenAsModal, defaulting tofalse. When enabled,createModalHostdetects an app:modaldia…#369. The store, documentation, and changeset define the public option. The modal host implements the dialog interaction. The demo and Playwright tests exercise the fea…✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share