Skip to content

πŸͺ’ Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

refactor(web): move all Radix/Vaul overlays onto the layer system (LFE-10471) (#14491)

Nikita Kabardin1bdd6cea8644
diff --git a/packages/eslint-plugin/src/index.ts b/packages/eslint-plugin/src/index.ts
index 8e238252d5..86a8ecef2a 100644
--- a/packages/eslint-plugin/src/index.ts
+++ b/packages/eslint-plugin/src/index.ts
@@ -1,11 +1,13 @@
import { default as noTailwindOverflowScroll } from "./rules/no-tailwind-overflow-scroll.js";
import { default as noInSourceVitest } from "./rules/no-in-source-vitest.js";
+import { default as noOverlayZindex } from "./rules/no-overlay-zindex.js";
import { default as noStyleProps } from "./rules/no-style-props.js";
import { default as noUnnecessaryCn } from "./rules/no-unnecessary-cn.js";
export const plugin = {
rules: {
"no-in-source-vitest": noInSourceVitest,
+ "no-overlay-zindex": noOverlayZindex,
"no-style-props": noStyleProps,
"no-tailwind-overflow-scroll": noTailwindOverflowScroll,
"no-unnecessary-cn": noUnnecessaryCn,
diff --git a/packages/eslint-plugin/src/rules/no-overlay-zindex.test.ts b/packages/eslint-plugin/src/rules/no-overlay-zindex.test.ts
new file mode 100644
index 0000000000..701c822c15
--- /dev/null
+++ b/packages/eslint-plugin/src/rules/no-overlay-zindex.test.ts
@@ -0,0 +1,182 @@
+import { RuleTester } from "@typescript-eslint/rule-tester";
+import * as typescriptEslintParser from "@typescript-eslint/parser";
+import { describe, expect, it, vi } from "vitest";
+import rule from "./no-overlay-zindex.js";
+
+const ruleTester = new RuleTester({
+ languageOptions: {
+ parser: typescriptEslintParser,
+ parserOptions: {
+ ecmaFeatures: {
+ jsx: true,
+ },
+ },
+ },
+});
+
+ruleTester.run("no-overlay-zindex", rule, {
+ valid: [
+ // Local, within-layer z-index for ordering content is fine.
+ `<div className="sticky top-0 z-30" />`,
+ `<div className="z-10" />`,
+ `<div className="z-40" />`,
+ `<div className="z-0" />`,
+ `<div className="z-auto" />`,
+ `<div className="z-[40]" />`,
+ `<div className="fixed inset-0 bg-black/50" />`,
+ `const value = 42;`,
+ // not a z-index utility
+ `<div className="gap-50" />`,
+ `<div className="grid-cols-50" />`,
+ ],
+ invalid: [
+ {
+ code: `<div className="fixed inset-0 z-50" />`,
+ errors: [{ messageId: "unexpected" }],
+ },
+ {
+ code: `<div className="z-9999" />`,
+ errors: [{ messageId: "unexpected" }],
+ },
+ {
+ code: `<div className="z-[9999]" />`,
+ errors: [{ messageId: "unexpected" }],
+ },
+ {
+ code: `<div className="md:z-50" />`,
+ errors: [{ messageId: "unexpected" }],
+ },
+ {
+ code: `<div className="!z-50" />`,
+ errors: [{ messageId: "unexpected" }],
+ },
+ // Important modifier sitting AFTER the variant prefix.
+ {
+ code: `<div className="md:!z-50" />`,
+ errors: [{ messageId: "unexpected" }],
+ },
+ {
+ code: `<div className="hover:!z-9999" />`,
+ errors: [{ messageId: "unexpected" }],
+ },
+ {
+ code: `<div className="dark:!z-[9999]" />`,
+ errors: [{ messageId: "unexpected" }],
+ },
+ {
+ code: `<div className="z-50!" />`,
+ errors: [{ messageId: "unexpected" }],
+ },
+ {
+ code: `<div className="data-[state=open]:animate-in z-9999 overflow-hidden" />`,
+ errors: [{ messageId: "unexpected" }],
+ },
+ {
+ code: `const className = "bg-popover z-50 min-w-32";`,
+ errors: [{ messageId: "unexpected" }],
+ },
+ {
+ code: `const className = cn("flex z-[9999]", className);`,
+ errors: [{ messageId: "unexpected" }],
+ },
+ {
+ code: `<div className={\`fixed inset-0 z-50\`} />`,
+ errors: [{ messageId: "unexpected" }],
+ },
+ ],
+});
+
+// overlay-content mode: flag a high z-index ONLY when it sits on an overlay
+// content JSX element (name ends in `Content`), so the rule can run app-wide
+// without flagging local page-chrome z-index on plain elements.
+ruleTester.run("no-overlay-zindex (overlay-content mode)", rule, {
+ valid: [
+ // Local page-chrome z-index on plain elements β€” never flagged app-wide.
+ {
+ code: `<header className="sticky top-0 z-50 w-full" />`,
+ options: [{ mode: "overlay-content" }],
+ },
+ {
+ code: `<div className="fixed inset-x-0 z-50 flex" />`,
+ options: [{ mode: "overlay-content" }],
+ },
+ {
+ code: `<div className="z-9999" />`,
+ options: [{ mode: "overlay-content" }],
+ },
+ // A non-overlay component that happens to take z-index is left alone.
+ {
+ code: `<SidebarRail className="z-50" />`,
+ options: [{ mode: "overlay-content" }],
+ },
+ // Low z-index on an overlay content element is still fine.
+ {
+ code: `<DropdownMenuContent className="z-40" />`,
+ options: [{ mode: "overlay-content" }],
+ },
+ // A className string not attached to any JSX element (assigned to a var) is
+ // not attributable to an overlay, so it's left alone in this mode.
+ {
+ code: `const className = "z-50";`,
+ options: [{ mode: "overlay-content" }],
+ },
+ // A high z-index on a plain child element of an overlay content element is
+ // attributed to the child (a <div>), not the overlay β€” so not flagged.
+ {
+ code: `<DropdownMenuContent><div className="z-50" /></DropdownMenuContent>`,
+ options: [{ mode: "overlay-content" }],
+ },
+ // Namespaced JSX names carry no overlay-content semantics β†’ not flagged.
+ {
+ code: `<svg:Content className="z-50" />`,
+ options: [{ mode: "overlay-content" }],
+ },
+ ],
+ invalid: [
+ // High z-index on overlay content elements IS flagged, app-wide.
+ {
+ code: `<DropdownMenuContent className="z-60 min-w-56" />`,
+ options: [{ mode: "overlay-content" }],
+ errors: [{ messageId: "unexpected" }],
+ },
+ {
+ code: `<HoverCardContent className="z-50 w-[520px]" />`,
+ options: [{ mode: "overlay-content" }],
+ errors: [{ messageId: "unexpected" }],
+ },
+ {
+ code: `<TooltipContent className="relative isolate z-9999" />`,
+ options: [{ mode: "overlay-content" }],
+ errors: [{ messageId: "unexpected" }],
+ },
+ // className via cn(...) on an overlay content element is still attributed.
+ {
+ code: `<PopoverContent className={cn("z-50", className)} />`,
+ options: [{ mode: "overlay-content" }],
+ errors: [{ messageId: "unexpected" }],
+ },
+ // Member-expression element name (Primitive.Content) uses the trailing name.
+ {
+ code: `<DialogPrimitive.Content className="z-50" />`,
+ options: [{ mode: "overlay-content" }],
+ errors: [{ messageId: "unexpected" }],
+ },
+ ],
+});
+
+describe("no-overlay-zindex", () => {
+ it("ignores template elements with non-string raw values", () => {
+ const report = vi.fn();
+ const listeners = rule.create({
+ report,
+ } as never);
+
+ listeners.TemplateElement?.({
+ value: {
+ raw: null,
+ },
+ } as never);
+
+ expect(report).not.toHaveBeenCalled();
+ });
+});
diff --git a/packages/eslint-plugin/src/rules/no-overlay-zindex.ts b/packages/eslint-plugin/src/rules/no-overlay-zindex.ts
new file mode 100644
index 0000000000..b6d6feaa8b
--- /dev/null
+++ b/packages/eslint-plugin/src/rules/no-overlay-zindex.ts
@@ -0,0 +1,175 @@
+import { AST_NODE_TYPES, type TSESTree } from "@typescript-eslint/utils";
+
+import { createRule } from "../util.js";
+
+// Overlay wrappers (Dialog, Sheet, Popover, Select, Tooltip, …) must stack via
+// the app layer system (components/ui/layer.tsx) β€” each portals into a layer
+// `container` and the layers order by DOM order. A high/arbitrary z-index on an
+// overlay wrapper is the old "escape to the top of <body>" habit this migration
+// removed; it silently fights the layer order. z-index stays a LOCAL tool for
+// ordering content WITHIN a layer (a dialog's sticky header `z-30`, a footer
+// `z-10`, …), so only large values are banned.
+//
+// Banned: `z-50` and above, and arbitrary `z-[…]` whose value is >= the
+// threshold (e.g. `z-[9999]`). Allowed: `z-0`..`z-40`, `z-auto`, and small
+// arbitrary values.
+//
+// Two modes (set per-file via eslint.config, see `mode` option):
+// - "wrapper": ban a high z-index ANYWHERE in the file. Used on the `ui/*`
+// overlay primitive wrappers, where any high z-index is an escape.
+// - "overlay-content": ban a high z-index only when it sits on an overlay
+// *content* JSX element (e.g. `<DropdownMenuContent className="z-60">`,
+// `<HoverCardContent className="z-50">`, `<TooltipContent>`). These render
+// through a layer and must never carry a magic z-index β€” but plain page
+// chrome (`<header className="sticky z-50">`, fixed banners/toolbars) lives
+// inside the app's isolated `#__next` stacking context, can't escape it, so
+// its local z-index is fine and left untouched. This mode is enabled
+// app-wide so a consumer can't re-introduce an escape on an overlay it
+// imports (the very `nav-user.tsx` `z-60` regression this PR removed).
+const Z_INDEX_THRESHOLD = 50;
+
+type Mode = "wrapper" | "overlay-content";
+
+// Overlay content components route through a layer (their `*.Portal` injects a
+// layer `container`), so a high z-index on them is an escape. The names follow
+// the Radix-wrapper convention used in `components/ui/*`: an uppercase
+// component whose name ends in `Content` (DialogContent, SheetContent,
+// PopoverContent, DropdownMenuContent, SelectContent, HoverCardContent,
+// TooltipContent, AlertDialogContent, DropdownMenuSubContent, …). A bespoke
+// `<div>`/`<header>` page-chrome element never matches, so it isn't flagged.
+function isOverlayContentElementName(name: string): boolean {
+ // `DropdownMenuContent`, `HoverCardContent`, `DropdownMenuSubContent`, … and
+ // the bare Radix member form `Primitive.Content` (resolved to `Content`).
+ return name === "Content" || /^[A-Z][A-Za-z]*Content$/.test(name);
+}
+
+// Tailwind important modifiers can wrap a utility token in either position,
+// e.g. `!z-50` or `z-50!`.
+function normalizeTailwindToken(token: string): string {
+ return token.replace(/^!|!$/g, "");
+}
+
+// Strip a leading variant chain (`md:`, `dark:`, `data-[state=open]:`, …) to
+// the final utility token. Bracketed variant segments can themselves contain
+// colons, so split on top-level colons only.
+function stripVariants(token: string): string {
+ let depth = 0;
+ let lastSeparator = -1;
+ for (let i = 0; i < token.length; i++) {
+ const ch = token[i];
+ if (ch === "[") depth++;
+ else if (ch === "]") depth = Math.max(0, depth - 1);
+ else if (ch === ":" && depth === 0) lastSeparator = i;
+ }
+ return lastSeparator === -1 ? token : token.slice(lastSeparator + 1);
+}
+
+// Return the numeric z-index of a normalized utility token if it is a banned
+// overlay z-index, else null. Handles `z-50` and arbitrary `z-[9999]`.
+function overlayZIndexValue(utility: string): number | null {
+ const arbitrary = /^z-\[(-?\d+)\]$/.exec(utility);
+ if (arbitrary) {
+ const value = Number(arbitrary[1]);
+ return value >= Z_INDEX_THRESHOLD ? value : null;
+ }
+ const scale = /^z-(\d+)$/.exec(utility);
+ if (scale) {
+ const value = Number(scale[1]);
+ return value >= Z_INDEX_THRESHOLD ? value : null;
+ }
+ return null;
+}
+
+function* offendingZIndexUtilities(value: string): Generator<string> {
+ for (const match of value.matchAll(/\S+/g)) {
+ // Strip the variant chain first, THEN the important modifier. The `!` can
+ // sit after the variant prefix (`md:!z-50`, `hover:!z-9999`,
+ // `dark:!z-[9999]`); stripping variants first leaves `!z-50`, which
+ // normalizeTailwindToken then reduces to `z-50` so the matcher sees it.
+ const utility = normalizeTailwindToken(stripVariants(match[0]));
+ if (overlayZIndexValue(utility) !== null) yield utility;
+ }
+}
+
+// The tag name of the JSX opening element a className/style string belongs to,
+// or null if the string isn't attached to one. Walks up from a
+// Literal/TemplateElement through `cn(...)` args and the JSXExpressionContainer
+// to the owning JSXOpeningElement (e.g. "DropdownMenuContent"). Stops at the
+// first JSXElement boundary so a string in a *child* element isn't attributed
+// to its parent's opening tag.
+function enclosingJsxOpeningElementName(node: TSESTree.Node): string | null {
+ let current: TSESTree.Node | undefined = node.parent;
+ while (current && current.type !== AST_NODE_TYPES.JSXElement) {
+ if (current.type === AST_NODE_TYPES.JSXOpeningElement) {
+ const elementName = current.name;
+ // Plain `<DropdownMenuContent>` or member `<Primitive.Content>` β€” the
+ // trailing identifier is the meaningful name. Namespaced names (rare in
+ // this codebase) have no overlay-content semantics, so null is fine.
+ if (elementName.type === AST_NODE_TYPES.JSXIdentifier) {
+ return elementName.name;
+ }
+ if (elementName.type === AST_NODE_TYPES.JSXMemberExpression) {
+ return elementName.property.name;
+ }
+ return null;
+ }
+ current = current.parent;
+ }
+ return null;
+}
+
+const rule = createRule<[{ mode: Mode }], "unexpected">({
+ name: "no-overlay-zindex",
+ meta: {
+ type: "problem",
+ docs: {
+ description:
+ "Disallow high/arbitrary z-index utilities (z-50+, z-[9999], …) on overlay wrappers and overlay content elements. Overlays must stack via the app layer system (route the portal through a layer container, see components/ui/layer.tsx), not by escalating z-index to escape to the top.",
+ },
+ schema: [
+ {
+ type: "object",
+ properties: {
+ mode: { type: "string", enum: ["wrapper", "overlay-content"] },
+ },
+ additionalProperties: false,
+ },
+ ],
+ messages: {
+ unexpected:
+ "Avoid `{{utility}}` on overlay wrappers/content. Overlays stack via the layer system β€” route the portal into a layer `container` (see components/ui/layer.tsx) instead of escalating z-index. z-index is for ordering content WITHIN a layer only.",
+ },
+ },
+ defaultOptions: [{ mode: "wrapper" }],
+ create(context, [{ mode }]) {
+ function check(node: TSESTree.Node, raw: unknown) {
+ if (typeof raw !== "string") return;
+
+ // In overlay-content mode, only flag z-index that sits on an overlay
+ // *content* JSX element; leave local page-chrome z-index alone.
+ if (mode === "overlay-content") {
+ const elementName = enclosingJsxOpeningElementName(node);
+ if (!elementName || !isOverlayContentElementName(elementName)) return;
+ }
+
+ for (const utility of offendingZIndexUtilities(raw)) {
+ context.report({
+ node,
+ messageId: "unexpected",
+ data: { utility },
+ });
+ break;
+ }
+ }
+ return {
+ Literal(node) {
+ check(node, node.value);
+ },
+ TemplateElement(node) {
+ check(node, node.value.raw);
+ },
+ };
+ },
+});
+
+export default rule;
diff --git a/web/AGENTS.md b/web/AGENTS.md
index cdfec370a6..fea86437ad 100644
--- a/web/AGENTS.md
+++ b/web/AGENTS.md
@@ -119,12 +119,16 @@ changes.
it). **To put something on top of something else, use a layer, not a
z-index.** The app renders inside `#__next`, isolated into one stacking
context (`globals.css`), so its z-indexes can't escape; overlays go in layers
- that sit outside it and always win. Today there's one layer, `tooltip`:
- containers declared in `_document.tsx`, ordered by `LAYER_ORDER` (later = on
- top), no z-index; render via `<Layer name="…">` (`src/components/ui/layer.tsx`).
- Add a layer only when an overlay must escape the app (else use a Radix
- `*.Portal`) by adding a name to `LAYER_ORDER`. z-index stays local to a layer
- or component (1–2 max), never to escape the app.
+ that sit outside it and always win. `LAYER_ORDER` is
+ `["agent", "modal", "popover", "tooltip", "toast"]` β€” containers declared in
+ `_document.tsx`, ordered by that array (later = on top), carrying NO z-index.
+ **THE RULE (see `src/components/ui/layer.tsx` JSDoc β€” source of truth): every
+ overlay portals through a layer container; never let a Radix/Vaul `*.Portal`
+ fall back to `<body>`.** Radix/Vaul primitives route via their `*.Portal`'s
+ `container` (the `ui/*` wrappers do this with `useLayerContainer`); bespoke
+ imperatively-positioned content renders via `<Layer name="…">`. z-index stays
+ local to a layer or component (1–2 max), never to escape the app β€” the
+ `@repo/no-overlay-zindex` lint rule enforces it.
- Public API routes should use
`src/features/public-api/server/withMiddlewares.ts`, define strict request and
response types in `src/features/public-api/types/*`, add server tests, and
diff --git a/web/eslint.config.mjs b/web/eslint.config.mjs
index 7f0c455b53..88be286506 100644
--- a/web/eslint.config.mjs
+++ b/web/eslint.config.mjs
@@ -82,6 +82,46 @@ export default [
},
},
+ // App-wide guard ("overlay-content" mode): a consumer must not re-introduce a
+ // z-index escape on an overlay it imports (e.g. nav-user's old `z-60` on
+ // DropdownMenuContent, or `z-50` on a HoverCardContent). This mode flags a
+ // high z-index ONLY when it sits on an overlay *content* element (a component
+ // whose name ends in `Content`), which always routes through a layer β€” so
+ // plain page chrome (sticky headers, fixed banners/toolbars at `z-50`) inside
+ // the isolated `#__next` stacking context is left alone, no false positives.
+ // Declared BEFORE the wrapper block so the stricter "wrapper" mode is the
+ // final word on the nine `ui/*` primitive files (flat-config last-match wins).
+ {
+ name: "langfuse/web/overlay-content-no-zindex-escape",
+ files: ["src/**/*.{ts,tsx}"],
+ rules: {
+ "@repo/no-overlay-zindex": ["error", { mode: "overlay-content" }],
+ },
+ },
+
+ // Overlay primitive wrappers must stack via the app layer system (route the
+ // portal into a layer container, see components/ui/layer.tsx), never by
+ // escalating z-index to escape to the top. On these wrapper files, ban a
+ // high/arbitrary z-index ANYWHERE (mode "wrapper") β€” every high z-index here
+ // is an escape. z-index stays a local, within-layer tool elsewhere.
+ {
+ name: "langfuse/web/overlays-no-zindex-escape",
+ files: [
+ "src/components/ui/dialog.tsx",
+ "src/components/ui/alert-dialog.tsx",
+ "src/components/ui/sheet.tsx",
+ "src/components/ui/drawer.tsx",
+ "src/components/ui/popover.tsx",
+ "src/components/ui/dropdown-menu.tsx",
+ "src/components/ui/select.tsx",
+ "src/components/ui/hover-card.tsx",
+ "src/components/ui/tooltip.tsx",
+ ],
+ rules: {
+ "@repo/no-overlay-zindex": ["error", { mode: "wrapper" }],
+ },
+ },
+
// Tests legitimately exercise backwards-compatible (deprecated) read paths
// such as getTraceById/getObservationById, so allow them in test code.
{
diff --git a/web/src/components/ActionButton.tsx b/web/src/components/ActionButton.tsx
index d1786335e1..665aed22af 100644
--- a/web/src/components/ActionButton.tsx
+++ b/web/src/components/ActionButton.tsx
@@ -5,8 +5,8 @@ import {
HoverCard,
HoverCardContent,
HoverCardTrigger,
+ HoverCardPortal,
} from "@/src/components/ui/hover-card";
-import { HoverCardPortal } from "@radix-ui/react-hover-card";
import Link from "next/link";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
diff --git a/web/src/components/date-range-dropdowns.tsx b/web/src/components/date-range-dropdowns.tsx
index e126acba98..ad7c9e1692 100644
--- a/web/src/components/date-range-dropdowns.tsx
+++ b/web/src/components/date-range-dropdowns.tsx
@@ -24,8 +24,8 @@ import {
HoverCard,
HoverCardContent,
HoverCardTrigger,
+ HoverCardPortal,
} from "@/src/components/ui/hover-card";
-import { HoverCardPortal } from "@radix-ui/react-hover-card";
type BaseDateRangeDropdownProps<T> = {
selectedOption: T;
diff --git a/web/src/components/design-system/OverlayLayers.stories.tsx b/web/src/components/design-system/OverlayLayers.stories.tsx
new file mode 100644
index 0000000000..2ac4e3f6d4
--- /dev/null
+++ b/web/src/components/design-system/OverlayLayers.stories.tsx
@@ -0,0 +1,167 @@
+import React from "react";
+import preview from "../../../.storybook/preview";
+
+/**
+ * Design-system documentation: how every overlay in the app stacks β€” by
+ * structure (DOM order), not z-index. Rendered as a story (not standalone MDX,
+ * which this Storybook setup doesn't wire a docs renderer for).
+ */
+
+const LAYERS: { name: string; holds: string; why: string }[] = [
+ {
+ name: "agent",
+ holds: "the in-app assistant window",
+ why: "persistent / draggable; floats above the page but BELOW every transient overlay",
+ },
+ {
+ name: "modal",
+ holds: "Dialog, AlertDialog, Sheet (incl. the table peek), Drawer",
+ why: "blocking surfaces, above the page and the assistant",
+ },
+ {
+ name: "popover",
+ holds: "Popover, DropdownMenu, Select, HoverCard",
+ why: "ABOVE modal, so a Select/Popover opened inside a Dialog still renders on top",
+ },
+ {
+ name: "tooltip",
+ holds: "Tooltip + bespoke anchored tooltips",
+ why: "hints stay above their trigger, even inside a modal",
+ },
+ {
+ name: "toast",
+ holds: "Sonner toasts",
+ why: "last, so they always sit above everything β€” by order alone, no z-index",
+ },
+];
+
+const Code = ({ children }: { children: React.ReactNode }) => (
+ <code className="bg-muted rounded px-1 py-0.5 font-mono text-[0.85em]">
+ {children}
+ </code>
+);
+
+const H = ({ children }: { children: React.ReactNode }) => (
+ <h2 className="text-foreground mt-8 mb-2 text-lg font-semibold">
+ {children}
+ </h2>
+);
+
+function OverlayLayersDoc() {
+ return (
+ <div className="text-foreground mx-auto max-w-3xl p-8 text-sm leading-relaxed">
+ <h1 className="text-2xl font-bold">Overlay layers</h1>
+ <p className="text-muted-foreground mt-1">
+ How every overlay in the app stacks β€”{" "}
+ <strong>by structure (DOM order), not by z-index.</strong>
+ </p>
+
+ <H>The problem this solves</H>
+ <p>
+ Overlays β€” dialogs, dropdowns, tooltips, toasts, the in-app assistant β€”
+ each used to portal to <Code>&lt;body&gt;</Code> and compete for
+ &ldquo;who&rsquo;s on top&rdquo; with hand-picked z-index numbers. Those
+ numbers kept escalating β€” <Code>z-50</Code> β†’ <Code>z-51</Code> β†’{" "}
+ <Code>z-60</Code> β†’ <Code>z-[9999]</Code> β€” and whoever picked the
+ bigger one won, until the next overlay reset the race. Real bugs
+ followed: toasts hidden behind the trace peek, the search-bar error
+ tooltip clipped, the nav dropdown colliding with the assistant window.
+ </p>
+
+ <H>The model</H>
+ <p>
+ The whole app renders inside <Code>#__next</Code>, which is its own
+ isolated stacking context (<Code>isolation: isolate</Code>). That caps
+ every z-index used inside the app β€” nothing in-app can paint over an
+ overlay. The overlay layer containers are declared once in{" "}
+ <Code>_document.tsx</Code> as <Code>&lt;body&gt;</Code> siblings{" "}
+ <em>after</em> <Code>#__next</Code>, so they paint on top purely by DOM
+ order (later = on top), and each is itself an isolated stacking context.
+ </p>
+ <p className="mt-2 font-medium">
+ Ordering is the layer&rsquo;s job. Overlays carry no z-index.
+ </p>
+
+ <H>The layers (low β†’ high)</H>
+ <table className="mt-2 w-full border-collapse text-left">
+ <thead>
+ <tr className="border-b">
+ <th className="py-2 pr-4 font-semibold">Layer</th>
+ <th className="py-2 pr-4 font-semibold">Holds</th>
+ <th className="py-2 font-semibold">Why it sits here</th>
+ </tr>
+ </thead>
+ <tbody>
+ {LAYERS.map((l) => (
+ <tr key={l.name} className="border-b align-top">
+ <td className="py-2 pr-4">
+ <Code>{l.name}</Code>
+ </td>
+ <td className="py-2 pr-4">{l.holds}</td>
+ <td className="text-muted-foreground py-2">{l.why}</td>
+ </tr>
+ ))}
+ </tbody>
+ </table>
+ <p className="text-muted-foreground mt-2">
+ <Code>LAYER_ORDER</Code> in <Code>components/ui/layer.tsx</Code> is the
+ source of truth; <Code>_document.tsx</Code> maps it to the containers.
+ </p>
+
+ <H>Pointer events</H>
+ <p>
+ The layer containers are <Code>pointer-events: none</Code>, so the empty
+ space around a non-modal overlay (like the table peek) stays
+ click-through to the app behind it. Each portaled overlay opts itself
+ back in with a single global rule β€”{" "}
+ <Code>
+ [data-overlay-root] &gt; [data-layer] &gt; * &#123; pointer-events:
+ auto &#125;
+ </Code>{" "}
+ β€” so every overlay is interactive by construction, modal or not.
+ </p>
+
+ <H>How to use it</H>
+ <ul className="ml-5 list-disc space-y-1">
+ <li>
+ <strong>Radix / Vaul primitive:</strong> route its{" "}
+ <Code>*.Portal</Code> into a layer with{" "}
+ <Code>useLayerContainer(name)</Code>. The <Code>ui/*</Code> wrappers
+ (Dialog, DropdownMenu, Select, …) already do this, so most code gets
+ it for free.
+ </li>
+ <li>
+ <strong>Bespoke positioned content:</strong> render it through{" "}
+ <Code>&lt;Layer name=&quot;…&quot;&gt;</Code>.
+ </li>
+ <li>
+ <strong>Never</strong> give an overlay a z-index to
+ &ldquo;escape&rdquo;, and <strong>never</strong> let a{" "}
+ <Code>*.Portal</Code> fall back to <Code>&lt;body&gt;</Code>.
+ </li>
+ </ul>
+
+ <H>The guardrail</H>
+ <p>
+ The <Code>@repo/no-overlay-zindex</Code> ESLint rule fails the build if
+ a new overlay reaches for a z-index escape β€” so the category of bug
+ can&rsquo;t return. Legit in-app chrome (sticky page headers, fixed top
+ banners, the bulk-action bar) keeps its z-index: it lives inside{" "}
+ <Code>#__next</Code> and never competes with overlays.
+ </p>
+
+ <p className="text-muted-foreground mt-8 border-t pt-4 text-xs">
+ Part of the design system. Storybook is, step by step, becoming the home
+ for these design-system decisions.
+ </p>
+ </div>
+ );
+}
+
+const meta = preview.meta({
+ title: "Design System/Overlay Layers",
+ component: OverlayLayersDoc,
+ parameters: { layout: "fullscreen" },
+});
+
+export const Overview = meta.story({});
diff --git a/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx b/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx
index 5c2be9adfa..9ee6cc9861 100644
--- a/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx
+++ b/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx
@@ -10,6 +10,7 @@ import { useRouter, type NextRouter } from "next/router";
import { SidebarProvider, SidebarInset } from "@/src/components/ui/sidebar";
import { AppSidebar } from "@/src/components/nav/app-sidebar";
import { Toaster } from "@/src/components/ui/sonner";
+import { Layer } from "@/src/components/ui/layer";
import { TopBannerProvider } from "@/src/features/top-banner";
import { AppContentWithRightDrawer } from "../right-drawer/AppContentWithRightDrawer";
import { ThemeToggle } from "@/src/features/theming/ThemeToggle";
@@ -202,7 +203,14 @@ export function AuthenticatedLayout({
<AppContentWithRightDrawer>
{children}
</AppContentWithRightDrawer>
- <Toaster visibleToasts={1} />
+ {/* Toasts render in the `toast` overlay layer β€” the last layer
+ in LAYER_ORDER β€” so they paint above every overlay (incl. a
+ non-modal peek) by DOM order alone, no z-index. Sonner's
+ Toaster is position:fixed, so nesting it in the fixed
+ full-screen layer container is positionally identical. */}
+ <Layer name="toast">
+ <Toaster visibleToasts={1} />
+ </Layer>
<CommandMenu mainNavigation={navigation.navigation} />
</SidebarInset>
</div>
diff --git a/web/src/components/layouts/doc-popup.tsx b/web/src/components/layouts/doc-popup.tsx
index 0581b0a22d..965241b1c7 100644
--- a/web/src/components/layouts/doc-popup.tsx
+++ b/web/src/components/layouts/doc-popup.tsx
@@ -2,10 +2,10 @@ import {
HoverCard,
HoverCardContent,
HoverCardTrigger,
+ HoverCardPortal,
} from "@/src/components/ui/hover-card";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
import { cn } from "@/src/utils/tailwind";
-import { Portal } from "@radix-ui/react-hover-card";
import { Info } from "lucide-react";
export type DocPopupProps = {
@@ -53,7 +53,7 @@ export default function DocPopup({
<Info className={"h-3 w-3"} />
</div>
</HoverCardTrigger>
- <Portal>
+ <HoverCardPortal>
<HoverCardContent>
<div
className={cn(
@@ -64,7 +64,7 @@ export default function DocPopup({
{description}
</div>
</HoverCardContent>
- </Portal>
+ </HoverCardPortal>
</HoverCard>
);
}
diff --git a/web/src/components/movable-resizable-panel.tsx b/web/src/components/movable-resizable-panel.tsx
index fab8810dba..908fa32373 100644
--- a/web/src/components/movable-resizable-panel.tsx
+++ b/web/src/components/movable-resizable-panel.tsx
@@ -96,7 +96,6 @@ type MovableResizablePanelProps = {
dragHandleSelector: string;
ignoreOutsideInteraction?: boolean;
style?: CSSProperties;
- zIndex?: number;
};
const DEFAULT_BOUNDS_PADDING = 8;
@@ -521,7 +520,6 @@ export const MovableResizablePanel = forwardRef<
handle,
ignoreOutsideInteraction = false,
style,
- zIndex,
},
forwardedRef,
) {
@@ -678,7 +676,6 @@ export const MovableResizablePanel = forwardRef<
top: renderedPanel.position.top,
width: renderedPanel.size.width,
height: renderedPanel.size.height,
- zIndex,
...style,
}}
onPointerDown={handleMovePointerDown}
diff --git a/web/src/components/nav/in-app-ai-agent-button.tsx b/web/src/components/nav/in-app-ai-agent-button.tsx
index b735a5a5d4..dd447c2497 100644
--- a/web/src/components/nav/in-app-ai-agent-button.tsx
+++ b/web/src/components/nav/in-app-ai-agent-button.tsx
@@ -1,5 +1,4 @@
-import { useEffect, useLayoutEffect, useRef, useState } from "react";
-import { createPortal } from "react-dom";
+import { useLayoutEffect, useRef, useState } from "react";
import { BotMessageSquare } from "lucide-react";
import { Button } from "@/src/components/ui/button";
@@ -11,6 +10,7 @@ import {
DialogHeader,
DialogTitle,
} from "@/src/components/ui/dialog";
+import { Layer } from "@/src/components/ui/layer";
import { SidebarMenuButton } from "@/src/components/ui/sidebar";
import { ControlledInAppAgentWindow } from "@/src/ee/features/in-app-agent/components";
import {
@@ -23,8 +23,6 @@ import { AIFeaturesDisabledNotice } from "@/src/features/organizations/component
import { useQueryProjectOrOrganization } from "@/src/features/projects/hooks";
import { useSupportDrawer } from "@/src/features/support-chat/SupportDrawerProvider";
-const IN_APP_AI_AGENT_WINDOW_Z_INDEX = 51;
-
export const InAppAiAgentButton = () => {
const { organization } = useQueryProjectOrOrganization();
const { isAvailable, open, setOpen, isExpanded, setIsExpanded } =
@@ -34,19 +32,12 @@ export const InAppAiAgentButton = () => {
const buttonRef = useRef<HTMLButtonElement>(null);
const panelRef = useRef<HTMLDivElement>(null);
const previousPanelRectRef = useRef<DOMRect | null>(null);
- const [portalContainer, setPortalContainer] = useState<HTMLElement | null>(
- null,
- );
const [enableDialogOpen, setEnableDialogOpen] = useState(false);
const floatingPanelHandle = useInAppAgentWindowShellPanelControl({
anchorRef: buttonRef,
});
- useEffect(() => {
- setPortalContainer(document.body);
- }, []);
-
useLayoutEffect(() => {
const previousRect = previousPanelRectRef.current;
const panel = panelRef.current;
@@ -74,17 +65,12 @@ export const InAppAiAgentButton = () => {
}, [isExpanded]);
useLayoutEffect(() => {
- if (
- !open ||
- !portalContainer ||
- isExpanded ||
- floatingPanelHandle.geometry
- ) {
+ if (!open || isExpanded || floatingPanelHandle.geometry) {
return;
}
floatingPanelHandle.initializeGeometry();
- }, [floatingPanelHandle, isExpanded, open, portalContainer]);
+ }, [floatingPanelHandle, isExpanded, open]);
if (!isAvailable || !hasInAppAgentEntitlement) {
return null;
@@ -115,34 +101,37 @@ export const InAppAiAgentButton = () => {
<BotMessageSquare className="h-4 w-4" />
Assistant
</SidebarMenuButton>
- {open && portalContainer
- ? createPortal(
- <InAppAgentWindowShell
- floatingPanelHandle={floatingPanelHandle}
- isExpanded={isExpanded}
- panelRef={panelRef}
- zIndex={IN_APP_AI_AGENT_WINDOW_Z_INDEX}
- >
- {({ isHeaderDragHandleEnabled }) => (
- <ControlledInAppAgentWindow
- isHeaderDragHandleEnabled={isHeaderDragHandleEnabled}
- zIndex={IN_APP_AI_AGENT_WINDOW_Z_INDEX}
- isExpanded={isExpanded}
- onExpandedChange={(nextIsExpanded) => {
- previousPanelRectRef.current =
- panelRef.current?.getBoundingClientRect() ?? null;
- setIsExpanded(nextIsExpanded);
- }}
- onClose={() => {
- floatingPanelHandle.clearGeometry();
- setOpen(false);
- }}
- />
- )}
- </InAppAgentWindowShell>,
- portalContainer,
- )
- : null}
+ {open ? (
+ // The assistant window lives in the `agent` overlay layer β€” a
+ // <body>-level layer container that floats above page content but below
+ // every transient overlay (dropdowns, dialogs, popovers, tooltips,
+ // toasts) by DOM order alone. No z-index: layer ORDER stacks it (see
+ // components/ui/layer.tsx). This replaces the old body portal + z-51,
+ // which fought the nav-user dropdown's z-60 at <body> level.
+ <Layer name="agent">
+ <InAppAgentWindowShell
+ floatingPanelHandle={floatingPanelHandle}
+ isExpanded={isExpanded}
+ panelRef={panelRef}
+ >
+ {({ isHeaderDragHandleEnabled }) => (
+ <ControlledInAppAgentWindow
+ isHeaderDragHandleEnabled={isHeaderDragHandleEnabled}
+ isExpanded={isExpanded}
+ onExpandedChange={(nextIsExpanded) => {
+ previousPanelRectRef.current =
+ panelRef.current?.getBoundingClientRect() ?? null;
+ setIsExpanded(nextIsExpanded);
+ }}
+ onClose={() => {
+ floatingPanelHandle.clearGeometry();
+ setOpen(false);
+ }}
+ />
+ )}
+ </InAppAgentWindowShell>
+ </Layer>
+ ) : null}
<Dialog open={enableDialogOpen} onOpenChange={setEnableDialogOpen}>
<DialogContent>
<DialogHeader>
diff --git a/web/src/components/nav/nav-user.tsx b/web/src/components/nav/nav-user.tsx
index d732df2917..2d80a23211 100644
--- a/web/src/components/nav/nav-user.tsx
+++ b/web/src/components/nav/nav-user.tsx
@@ -108,8 +108,11 @@ export function NavUser({ user, items }: UserNavigationProps) {
</SidebarMenuButton>
</DropdownMenuTrigger>
<DropdownMenuContent
- // Ensure the zIndex here is higher than that of the in-app agent window (see: web/src/ee/features/in-app-agent/components/InAppAgentWindow.tsx)
- className="z-60 w-(--radix-dropdown-menu-trigger-width) min-w-56 rounded-lg"
+ // No z-index: this dropdown portals into the `popover` overlay
+ // layer, which sits above the `agent` layer (the assistant window)
+ // by layer ORDER β€” so it opens above the window with no magic
+ // number. See components/ui/layer.tsx.
+ className="w-(--radix-dropdown-menu-trigger-width) min-w-56 rounded-lg"
side={isMobile ? "bottom" : "right"}
align="end"
sideOffset={4}
diff --git a/web/src/components/ui/alert-dialog.tsx b/web/src/components/ui/alert-dialog.tsx
index 3a61ee5184..59bc5f5985 100644
--- a/web/src/components/ui/alert-dialog.tsx
+++ b/web/src/components/ui/alert-dialog.tsx
@@ -5,13 +5,22 @@ import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog";
import { cn } from "@/src/utils/tailwind";
import { buttonVariants } from "@/src/components/ui/button";
+import { useLayerContainer } from "@/src/components/ui/layer";
import motionStyles from "./dialog-motion.module.css";
const AlertDialog = AlertDialogPrimitive.Root;
const AlertDialogTrigger = AlertDialogPrimitive.Trigger;
-const AlertDialogPortal = AlertDialogPrimitive.Portal;
+// Route the portal into the `modal` overlay layer (null until mounted β†’
+// falls back to <body>, SSR-parity). Layer order, not z-index, stacks it.
+const AlertDialogPortal = ({
+ ...props
+}: React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Portal>) => {
+ const container = useLayerContainer("modal");
+ return <AlertDialogPrimitive.Portal container={container} {...props} />;
+};
+AlertDialogPortal.displayName = "AlertDialogPortal";
const AlertDialogOverlay = React.forwardRef<
React.ComponentRef<typeof AlertDialogPrimitive.Overlay>,
@@ -20,7 +29,7 @@ const AlertDialogOverlay = React.forwardRef<
<AlertDialogPrimitive.Overlay
className={cn(
motionStyles.overlay,
- "fixed inset-0 z-50 bg-black/50 dark:bg-black/65",
+ "fixed inset-0 bg-black/50 dark:bg-black/65",
className,
)}
{...props}
@@ -39,7 +48,7 @@ const AlertDialogContent = React.forwardRef<
ref={ref}
className={cn(
motionStyles.content,
- "bg-background fixed top-[50%] left-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border p-6 shadow-lg sm:rounded-lg",
+ "bg-background fixed top-[50%] left-[50%] grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border p-6 shadow-lg sm:rounded-lg",
className,
)}
{...props}
diff --git a/web/src/components/ui/dialog.tsx b/web/src/components/ui/dialog.tsx
index 585277b6ee..4fcb9465af 100644
--- a/web/src/components/ui/dialog.tsx
+++ b/web/src/components/ui/dialog.tsx
@@ -6,13 +6,22 @@ import { X } from "lucide-react";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/src/utils/tailwind";
+import { useLayerContainer } from "@/src/components/ui/layer";
import motionStyles from "./dialog-motion.module.css";
const Dialog = DialogPrimitive.Root;
const DialogTrigger = DialogPrimitive.Trigger;
-const DialogPortal = DialogPrimitive.Portal;
+// Route the portal into the `modal` overlay layer (null until mounted β†’
+// falls back to <body>, SSR-parity). Layer order, not z-index, stacks it.
+const DialogPortal = ({
+ ...props
+}: React.ComponentPropsWithoutRef<typeof DialogPrimitive.Portal>) => {
+ const container = useLayerContainer("modal");
+ return <DialogPrimitive.Portal container={container} {...props} />;
+};
+DialogPortal.displayName = "DialogPortal";
const DialogClose = DialogPrimitive.Close;
@@ -34,7 +43,7 @@ const DialogOverlay = React.forwardRef<
ref={ref}
className={cn(
motionStyles.overlay,
- "fixed inset-0 z-50",
+ "fixed inset-0",
dialogOverlayClasses[overlayMode],
className,
)}
@@ -44,7 +53,7 @@ const DialogOverlay = React.forwardRef<
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
const dialogContentVariants = cva(
- "fixed left-[50%] top-[50%] overflow-hidden z-50 flex w-full translate-x-[-50%] translate-y-[-50%] flex-col bg-background shadow-lg sm:rounded-lg",
+ "fixed left-[50%] top-[50%] overflow-hidden flex w-full translate-x-[-50%] translate-y-[-50%] flex-col bg-background shadow-lg sm:rounded-lg",
{
variants: {
size: {
diff --git a/web/src/components/ui/drawer.tsx b/web/src/components/ui/drawer.tsx
index 5414a2a44e..2372226b16 100644
--- a/web/src/components/ui/drawer.tsx
+++ b/web/src/components/ui/drawer.tsx
@@ -4,6 +4,7 @@ import * as React from "react";
import { Drawer as DrawerPrimitive } from "vaul";
import { cn } from "@/src/utils/tailwind";
+import { useLayerContainer } from "@/src/components/ui/layer";
import { useMediaQuery } from "react-responsive";
import { cva } from "class-variance-authority";
@@ -35,7 +36,7 @@ type DrawerContentProps = React.ComponentPropsWithoutRef<
// https://tailwindcss.com/docs/responsive-design
const TAILWIND_MD_MEDIA_QUERY = 768;
-const drawerVariants = cva("fixed z-50 flex flex-col border bg-background", {
+const drawerVariants = cva("fixed flex flex-col border bg-background", {
variants: {
direction: {
bottom: "inset-x-0 bottom-0 rounded-t-lg",
@@ -109,7 +110,15 @@ Drawer.displayName = "Drawer";
const DrawerTrigger = DrawerPrimitive.Trigger;
-const DrawerPortal = DrawerPrimitive.Portal;
+// Route the Vaul portal into the `modal` overlay layer (null until mounted β†’
+// falls back to <body>, SSR-parity). Layer order, not z-index, stacks it.
+const DrawerPortal = ({
+ ...props
+}: React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Portal>) => {
+ const container = useLayerContainer("modal");
+ return <DrawerPrimitive.Portal container={container} {...props} />;
+};
+DrawerPortal.displayName = "DrawerPortal";
const DrawerClose = DrawerPrimitive.Close;
@@ -119,7 +128,7 @@ const DrawerOverlay = React.forwardRef<
>(({ className, ...props }, ref) => (
<DrawerPrimitive.Overlay
ref={ref}
- className={cn("bg-primary/20 fixed inset-0 z-50", className)}
+ className={cn("bg-primary/20 fixed inset-0", className)}
{...props}
/>
));
diff --git a/web/src/components/ui/dropdown-menu.tsx b/web/src/components/ui/dropdown-menu.tsx
index c614568d52..aa0681325b 100644
--- a/web/src/components/ui/dropdown-menu.tsx
+++ b/web/src/components/ui/dropdown-menu.tsx
@@ -5,6 +5,7 @@ import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
import { Check, ChevronRight, Circle, Minus } from "lucide-react";
import { cn } from "@/src/utils/tailwind";
+import { useLayerContainer } from "@/src/components/ui/layer";
const DropdownMenu = DropdownMenuPrimitive.Root;
@@ -12,7 +13,16 @@ const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;
const DropdownMenuGroup = DropdownMenuPrimitive.Group;
-const DropdownMenuPortal = DropdownMenuPrimitive.Portal;
+// Route the portal into the `popover` overlay layer (above `modal`). null
+// until mounted β†’ falls back to <body>, SSR-parity. Layer order, not z-index,
+// stacks it. An explicit `container` prop still overrides the default.
+const DropdownMenuPortal = ({
+ ...props
+}: React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Portal>) => {
+ const container = useLayerContainer("popover");
+ return <DropdownMenuPrimitive.Portal container={container} {...props} />;
+};
+DropdownMenuPortal.displayName = "DropdownMenuPortal";
const DropdownMenuSub = DropdownMenuPrimitive.Sub;
@@ -48,7 +58,7 @@ const DropdownMenuSubContent = React.forwardRef<
<DropdownMenuPrimitive.SubContent
ref={ref}
className={cn(
- "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 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 z-50 min-w-32 overflow-hidden rounded-md border p-1 shadow-lg",
+ "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 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 min-w-32 overflow-hidden rounded-md border p-1 shadow-lg",
className,
)}
{...props}
@@ -60,19 +70,24 @@ DropdownMenuSubContent.displayName =
const DropdownMenuContent = React.forwardRef<
React.ComponentRef<typeof DropdownMenuPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>
->(({ className, sideOffset = 4, ...props }, ref) => (
- <DropdownMenuPrimitive.Portal>
- <DropdownMenuPrimitive.Content
- ref={ref}
- sideOffset={sideOffset}
- className={cn(
- "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 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 z-50 min-w-32 overflow-hidden rounded-md border p-1 shadow-md",
- className,
- )}
- {...props}
- />
- </DropdownMenuPrimitive.Portal>
-));
+>(({ className, sideOffset = 4, ...props }, ref) => {
+ // Route into the `popover` overlay layer (above `modal`). null until mounted
+ // β†’ falls back to <body>, SSR-parity. Layer order, not z-index, stacks it.
+ const container = useLayerContainer("popover");
+ return (
+ <DropdownMenuPrimitive.Portal container={container}>
+ <DropdownMenuPrimitive.Content
+ ref={ref}
+ sideOffset={sideOffset}
+ className={cn(
+ "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 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 min-w-32 overflow-hidden rounded-md border p-1 shadow-md",
+ className,
+ )}
+ {...props}
+ />
+ </DropdownMenuPrimitive.Portal>
+ );
+});
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;
const DropdownMenuItem = React.forwardRef<
diff --git a/web/src/components/ui/hover-card.tsx b/web/src/components/ui/hover-card.tsx
index e635ae5b21..ff133bcb40 100644
--- a/web/src/components/ui/hover-card.tsx
+++ b/web/src/components/ui/hover-card.tsx
@@ -4,28 +4,45 @@ import * as React from "react";
import * as HoverCardPrimitive from "@radix-ui/react-hover-card";
import { cn } from "@/src/utils/tailwind";
+import { useLayerContainer } from "@/src/components/ui/layer";
const HoverCard = HoverCardPrimitive.Root;
const HoverCardTrigger = HoverCardPrimitive.Trigger;
+// Route into the `popover` overlay layer (same as HoverCardContent). null until
+// mounted β†’ falls back to <body>, SSR-parity. Layer order, not z-index, stacks
+// it. An explicit `container` prop still overrides the default.
+const HoverCardPortal = ({
+ ...props
+}: React.ComponentPropsWithoutRef<typeof HoverCardPrimitive.Portal>) => {
+ const container = useLayerContainer("popover");
+ return <HoverCardPrimitive.Portal container={container} {...props} />;
+};
+HoverCardPortal.displayName = "HoverCardPortal";
+
const HoverCardContent = React.forwardRef<
React.ComponentRef<typeof HoverCardPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof HoverCardPrimitive.Content>
->(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
- <HoverCardPrimitive.Portal>
- <HoverCardPrimitive.Content
- ref={ref}
- align={align}
- sideOffset={sideOffset}
- className={cn(
- "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 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 z-9999 w-64 rounded-md border p-3 shadow-md outline-hidden",
- className,
- )}
- {...props}
- />
- </HoverCardPrimitive.Portal>
-));
+>(({ className, align = "center", sideOffset = 4, ...props }, ref) => {
+ // Route into the `popover` overlay layer. null until mounted β†’ falls back to
+ // <body>, SSR-parity. Layer order, not z-index, stacks it.
+ const container = useLayerContainer("popover");
+ return (
+ <HoverCardPrimitive.Portal container={container}>
+ <HoverCardPrimitive.Content
+ ref={ref}
+ align={align}
+ sideOffset={sideOffset}
+ className={cn(
+ "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 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 w-64 rounded-md border p-3 shadow-md outline-hidden",
+ className,
+ )}
+ {...props}
+ />
+ </HoverCardPrimitive.Portal>
+ );
+});
HoverCardContent.displayName = HoverCardPrimitive.Content.displayName;
const HoverCardTitle = React.forwardRef<
@@ -43,4 +60,10 @@ const HoverCardTitle = React.forwardRef<
));
HoverCardTitle.displayName = "HoverCardTitle";
-export { HoverCard, HoverCardTrigger, HoverCardContent, HoverCardTitle };
+export {
+ HoverCard,
+ HoverCardTrigger,
+ HoverCardContent,
+ HoverCardTitle,
+ HoverCardPortal,
+};
diff --git a/web/src/components/ui/layer.tsx b/web/src/components/ui/layer.tsx
index f44c56ceb2..318bbd127d 100644
--- a/web/src/components/ui/layer.tsx
+++ b/web/src/components/ui/layer.tsx
@@ -2,7 +2,7 @@ import * as React from "react";
import { createPortal } from "react-dom";
/**
- * App overlay layers β€” the seed of an app-wide layer system.
+ * App overlay layers β€” the app-wide layer system for ALL overlays.
*
* The whole app renders inside `#__next`, isolated into its own stacking
* context (`isolation: isolate`, in globals.css). That caps every z-index in
@@ -14,21 +14,54 @@ import { createPortal } from "react-dom";
* (later = on top) and each is its own isolated stacking context. z-index stays
* a LOCAL tool for ordering content WITHIN one layer (or within the app), never
* a global escalation. To add a layer, append its name here β€” `_document.tsx`
- * maps this list to the containers β€” and render `<Layer name="…">`.
+ * maps this list to the containers β€” and render `<Layer name="…">` (for bespoke
+ * content) or route a Radix/Vaul portal into it via {@link useLayerContainer}
+ * (for primitives).
*
- * TODO (follow-up): integrate Radix overlays into this system. Today they
- * portal to `<body>` at `z-50` and so sit above these (z-index-less) layers by
- * virtue of that number. The end state is to route them through layers too
- * (e.g. a `popover`/`modal`/`toast` layer above `tooltip`), retiring the last
- * app-wide z-index numbers so ordering everywhere is layer order.
+ * THE RULE (enforce, don't regress): every overlay portals ONLY through a
+ * layer `container`; never re-introduce a high/arbitrary z-index (`z-50`,
+ * `z-[9999]`, …) on an overlay wrapper to "escape" to the top, and never let a
+ * Radix/Vaul `*.Portal` fall back to `<body>`. Ordering is the layer's job. The
+ * `@repo/no-overlay-zindex` lint rule guards the z-index half of this.
+ *
+ * The bands, low β†’ high:
+ * - `agent` β€” the in-app assistant window: a persistent, draggable/resizable
+ * panel that floats above page content but BELOW every transient overlay, so
+ * dropdowns, dialogs, popovers, tooltips and toasts (incl. ones opened from
+ * inside the window itself, e.g. its conversation-history menu) all paint
+ * above it. First (lowest) overlay rung β€” above `#__next`, below the rest.
+ * - `modal` β€” Dialog, AlertDialog, Sheet (incl. the table peek), Drawer.
+ * - `popover` β€” Popover, DropdownMenu, Select, HoverCard. ABOVE `modal` so a
+ * Select/Popover/Dropdown opened *inside* a Dialog renders above it (matches
+ * the old "newest-opened wins" z-50 behaviour; the common in-form case).
+ * - `tooltip` β€” Tooltip and bespoke anchored tooltips (search bar).
+ * - `toast` β€” Sonner toasts. Last, so they always sit above every overlay
+ * (incl. a non-modal peek) by DOM order alone β€” no z-index needed.
*/
-export const LAYER_ORDER = ["tooltip"] as const;
+export const LAYER_ORDER = [
+ "agent",
+ "modal",
+ "popover",
+ "tooltip",
+ "toast",
+] as const;
export type LayerName = (typeof LAYER_ORDER)[number];
-function useLayerContainer(name: LayerName): HTMLElement | null {
- // null on the server and the first client render (SSR parity), then the
- // matching container declared in _document. It is static HTML, so it always
- // exists post-hydration β€” no creation, no ordering, no teardown here.
+/**
+ * The DOM element of the named overlay layer, for handing to a Radix/Vaul
+ * `*.Portal`'s `container` prop so the portal re-parents into that layer
+ * instead of `<body>`. This only moves where the DOM is appended β€” it does NOT
+ * touch a11y: focus trap, Escape, aria wiring and `data-state` animations all
+ * live on the Radix Root/Content, not the portal parent.
+ *
+ * Returns `null` on the server and the first client render (SSR parity), then
+ * the matching container declared in `_document`. When `null`, callers pass it
+ * straight through to the portal's `container`, which falls back to
+ * `document.body` β€” identical to pre-migration behaviour on first paint. The
+ * container is static HTML, so it always exists post-hydration: no creation, no
+ * ordering, no teardown here.
+ */
+export function useLayerContainer(name: LayerName): HTMLElement | null {
const [container, setContainer] = React.useState<HTMLElement | null>(null);
React.useEffect(() => {
setContainer(
@@ -46,8 +79,9 @@ function useLayerContainer(name: LayerName): HTMLElement | null {
* until mounted, so it is SSR-safe. Children position themselves (`fixed` /
* `absolute`) and opt back into pointer events as needed.
*
- * Prefer the Radix primitives' built-in `*.Portal` for Radix overlays; reach
- * for `<Layer>` when portaling bespoke, imperatively-positioned content (e.g. a
+ * Prefer the Radix primitives' built-in `*.Portal` (with
+ * {@link useLayerContainer} for the `container`) for Radix overlays; reach for
+ * `<Layer>` when portaling bespoke, imperatively-positioned content (e.g. a
* contenteditable's anchored tooltip) that isn't a Radix component.
*/
export function Layer({
diff --git a/web/src/components/ui/popover.tsx b/web/src/components/ui/popover.tsx
index 9fed3485ef..2d655d015b 100644
--- a/web/src/components/ui/popover.tsx
+++ b/web/src/components/ui/popover.tsx
@@ -4,6 +4,7 @@ import * as React from "react";
import * as PopoverPrimitive from "@radix-ui/react-popover";
import { cn } from "@/src/utils/tailwind";
+import { useLayerContainer } from "@/src/components/ui/layer";
const Popover = PopoverPrimitive.Root;
@@ -12,20 +13,26 @@ const PopoverTrigger = PopoverPrimitive.Trigger;
const PopoverContent = React.forwardRef<
React.ComponentRef<typeof PopoverPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
->(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
- <PopoverPrimitive.Portal>
- <PopoverPrimitive.Content
- ref={ref}
- align={align}
- sideOffset={sideOffset}
- className={cn(
- "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 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 z-50 max-h-[calc(var(--radix-popover-content-available-height)-1rem)] max-w-[max(var(--radix-popover-trigger-width),fit-content)] min-w-72 overflow-y-auto rounded-md border p-3 shadow-md outline-hidden",
- className,
- )}
- {...props}
- />
- </PopoverPrimitive.Portal>
-));
+>(({ className, align = "center", sideOffset = 4, ...props }, ref) => {
+ // Route into the `popover` overlay layer (above `modal`, so popovers opened
+ // inside a dialog render above it). null until mounted β†’ falls back to
+ // <body>, SSR-parity. Layer order, not z-index, stacks it.
+ const container = useLayerContainer("popover");
+ return (
+ <PopoverPrimitive.Portal container={container}>
+ <PopoverPrimitive.Content
+ ref={ref}
+ align={align}
+ sideOffset={sideOffset}
+ className={cn(
+ "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 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 max-h-[calc(var(--radix-popover-content-available-height)-1rem)] max-w-[max(var(--radix-popover-trigger-width),fit-content)] min-w-72 overflow-y-auto rounded-md border p-3 shadow-md outline-hidden",
+ className,
+ )}
+ {...props}
+ />
+ </PopoverPrimitive.Portal>
+ );
+});
PopoverContent.displayName = PopoverPrimitive.Content.displayName;
const PopoverClose = PopoverPrimitive.Close;
diff --git a/web/src/components/ui/select.tsx b/web/src/components/ui/select.tsx
index 825ad00b53..1f4f653a8d 100644
--- a/web/src/components/ui/select.tsx
+++ b/web/src/components/ui/select.tsx
@@ -5,6 +5,7 @@ import * as SelectPrimitive from "@radix-ui/react-select";
import { Check, ChevronDown, ChevronUp } from "lucide-react";
import { cn } from "@/src/utils/tailwind";
+import { useLayerContainer } from "@/src/components/ui/layer";
const Select = SelectPrimitive.Root;
@@ -74,33 +75,39 @@ SelectScrollDownButton.displayName =
const SelectContent = React.forwardRef<
React.ComponentRef<typeof SelectPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
->(({ className, children, position = "popper", ...props }, ref) => (
- <SelectPrimitive.Portal>
- <SelectPrimitive.Content
- ref={ref}
- className={cn(
- "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 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 relative z-50 max-h-96 min-w-32 overflow-hidden rounded-md border shadow-md",
- position === "popper" &&
- "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
- className,
- )}
- position={position}
- {...props}
- >
- <SelectScrollUpButton />
- <SelectPrimitive.Viewport
+>(({ className, children, position = "popper", ...props }, ref) => {
+ // Route into the `popover` overlay layer (above `modal`, so a Select opened
+ // inside a Dialog renders above it). null until mounted β†’ falls back to
+ // <body>, SSR-parity. Layer order, not z-index, stacks it.
+ const container = useLayerContainer("popover");
+ return (
+ <SelectPrimitive.Portal container={container}>
+ <SelectPrimitive.Content
+ ref={ref}
className={cn(
- "p-1",
+ "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 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 relative max-h-96 min-w-32 overflow-hidden rounded-md border shadow-md",
position === "popper" &&
- "h-(--radix-select-trigger-height) w-full min-w-(--radix-select-trigger-width)",
+ "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
+ className,
)}
+ position={position}
+ {...props}
>
- {children}
- </SelectPrimitive.Viewport>
- <SelectScrollDownButton />
- </SelectPrimitive.Content>
- </SelectPrimitive.Portal>
-));
+ <SelectScrollUpButton />
+ <SelectPrimitive.Viewport
+ className={cn(
+ "p-1",
+ position === "popper" &&
+ "h-(--radix-select-trigger-height) w-full min-w-(--radix-select-trigger-width)",
+ )}
+ >
+ {children}
+ </SelectPrimitive.Viewport>
+ <SelectScrollDownButton />
+ </SelectPrimitive.Content>
+ </SelectPrimitive.Portal>
+ );
+});
SelectContent.displayName = SelectPrimitive.Content.displayName;
const SelectLabel = React.forwardRef<
diff --git a/web/src/components/ui/sheet.tsx b/web/src/components/ui/sheet.tsx
index 1bca52f6fe..1b6a72548f 100644
--- a/web/src/components/ui/sheet.tsx
+++ b/web/src/components/ui/sheet.tsx
@@ -6,6 +6,7 @@ import { cva, type VariantProps } from "class-variance-authority";
import { X } from "lucide-react";
import { cn } from "@/src/utils/tailwind";
+import { useLayerContainer } from "@/src/components/ui/layer";
const Sheet = SheetPrimitive.Root;
@@ -13,7 +14,17 @@ const SheetTrigger = SheetPrimitive.Trigger;
const SheetClose = SheetPrimitive.Close;
-const SheetPortal = SheetPrimitive.Portal;
+// Route the portal into the `modal` overlay layer (null until mounted β†’
+// falls back to <body>, SSR-parity). Layer order, not z-index, stacks it.
+// The non-modal table peek (modal={false}) portals here too; the `toast`
+// layer is ordered after `modal`, so toasts paint above the peek by DOM order.
+const SheetPortal = ({
+ ...props
+}: React.ComponentPropsWithoutRef<typeof SheetPrimitive.Portal>) => {
+ const container = useLayerContainer("modal");
+ return <SheetPrimitive.Portal container={container} {...props} />;
+};
+SheetPortal.displayName = "SheetPortal";
const SheetOverlay = React.forwardRef<
React.ComponentRef<typeof SheetPrimitive.Overlay>,
@@ -21,7 +32,7 @@ const SheetOverlay = React.forwardRef<
>(({ className, ...props }, ref) => (
<SheetPrimitive.Overlay
className={cn(
- "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/80",
+ "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 bg-black/80",
className,
)}
{...props}
@@ -31,7 +42,7 @@ const SheetOverlay = React.forwardRef<
SheetOverlay.displayName = SheetPrimitive.Overlay.displayName;
const sheetVariants = cva(
- "fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-100 data-[state=open]:duration-100",
+ "fixed gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-100 data-[state=open]:duration-100",
{
variants: {
side: {
diff --git a/web/src/components/ui/sidebar.tsx b/web/src/components/ui/sidebar.tsx
index ce57879c84..613028cb96 100644
--- a/web/src/components/ui/sidebar.tsx
+++ b/web/src/components/ui/sidebar.tsx
@@ -18,7 +18,6 @@ import {
TooltipProvider,
TooltipTrigger,
} from "@/src/components/ui/tooltip";
-import { Portal } from "@radix-ui/react-tooltip";
const SIDEBAR_STORAGE_KEY = "sidebar:state";
const SIDEBAR_WIDTH = "11.5rem";
@@ -604,17 +603,18 @@ const SidebarMenuButton = React.forwardRef<
return (
<Tooltip>
<TooltipTrigger asChild>{button}</TooltipTrigger>
- <Portal>
- <TooltipContent
- side="right"
- align="center"
- hidden={state !== "collapsed" || isMobile}
- // relative + isolate create a new stacking context
- // z-9999 ensures this appears above other elements, even across different stacking contexts
- className="relative isolate z-9999 text-sm font-semibold"
- {...tooltip}
- />
- </Portal>
+ {/* No extra Portal, no z-index: TooltipContent already portals into the
+ `tooltip` overlay layer, which paints above the whole app by layer
+ ORDER (see components/ui/layer.tsx). The old outer Portal re-parented
+ to <body> and `relative isolate z-9999` escaped via a magic number β€”
+ both are now obsolete and the `isolate` even risked trapping it. */}
+ <TooltipContent
+ side="right"
+ align="center"
+ hidden={state !== "collapsed" || isMobile}
+ className="text-sm font-semibold"
+ {...tooltip}
+ />
</Tooltip>
);
},
diff --git a/web/src/components/ui/tooltip.tsx b/web/src/components/ui/tooltip.tsx
index a52fa400b1..abe25f3a05 100644
--- a/web/src/components/ui/tooltip.tsx
+++ b/web/src/components/ui/tooltip.tsx
@@ -4,6 +4,7 @@ import * as React from "react";
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
import { cn } from "@/src/utils/tailwind";
+import { useLayerContainer } from "@/src/components/ui/layer";
const TooltipProvider = TooltipPrimitive.Provider;
@@ -14,19 +15,25 @@ const TooltipTrigger = TooltipPrimitive.Trigger;
const TooltipContent = React.forwardRef<
React.ComponentRef<typeof TooltipPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
->(({ className, sideOffset = 4, ...props }, ref) => (
- <TooltipPrimitive.Portal>
- <TooltipPrimitive.Content
- ref={ref}
- sideOffset={sideOffset}
- className={cn(
- "bg-popover text-popover-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 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 z-9999 overflow-hidden rounded-md border px-3 py-1.5 text-sm shadow-md",
- className,
- )}
- {...props}
- />
- </TooltipPrimitive.Portal>
-));
+>(({ className, sideOffset = 4, ...props }, ref) => {
+ // Route into the `tooltip` overlay layer (above `popover`/`modal`, below
+ // `toast`). null until mounted β†’ falls back to <body>, SSR-parity. Layer
+ // order, not z-index, stacks it.
+ const container = useLayerContainer("tooltip");
+ return (
+ <TooltipPrimitive.Portal container={container}>
+ <TooltipPrimitive.Content
+ ref={ref}
+ sideOffset={sideOffset}
+ className={cn(
+ "bg-popover text-popover-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 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 overflow-hidden rounded-md border px-3 py-1.5 text-sm shadow-md",
+ className,
+ )}
+ {...props}
+ />
+ </TooltipPrimitive.Portal>
+ );
+});
TooltipContent.displayName = TooltipPrimitive.Content.displayName;
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
diff --git a/web/src/ee/features/in-app-agent/components/ControlledInAppAgentWindow.tsx b/web/src/ee/features/in-app-agent/components/ControlledInAppAgentWindow.tsx
index 18b80033a7..6b54a2c1c0 100644
--- a/web/src/ee/features/in-app-agent/components/ControlledInAppAgentWindow.tsx
+++ b/web/src/ee/features/in-app-agent/components/ControlledInAppAgentWindow.tsx
@@ -7,7 +7,6 @@ import { getDrawerMessages } from "./utils/utils";
type ControlledInAppAgentWindowBaseProps = {
isHeaderDragHandleEnabled?: boolean;
- zIndex?: number;
isExpanded: boolean;
onExpandedChange: (isExpanded: boolean) => void;
};
@@ -64,7 +63,6 @@ export function ControlledInAppAgentWindow(
messages={drawerMessages}
conversations={conversations}
hasMoreConversations={hasMoreConversations}
- zIndex={props.zIndex}
isLoadingMoreConversations={isLoadingMoreConversations}
selectedConversationId={selectedConversationId}
onLoadMoreConversations={loadMoreConversations}
diff --git a/web/src/ee/features/in-app-agent/components/InAppAgentMessage.tsx b/web/src/ee/features/in-app-agent/components/InAppAgentMessage.tsx
index 9eeeaf0265..6071309b54 100644
--- a/web/src/ee/features/in-app-agent/components/InAppAgentMessage.tsx
+++ b/web/src/ee/features/in-app-agent/components/InAppAgentMessage.tsx
@@ -147,7 +147,6 @@ export type InAppAgentMessageProps = {
content: InAppAgentMessageContent;
isCompact?: boolean;
isFeedbackDisabled?: boolean;
- windowZIndex?: number;
onSubmitFeedback?: (params: {
value: InAppAgentMessageFeedbackValue | null;
comment?: string | null;
@@ -159,7 +158,6 @@ export function InAppAgentMessage({
content,
isCompact = false,
isFeedbackDisabled = false,
- windowZIndex,
onSubmitFeedback,
}: InAppAgentMessageProps) {
if (content.type === "redirectAction") {
@@ -191,7 +189,6 @@ export function InAppAgentMessage({
content={content}
isCompact={isCompact}
isFeedbackDisabled={isFeedbackDisabled}
- windowZIndex={windowZIndex}
onSubmitFeedback={onSubmitFeedback}
/>
);
@@ -249,13 +246,11 @@ function AssistantMessageWithFeedback({
content,
isCompact,
isFeedbackDisabled,
- windowZIndex,
onSubmitFeedback,
}: {
content: Extract<InAppAgentMessageContent, { type: "text" }>;
isCompact: boolean;
isFeedbackDisabled: boolean;
- windowZIndex?: number;
onSubmitFeedback?: (params: {
value: InAppAgentMessageFeedbackValue | null;
comment?: string | null;
@@ -292,16 +287,11 @@ function AssistantMessageWithFeedback({
feedback={content.feedback}
isCompact={isCompact}
isFeedbackDisabled={isFeedbackDisabled}
- windowZIndex={windowZIndex}
onSubmitFeedback={onSubmitFeedback}
/>
) : null}
{hasSources ? (
- <SourcesPopover
- sources={sources}
- isCompact={isCompact}
- windowZIndex={windowZIndex}
- />
+ <SourcesPopover sources={sources} isCompact={isCompact} />
) : null}
</div>
</div>
@@ -314,13 +304,11 @@ function MessageFeedbackControls({
feedback,
isCompact,
isFeedbackDisabled,
- windowZIndex,
onSubmitFeedback,
}: {
feedback?: InAppAgentMessageFeedback;
isCompact: boolean;
isFeedbackDisabled: boolean;
- windowZIndex?: number;
onSubmitFeedback: (params: {
value: InAppAgentMessageFeedbackValue | null;
comment?: string | null;
@@ -448,11 +436,6 @@ function MessageFeedbackControls({
align="start"
side="top"
className="w-72 space-y-1.5 p-2"
- style={
- typeof windowZIndex === "number"
- ? { zIndex: windowZIndex + 1 }
- : undefined
- }
>
<div>
<textarea
@@ -486,11 +469,9 @@ function MessageFeedbackControls({
function SourcesPopover({
sources,
isCompact,
- windowZIndex,
}: {
sources: InAppAgentMessageSource[];
isCompact: boolean;
- windowZIndex?: number;
}) {
return (
<Popover>
@@ -506,16 +487,7 @@ function SourcesPopover({
Sources
</button>
</PopoverTrigger>
- <PopoverContent
- align="start"
- side="top"
- className="w-72 p-1.5"
- style={
- typeof windowZIndex === "number"
- ? { zIndex: windowZIndex + 1 }
- : undefined
- }
- >
+ <PopoverContent align="start" side="top" className="w-72 p-1.5">
<div className="space-y-0.5">
{sources.map((source) => (
<a
diff --git a/web/src/ee/features/in-app-agent/components/InAppAgentWindow.stories.tsx b/web/src/ee/features/in-app-agent/components/InAppAgentWindow.stories.tsx
index ce676026c0..45d60bebbc 100644
--- a/web/src/ee/features/in-app-agent/components/InAppAgentWindow.stories.tsx
+++ b/web/src/ee/features/in-app-agent/components/InAppAgentWindow.stories.tsx
@@ -30,7 +30,6 @@ function InAppAgentWindowStoryShell({
floatingPanelHandle={floatingPanelHandle}
isExpanded={isExpanded}
panelRef={panelRef}
- zIndex={1}
>
{children}
</InAppAgentWindowShell>
diff --git a/web/src/ee/features/in-app-agent/components/InAppAgentWindow.tsx b/web/src/ee/features/in-app-agent/components/InAppAgentWindow.tsx
index cf1f3e3659..f6fc875aa9 100644
--- a/web/src/ee/features/in-app-agent/components/InAppAgentWindow.tsx
+++ b/web/src/ee/features/in-app-agent/components/InAppAgentWindow.tsx
@@ -105,7 +105,6 @@ export type InAppAgentWindowProps = {
comment?: string | null;
}) => Promise<void>;
selectedConversationId: string | undefined;
- zIndex?: number;
} & InAppAgentWindowCloseButtonProps;
export function InAppAgentWindow(props: InAppAgentWindowProps) {
@@ -125,7 +124,6 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {
onSubmit,
onSubmitFeedback,
selectedConversationId,
- zIndex,
} = props;
const viewportRef = useRef<HTMLDivElement>(null);
const isAutoScrollAttachedRef = useRef(true);
@@ -245,9 +243,6 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {
<DropdownMenuContent
align="end"
className="max-h-80 w-64 overflow-y-auto"
- style={
- typeof zIndex === "number" ? { zIndex: zIndex + 1 } : undefined
- }
>
<DropdownMenuLabel>Recent conversations</DropdownMenuLabel>
<DropdownMenuSeparator />
@@ -427,7 +422,6 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {
content={message.content}
isCompact={!isExpanded}
isFeedbackDisabled={isInputDisabled}
- windowZIndex={zIndex}
onSubmitFeedback={
feedbackRunId
? (params) =>
diff --git a/web/src/ee/features/in-app-agent/components/InAppAgentWindowShell.tsx b/web/src/ee/features/in-app-agent/components/InAppAgentWindowShell.tsx
index 796924588d..bc6615e30e 100644
--- a/web/src/ee/features/in-app-agent/components/InAppAgentWindowShell.tsx
+++ b/web/src/ee/features/in-app-agent/components/InAppAgentWindowShell.tsx
@@ -71,7 +71,6 @@ type InAppAgentWindowShellProps = {
floatingPanelHandle: MovableResizablePanelHandle;
isExpanded: boolean;
panelRef: RefObject<HTMLDivElement | null>;
- zIndex: number;
};
export function InAppAgentWindowShell({
@@ -79,19 +78,22 @@ export function InAppAgentWindowShell({
floatingPanelHandle,
isExpanded,
panelRef,
- zIndex,
}: InAppAgentWindowShellProps) {
if (!isExpanded && !floatingPanelHandle.geometry) {
return null;
}
+ // The shell renders inside the `agent` overlay layer (see
+ // components/ui/layer.tsx), whose container is `pointer-events: none` so the
+ // rest of the app stays click-through. The panel is the interactive surface,
+ // so it opts pointer events back in via `pointer-events-auto`. No z-index:
+ // layer ORDER stacks the whole `agent` layer below every transient overlay.
if (isExpanded) {
return (
<div
ref={panelRef}
- className="fixed inset-x-3 top-[calc(var(--banner-offset)+0.75rem)] bottom-3 origin-top-left"
+ className="pointer-events-auto fixed inset-x-3 top-[calc(var(--banner-offset)+0.75rem)] bottom-3 origin-top-left"
data-ignore-outside-interaction
- style={{ zIndex }}
>
<div
data-ignore-outside-interaction
@@ -109,7 +111,7 @@ export function InAppAgentWindowShell({
ignoreOutsideInteraction
ref={panelRef}
handle={floatingPanelHandle}
- zIndex={zIndex}
+ className="pointer-events-auto"
>
<div
data-ignore-outside-interaction
diff --git a/web/src/features/batch-actions/components/RunEvaluationDialog/EvaluatorPromptPreview.tsx b/web/src/features/batch-actions/components/RunEvaluationDialog/EvaluatorPromptPreview.tsx
index ca72ea64d9..357570bf76 100644
--- a/web/src/features/batch-actions/components/RunEvaluationDialog/EvaluatorPromptPreview.tsx
+++ b/web/src/features/batch-actions/components/RunEvaluationDialog/EvaluatorPromptPreview.tsx
@@ -16,7 +16,7 @@ export function EvaluatorPromptPreview(props: EvaluatorPromptPreviewProps) {
<HoverCard openDelay={150} closeDelay={150}>
<HoverCardTrigger asChild>{trigger}</HoverCardTrigger>
<HoverCardContent
- className="z-50 w-[520px] max-w-[85vw]"
+ className="w-[520px] max-w-[85vw]"
align="end"
onWheel={(event) => event.stopPropagation()}
>
diff --git a/web/src/features/rbac/components/MembersTable.tsx b/web/src/features/rbac/components/MembersTable.tsx
index f37d762b7a..158a4048f4 100644
--- a/web/src/features/rbac/components/MembersTable.tsx
+++ b/web/src/features/rbac/components/MembersTable.tsx
@@ -30,8 +30,8 @@ import {
HoverCard,
HoverCardContent,
HoverCardTrigger,
+ HoverCardPortal,
} from "@/src/components/ui/hover-card";
-import { HoverCardPortal } from "@radix-ui/react-hover-card";
import Link from "next/link";
import useColumnOrder from "@/src/features/column-visibility/hooks/useColumnOrder";
import { SettingsTableCard } from "@/src/components/layouts/settings-table-card";
diff --git a/web/src/features/rbac/components/RoleSelectItem.tsx b/web/src/features/rbac/components/RoleSelectItem.tsx
index e5af370568..cd0cd37061 100644
--- a/web/src/features/rbac/components/RoleSelectItem.tsx
+++ b/web/src/features/rbac/components/RoleSelectItem.tsx
@@ -2,10 +2,10 @@ import {
HoverCard,
HoverCardContent,
HoverCardTrigger,
+ HoverCardPortal,
} from "@/src/components/ui/hover-card";
import { SelectItem } from "@/src/components/ui/select";
import { Role } from "@langfuse/shared";
-import { HoverCardPortal } from "@radix-ui/react-hover-card";
import {
organizationRoleAccessRights,
orgNoneRoleComment,
diff --git a/web/src/features/search-bar/README.md b/web/src/features/search-bar/README.md
index ca3e033210..3c2afe692a 100644
--- a/web/src/features/search-bar/README.md
+++ b/web/src/features/search-bar/README.md
@@ -413,17 +413,30 @@ unused planners).
strips redundant parens and would bail on a now-"invalid" paren) and
removes documented top-level grouping β€” needs its own pass.
- **Layer system**: the bar's in-flow overlays use a hardcoded local ladder (X
- z-20 < autocomplete popover z-50, both drop into the table below the bar). The
- **error tooltip is the exception**: when the popover is open it flips ABOVE
- the bar, into the page header's band, where no in-flow z-index can win β€”
- `#page > main` is `overflow:hidden` (clips anything above the bar) and the
- header is inside the app's isolated stacking context. So that one tooltip
- renders through the `"tooltip"` `<Layer>` (`components/ui/layer.tsx`), which
- puts it in a `<body>`-level overlay layer that paints above the whole app by
- DOM order β€” no z-index needed. `<Layer>` is the seed of an app-wide layer
- system (one layer today, ordered by `LAYER_ORDER`). New overlays that must
- escape clipping/stacking should reuse `<Layer>` rather than a one-off portal +
- z-index.
+ z-20 < autocomplete popover z-50, both drop into the table below the bar).
+ These are genuinely local β€” they live inside the app's isolated `#__next`
+ stacking context, can't escape it, and never need to beat a body-level
+ overlay, so their z-index is fine. The **error tooltip is the exception**:
+ when the popover is open it flips ABOVE the bar, into the page header's band,
+ where no in-flow z-index can win β€” `#page > main` is `overflow:hidden` (clips
+ anything above the bar) and the header is inside the isolated stacking
+ context. So that one tooltip renders through the `"tooltip"` `<Layer>`
+ (`components/ui/layer.tsx`), which puts it in a `<body>`-level overlay layer
+ that paints above the whole app by DOM ORDER β€” no z-index needed.
+- **The app-wide layer system** (`components/ui/layer.tsx`): `<Layer>` is now
+ part of the full overlay band, not a one-off seed. `LAYER_ORDER` is
+ `["agent", "modal", "popover", "tooltip", "toast"]` β€” five `<body>`-level
+ layers (declared in `_document.tsx`), each its own isolated stacking context,
+ stacked by DOM ORDER (later = on top), carrying NO z-index of their own. ALL
+ overlays route through it: Radix/Vaul primitives via their `*.Portal`'s
+ `container` (use `useLayerContainer`), and bespoke
+ imperatively-positioned content (like this bar's error tooltip) via `<Layer>`.
+ No overlay carries a magic z-index to "escape to the top" anymore; the
+ `@repo/no-overlay-zindex` lint rule enforces this β€” it bans high z-index on
+ the `ui/*` overlay wrappers, and app-wide on any overlay _content_ element
+ (e.g. a `*Content` you put a stray `z-50` on). When adding a search-bar
+ overlay that must escape clipping/stacking, reach for `<Layer>` (bespoke) or a
+ layer-routed Radix primitive β€” never a one-off portal + z-index.
- Optional: extract `SearchComposer`'s contenteditable selection/`beforeinput`
machinery into a `useContentEditableController` hook to fully separate the
imperative integration from the React component.
diff --git a/web/src/features/widgets/components/WidgetPropertySelectItem.tsx b/web/src/features/widgets/components/WidgetPropertySelectItem.tsx
index 766102315f..c95fcbfe32 100644
--- a/web/src/features/widgets/components/WidgetPropertySelectItem.tsx
+++ b/web/src/features/widgets/components/WidgetPropertySelectItem.tsx
@@ -2,8 +2,8 @@ import {
HoverCard,
HoverCardContent,
HoverCardTrigger,
+ HoverCardPortal,
} from "@/src/components/ui/hover-card";
-import { HoverCardPortal } from "@radix-ui/react-hover-card";
import { SelectItem } from "@/src/components/ui/select";
import * as React from "react";
diff --git a/web/src/styles/globals.css b/web/src/styles/globals.css
index 6392fa64cb..5f2b143354 100644
--- a/web/src/styles/globals.css
+++ b/web/src/styles/globals.css
@@ -410,8 +410,21 @@
/* Overlay layer roots (see _document.tsx + components/ui/layer.tsx). The
stack is click-through; each layer is its own isolated stacking context and
- they order by DOM order (later = on top). Overlay content opts back into
- pointer events on itself. */
+ they order by DOM order (later = on top). The layer containers are
+ `pointer-events: none` so the EMPTY regions around an overlay pass clicks
+ through to the app behind (e.g. the non-modal table peek leaves the rest of
+ the page clickable). Each portaled overlay is appended as a DIRECT CHILD of
+ its layer container (Radix/Vaul `*.Portal` `container`, or `<Layer>`'s
+ `createPortal`), so we opt those overlay roots β€” and thus their subtrees β€”
+ back into pointer events here. This makes interactivity correct-by-
+ construction for EVERY overlay routed through a layer, including non-modal
+ ones (peek, Popover, HoverCard, Tooltip) where Radix does NOT manage
+ pointer-events itself (it only sets `auto` when it disables outside pointer
+ events, i.e. modal Dialog/Sheet/AlertDialog/Drawer and DropdownMenu/Select).
+ Without this, a non-modal overlay inherits the container's `none` and is
+ fully click-through β€” clicks fall to the app underneath. A specific child
+ can still opt back out with its own `pointer-events: none` (e.g. a
+ decorative arrow) β€” that wins by specificity/cascade. */
[data-overlay-root] {
position: fixed;
inset: 0;
@@ -423,6 +436,9 @@
isolation: isolate;
pointer-events: none;
}
+ [data-overlay-root] > [data-layer] > * {
+ pointer-events: auto;
+ }
}
@layer base {