An open-source, faster Devin alternative
TypeScript
docs(web): compress floating-layer comments to signal-only
Igor Zalutskie3b5f1bb1b76
diff --git a/web/src/components/form.tsx b/web/src/components/form.tsxindex 3fa727f0..b4e7ef08 100644--- a/web/src/components/form.tsx+++ b/web/src/components/form.tsx@@ -51,9 +51,7 @@ export function Select({<SelectPrimitive.Contentposition="popper"sideOffset={4}- // Mark the gesture that closes this menu so a parent Dialog/Sheet- // doesn't dismiss on the retargeted tail of the same click. See- // floating-layer.ts for the full rationale.+ // Don't let closing this menu dismiss a parent Dialog (floating-layer.ts).onPointerDownOutside={markFloatingLayerPointerDismiss}className="bg-popover text-popover-foreground ring-foreground/10 shadow-overlay data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 z-50 max-h-(--radix-select-content-available-height) min-w-(--radix-select-trigger-width) origin-(--radix-select-content-transform-origin) overflow-hidden rounded-lg p-1 ring-1 duration-100">diff --git a/web/src/components/ui/dialog.tsx b/web/src/components/ui/dialog.tsxindex 5bdee216..6bf252d8 100644--- a/web/src/components/ui/dialog.tsx+++ b/web/src/components/ui/dialog.tsx@@ -6,11 +6,8 @@ import { Button } from '@/components/ui/button'import { XIcon } from 'lucide-react'import { shouldKeepParentOpenForFloatingLayer } from '@/components/ui/floating-layer'-// Radix dismisses a modal Dialog on any "outside" interaction. A Select/dropdown-// inside the dialog portals out, so interacting with it — or, worse, the-// retargeted tail of the click that closes it — reads as outside and wrongly-// closes the dialog. preventDefault() on these handlers is Radix's intended-// override; the decision of when to override lives in floating-layer.ts.+// A portaled Select/dropdown inside the dialog reads as an "outside" click and+// wrongly dismisses it; suppress that case (why/when: floating-layer.ts).function keepDialogOpenForFloatingLayer(event: Event) {if (shouldKeepParentOpenForFloatingLayer(event)) event.preventDefault()}diff --git a/web/src/components/ui/dropdown-menu.tsx b/web/src/components/ui/dropdown-menu.tsxindex 8bd8ea88..7fb71904 100644--- a/web/src/components/ui/dropdown-menu.tsx+++ b/web/src/components/ui/dropdown-menu.tsx@@ -47,8 +47,7 @@ function DropdownMenuContent({'bg-popover text-popover-foreground ring-foreground/10 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 shadow-overlay z-50 max-h-(--radix-dropdown-menu-content-available-height) w-(--radix-dropdown-menu-trigger-width) min-w-32 origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-lg p-1 ring-1 duration-100 data-[state=closed]:overflow-hidden',className,)}- // Mark the gesture that closes this menu so a parent Dialog/Sheet doesn't- // dismiss on the retargeted tail of the same click (floating-layer.ts).+ // Don't let closing this menu dismiss a parent Dialog (floating-layer.ts).onPointerDownOutside={(event) => {markFloatingLayerPointerDismiss()onPointerDownOutside?.(event)@@ -248,8 +247,7 @@ function DropdownMenuSubContent({className,...props}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {- // No floating-layer guard here: a submenu is nested inside its parent menu, not- // a dialog, so it never produces the Select-in-Dialog dismiss (floating-layer.ts).+ // No guard: a submenu is nested in its parent menu, never a dialog.return (<DropdownMenuPrimitive.SubContentdata-slot="dropdown-menu-sub-content"diff --git a/web/src/components/ui/floating-layer.ts b/web/src/components/ui/floating-layer.tsindex 59598a50..8870f72d 100644--- a/web/src/components/ui/floating-layer.ts+++ b/web/src/components/ui/floating-layer.ts@@ -1,80 +1,35 @@/**- * Keep a parent Dialog/Sheet open when the user interacts with a Radix- * Select / DropdownMenu rendered inside it.+ * Keep a parent Dialog/Sheet open when a Radix Select/DropdownMenu inside it is+ * dismissed.*- * ── WHY THIS EXISTS ─────────────────────────────────────────────────────────- * Radix portals Select/DropdownMenu content to <body>, so the menu is a DOM- * sibling of the dialog, not a descendant. Radix's DismissableLayer normally- * shields the dialog while a menu is open (nested layers share a context, and a- * child layer's interaction is not treated as "outside" the parent). That- * shielding holds for the ordinary cases — but NOT for one specific, by-design- * Radix behavior that produces the bug we actually hit:- *- * `Select` is hardcoded `disableOutsidePointerEvents` and exposes no `modal`- * opt-out. While open it sets `pointer-events: none` on everything outside its- * menu. When you click the trigger a SECOND time to close the menu, that- * pointer-down hits the now-non-interactive trigger, closes the menu, and the- * TAIL of the same gesture (the pointerup/click, once pointer-events are- * restored) retargets onto the dialog overlay. The dialog reads that as an- * outside click and dismisses — even though the user only meant to close the- * menu. The menu has already left the layer stack by then, so Radix's native- * shielding can't catch it.- *- * Radix considers this intended and won't change it (primitives #2961 closed as- * not-planned; #2731 documents the "you have to click twice" behavior of- * `disableOutsidePointerEvents`). The blessed escape hatch is exactly what we- * use: Dialog/Sheet forward `onInteractOutside` / `onPointerDownOutside` /- * `onFocusOutside` into DismissableLayer, and we `preventDefault()` when an- * "outside" interaction is really part of a menu interaction.- *- * ── TWO SIGNALS (the two failure modes look different to the dialog) ─────────- * 1. ELEMENT — the interaction's target is inside a portaled popper, i.e. the- * user clicked into the menu itself. We match Radix's own marker- * `[data-radix-popper-content-wrapper]`, which Radix stamps on every popper- * layer (Select, DropdownMenu, Popover, …), so new floating components are- * covered for free without us tagging each one.- * 2. GESTURE — the second-click retarget above. Here the dialog's handler sees- * the dialog OVERLAY as the target (the menu is already gone), so signal (1)- * can't catch it. When a popper dismisses from a pointer interaction it calls- * `markFloatingLayerPointerDismiss()`, and we then swallow the dialog's- * dismiss for the rest of THAT single pointer gesture.- *- * ── WHY A GESTURE FLAG, NOT A TIMER ─────────────────────────────────────────- * An earlier version used a 500ms wall-clock window plus "is any popper mounted- * anywhere in the document". Both are too broad: they also swallow genuine- * backdrop clicks for 500ms after using a menu, and disable outside-dismiss- * entirely whenever any unrelated dropdown is mounted. The precise fact we want- * is "this is the same physical gesture that just closed a menu" — so we set a- * flag on the menu's pointer-dismiss and clear it at the very start of the next- * gesture (a fresh document `pointerdown`, capture phase, before Radix's own- * handlers run). The flag therefore survives exactly one gesture's- * pointerdown → pointerup → click and never a later, genuine outside click.- *- * ── A SHARP EDGE THAT WASTED EARLIER ATTEMPTS ───────────────────────────────- * Radix wraps the native event: `event.target` on the synthetic outside-event is- * the layer node, NOT the click target. The element check must read- * `event.detail.originalEvent.target`. Missing this is why prior tries at the- * `data-radix-popper-content-wrapper` guard silently did nothing.+ * Bug: Select hardcodes `disableOutsidePointerEvents` (no `modal` opt-out), so a+ * second click on its trigger closes the menu and that same gesture's tail+ * retargets onto the dialog overlay → the dialog dismisses. The menu has left+ * Radix's layer stack by then, so its native shielding can't catch it, and Radix+ * considers this by-design (primitives #2961, #2731). Fix = Radix's intended+ * override, preventDefault() on the dialog's outside handlers, when the "outside"+ * event is really a menu interaction — detected two ways:+ * 1. target is inside Radix's own `[data-radix-popper-content-wrapper]` (clicked+ * into the menu). Read detail.originalEvent.target, NOT event.target: Radix+ * wraps the event so event.target is the layer node — missing this silently+ * no-ops the guard, which is why earlier attempts failed.+ * 2. the retarget, where target is the overlay that (1) can't see: the popper+ * flags its dismissing gesture (below); we honor it until the next pointerdown.*/-// Radix's built-in marker on every portaled popper layer. Keying off Radix's own-// attribute (rather than a tag we add) means future floating components are-// covered automatically.const POPPER_WRAPPER_SELECTOR = '[data-radix-popper-content-wrapper]'type OutsideEventDetail = {originalEvent?: Event}-// True only between a popper's pointer-dismiss and the start of the next pointer-// gesture — i.e. for the single gesture whose retargeted tail would otherwise-// close the parent dialog.+// Set while a popper's dismissing gesture is in flight (signal 2). Cleared at the+// start of each gesture — capture phase, registered at module load, so it runs+// before Radix's per-menu handlers and the flag spans exactly one gesture+// (pointerdown→pointerup→click), never a later genuine backdrop click. A timer or+// "any popper mounted" check would instead swallow real outside clicks too.let swallowDialogDismissForGesture = false-// Clear the flag at the very start of every new gesture. Capture phase + a-// module-load registration means this runs before Radix's per-layer pointerdown-// handlers (which register later, when a menu opens), so the flag set during a-// gesture is never cleared within that same gesture — only at the next one.if (typeof document !== 'undefined') {document.addEventListener('pointerdown',@@ -92,22 +47,12 @@ function originalEventTarget(event: Event): EventTarget | null {return originalEvent?.target ?? event.target}-/**- * Call from a Select/DropdownMenu `onPointerDownOutside`. The pointer gesture- * that dismissed the menu is the one whose tail can retarget onto and close the- * parent dialog; this marks that gesture so the dialog ignores the resulting- * dismiss. (Item clicks and keyboard selection don't need this — they don't- * retarget outside the menu.)- */+// Call from a popper's onPointerDownOutside — the gesture whose tail can retarget+// onto and close the parent dialog. (Item clicks / keyboard don't retarget out.)export function markFloatingLayerPointerDismiss(): void {swallowDialogDismissForGesture = true}-/**- * True when a Dialog/Sheet outside-dismiss should be suppressed because it is- * really a menu interaction — either a click into a portaled popper (element- * signal) or the tail of the gesture that just dismissed one (gesture signal).- */export function shouldKeepParentOpenForFloatingLayer(event: Event): boolean {if (swallowDialogDismissForGesture) return truediff --git a/web/src/components/ui/sheet.tsx b/web/src/components/ui/sheet.tsxindex bcfdc67b..5497245d 100644--- a/web/src/components/ui/sheet.tsx+++ b/web/src/components/ui/sheet.tsx@@ -8,9 +8,7 @@ import { Button } from '@/components/ui/button'import { XIcon } from 'lucide-react'import { shouldKeepParentOpenForFloatingLayer } from '@/components/ui/floating-layer'-// Same Select/dropdown-dismiss guard as Dialog — a Sheet is a Radix Dialog under-// the hood, so a portaled menu inside it can wrongly dismiss it. See-// floating-layer.ts for the full rationale.+// A Sheet is a Radix Dialog; same Select/dropdown-dismiss guard (floating-layer.ts).function keepSheetOpenForFloatingLayer(event: Event) {if (shouldKeepParentOpenForFloatingLayer(event)) event.preventDefault()}