LibreChat/client
Danny Avila fd229fe478
👯 fix: Collapse Radix Layer Packages to One Copy (#15742)
* 🧬 fix: Collapse Radix Layer Packages to One Copy

Radix coordinates nested layers and focus scopes through module-level state,
so a dialog and a popover inside it cooperate only while they import the same
copy of `react-dismissable-layer` / `react-focus-scope`. This tree had four
and three of them:

  dialog -> react-dialog/node_modules/…  1.0.2   (exact pin)
  select -> react-select/node_modules/…  1.1.10
  menu   -> react-menu/node_modules/…    1.1.0
  hover  -> hoisted                      1.0.5

Split that way, a popover never learns the dialog disabled body pointer
events and the dialog's focus trap is never paused, so in-dialog selects and
hover cards are inert and keyboard-dead (#15738). The exact `1.0.2` pin on
`react-dialog` and `react-alert-dialog` came from #11023, which downgraded
them from ^1.1.15 to fix modal tooltip and dropdown regressions — the same
split seen from the other side, when the dialog was the new package and
everything else was old.

Unpinning both and refreshing the other Radix packages inside their existing
carets collapses the tree to one copy of each. No `overrides` entry: the
resolution stands on its own, and pinning transitive versions would only hide
the next split. `radixLayers.spec.ts` reads the lockfile and fails if either
package is ever nested again; `dialogPopoverFocus.spec.tsx` asserts the
behaviour that invariant exists for — a portaled option holding focus inside
a dialog, which fails on the old tree and passes on this one.

Verified with a real install in a worktree: one copy of each resolved from
dialog, select and hover-card alike; `packages/client` 46 suites / 476 tests
and `client` 323 suites / 3201 tests green; both workspaces typecheck.

Needs a manual pass over the app's modals before merge — what #11023 was
guarding cannot be proven by jsdom.

* 🍞 fix: Give Escape Back to the Dialog Under a Toast

Radix routes Escape to the highest dismissable layer only, and `Toast.Root`
registers one — mounted after whatever dialog is already open. Splitting
`react-dismissable-layer` into per-package copies hid this: toasts and dialogs
were never in the same stack. Collapsing them to one copy puts a status toast
above every open dialog, and it eats the Escape meant for the dialog beneath.

Measured in the running app (mock e2e, instrumented): the dialog's own
`onEscapeKeyDown` was never called, the layer above it was
`<li class="toast-root" data-radix-collection-item>`, and a SECOND Escape
closed the dialog. That is `agent-skills.spec.ts:709`, which failed
deterministically here across three attempts.

The frontmost open dialog now takes Escape back while a toast is present,
closing through a hidden `Dialog.Close` so controlled and uncontrolled dialogs
behave alike. Scoped tightly: no toast on screen leaves Radix's arbitration
untouched, and only the frontmost dialog acts, so an inner dialog still closes
alone.

The toast is matched whatever its `data-state`. A toast that has begun closing
keeps its layer registered until the exit animation ends, and that is exactly
the case that failed — the first attempt keyed on `[data-state="open"]` and
missed it, which the instrumentation caught (`FB toast= null allLis= 1`).

`agent-skills.spec.ts` now passes locally on the deduped tree: 4 passed.
Regression test verified to fail with the fix reverted.

* 🚪 fix: Close the MCP Menu With the Dialog It Opened

Ariakit takes Escape for a menu only when the event target is the menu, its
trigger, or `body`:

    if (event.key !== "Escape") return;
    if (event.defaultPrevented) return;
    ...
    if (isElement(target) && target.tagName === "BODY") return true;
    if (contains(dialog, target)) return true;
    if (contains(disclosureElement, target)) return true;
    return false;                                  // ariakit dialog.tsx:496-517

While the MCP config dialog holds focus none of those is true, so the Escape
that closes the dialog leaves the menu open behind it — and `disabled={isOpen}`
on the trigger then makes it unclickable. The reader is stranded with a menu
they cannot reach and a button they cannot press; `mcp-oauth-readiness` times
out clicking it, three tests over.

Keyed on the dialog CLOSING, not opening. The first attempt closed the menu as
the dialog opened and broke a fourth test that reads the server rows from the
still-mounted menu underneath (`unmountOnHide` deletes them):
`element(s) not found`. Closing on the way back out leaves that untouched.

Local mock e2e on the deduped tree: `mcp-oauth-readiness` 5 passed (was 2/5),
`agent-skills` + `mcp` 5 passed, `client` 3204 tests green, typecheck clean.

* 🛡️ fix: Keep the Escape Fallback Inside Its Lane

Codex found three, all real.

**P1 — the fallback overruled the guards it should obey.** Any Escape while a
toast was up clicked the dialog's close button, including when a select inside
the dialog owned that Escape (WCAG 2.1.1) or when another layer had already
answered it. A reader closing a listbox would have lost the whole dialog and
anything unsaved in it. It now bails on `event.defaultPrevented` and on the
same popup conditions the Radix-provided handler honours — extracted into one
`escapeBelongsToPopup` helper both call, so they cannot drift apart.

**P2 — the frontmost check read inline z-index only.** `ImagePreview` is a raw
`DialogPrimitive.Content` carrying `z-[250]` as a CLASS, so it scored zero and
the My Files dialog underneath was mistaken for the frontmost — Escape in the
preview would have closed it too. Ranking now reads the resolved
`getComputedStyle().zIndex`.

**P2 — the published contract did not carry the singleton.** `@librechat/client`
still admitted `react-toast@1.1.5` and `react-popover@1.0.7`, which depend on
the older dismissable-layer/focus-scope line, so a consumer could reassemble
the very split this PR removes. Radix minimums raised to the versions the
lockfile resolves; the tree still holds exactly one copy of each.

Three regression tests, each verified to fail against the pre-fix component.
`packages/client` 484 tests, `client` 3204 tests, both typecheck clean, local
mock e2e `agent-skills` + `mcp-oauth-readiness` 9 passed.

* 🎚️ fix: Let the Consumer and the Alert Dialog Have Their Say

Two more from codex, both real.

The fallback never ran the dialog's own `onEscapeKeyDown`. Radix calls that
only for the highest layer, which the toast is — so a dialog whose consumer
cancels Escape (`event.preventDefault()`) closed anyway, taking whatever was
in it. The fallback now invokes the supplied handler and honours the
cancellation, exactly as the Radix path does.

The frontmost ranking looked only for `role="dialog"`. `OGDialogContent` is
also used as an alert dialog — the shared-link delete confirmation
(`SharedLinkButton.tsx:426`) — so its content was never found, `frontmost`
stayed null, and the fallback declined to act: that confirmation still needed
two Escapes. Alert dialogs are ranked too.

Two more regression tests, both verified to fail against the previous version.
`packages/client` 486 tests, `client` 3204 tests, typecheck and static checks
clean.
2026-09-08 16:00:27 -04:00
..
public 🍋 feat: Add AMD Lemonade Provider Recognition and Branding (#15664) 2026-09-06 20:46:08 +02:00
src 👯 fix: Collapse Radix Layer Packages to One Copy (#15742) 2026-09-08 16:00:27 -04:00
sw 🛟 fix: Auto-Recover from Stale Service Worker Assets After Deploys (#13686) 2026-06-11 11:57:06 -04:00
test 🎨 feat: Theme-Adaptive SVG Support for Custom MCP and Group Icons (#13817) 2026-09-04 10:49:43 -04:00
babel.config.cjs
check_updates.sh
index.html 🔭 feat: Tag Browser Diagnostics With Client Build IDs (#15656) 2026-09-06 12:47:34 -04:00
jest.config.cjs ✨ feat: add morphing state icons across the client (#14697) 2026-09-04 03:27:14 +02:00
jest.resolver.cjs ⬆️ chore: Migrate off deprecated @ariakit/react-core to @ariakit/react-components (#13940) 2026-06-24 23:13:57 -04:00
nginx.conf 🐳 feat: Bundle Admin Panel in Docker Compose Stacks (#13876) 2026-06-22 16:59:08 -04:00
package.json 👯 fix: Collapse Radix Layer Packages to One Copy (#15742) 2026-09-08 16:00:27 -04:00
postcss.config.cjs
tailwind.config.cjs ✨ feat: Context Gauge Hover Reveal and Breakdown Motion Polish (#15038) 2026-08-21 11:34:36 -04:00
tsconfig.json 👷 ci: Type-check the Client Workspace (#13560) 2026-06-06 18:40:31 -04:00
vite.config.ts 🖼️ fix: Precache PWA Icons and Let Them Refresh (#15654) 2026-09-06 11:32:09 -04:00