Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(web): ignore unmounted resizable panel group lookups (#17115)

cursor[bot]956d9f9468e5
diff --git a/web/src/components/ui/resizable-panel-imperative.clienttest.ts b/web/src/components/ui/resizable-panel-imperative.clienttest.ts
new file mode 100644
index 0000000000..27fbcbfe84
--- /dev/null
+++ b/web/src/components/ui/resizable-panel-imperative.clienttest.ts
@@ -0,0 +1,91 @@
+import {
+ isUnmountedResizablePanelGroupError,
+ withMountedPanel,
+} from "@/src/components/ui/resizable-panel-imperative";
+import type { PanelImperativeHandle } from "react-resizable-panels";
+
+function panelStub(
+ overrides: Partial<PanelImperativeHandle> = {},
+): PanelImperativeHandle {
+ return {
+ collapse: () => {},
+ expand: () => {},
+ getSize: () => ({ asPercentage: 30, inPixels: 280 }),
+ isCollapsed: () => false,
+ resize: () => {},
+ ...overrides,
+ };
+}
+
+describe("isUnmountedResizablePanelGroupError", () => {
+ it("matches the library's group-lookup throws", () => {
+ expect(
+ isUnmountedResizablePanelGroupError(
+ new Error(
+ "Group resizable-layout-filter-layout-observations-events not found",
+ ),
+ ),
+ ).toBe(true);
+ expect(
+ isUnmountedResizablePanelGroupError(
+ new Error("Could not find data for Group with id _r_tt_"),
+ ),
+ ).toBe(true);
+ expect(
+ isUnmountedResizablePanelGroupError(
+ new Error('Could not find Group with id "resizable-layout-foo"'),
+ ),
+ ).toBe(true);
+ });
+
+ it("does not match unrelated errors", () => {
+ expect(
+ isUnmountedResizablePanelGroupError(
+ new Error(
+ "Group Context not found; did you render a Panel or Separator outside of a Group?",
+ ),
+ ),
+ ).toBe(false);
+ expect(isUnmountedResizablePanelGroupError(new Error("not found"))).toBe(
+ false,
+ );
+ expect(isUnmountedResizablePanelGroupError("Group foo not found")).toBe(
+ false,
+ );
+ });
+});
+
+describe("withMountedPanel", () => {
+ it("returns the fallback when the panel ref is empty", () => {
+ expect(withMountedPanel(null, (panel) => panel.isCollapsed(), true)).toBe(
+ true,
+ );
+ });
+
+ it("returns the callback result when the group is still registered", () => {
+ const panel = panelStub({ isCollapsed: () => true });
+ expect(withMountedPanel(panel, (p) => p.isCollapsed(), false)).toBe(true);
+ });
+
+ it("returns the fallback when the library throws a missing-group error", () => {
+ const panel = panelStub({
+ isCollapsed: () => {
+ throw new Error(
+ "Group resizable-layout-filter-layout-observations-events not found",
+ );
+ },
+ });
+ expect(withMountedPanel(panel, (p) => !p.isCollapsed(), true)).toBe(true);
+ });
+
+ it("rethrows unexpected imperative errors", () => {
+ const panel = panelStub({
+ expand: () => {
+ throw new Error("Panel constraints not found for Panel secondary");
+ },
+ });
+ expect(() => withMountedPanel(panel, (p) => p.expand(), undefined)).toThrow(
+ "Panel constraints not found for Panel secondary",
+ );
+ });
+});
diff --git a/web/src/components/ui/resizable-panel-imperative.ts b/web/src/components/ui/resizable-panel-imperative.ts
new file mode 100644
index 0000000000..907f0d314c
--- /dev/null
+++ b/web/src/components/ui/resizable-panel-imperative.ts
@@ -0,0 +1,36 @@
+import type { PanelImperativeHandle } from "react-resizable-panels";
+
+/**
+ * react-resizable-panels' imperative API looks the group up in a module-level
+ * registry. After the group unmounts — desktop↔mobile swap, navigation, or a
+ * remount that tears the group down — the panel ref still holds the live
+ * methods, and isCollapsed / expand / collapse / resize / getSize throw.
+ */
+export function isUnmountedResizablePanelGroupError(error: unknown): boolean {
+ if (!(error instanceof Error)) return false;
+ // Same "Group … not found" prefix as the registry miss, but this library
+ // message means a Panel rendered outside a Group — still an application bug.
+ if (error.message.startsWith("Group Context not found")) return false;
+ return (
+ /^Group \S+ not found$/.test(error.message) ||
+ /^Could not find (?:data for )?Group with id /.test(error.message)
+ );
+}
+
+/**
+ * Run an imperative panel call, treating a missing group as "the panel is
+ * already gone" rather than an application error.
+ */
+export function withMountedPanel<T>(
+ panel: PanelImperativeHandle | null | undefined,
+ fn: (panel: PanelImperativeHandle) => T,
+ fallback: T,
+): T {
+ if (!panel) return fallback;
+ try {
+ return fn(panel);
+ } catch (error) {
+ if (isUnmountedResizablePanelGroupError(error)) return fallback;
+ throw error;
+ }
+}
diff --git a/web/src/components/ui/resizable-split-layout.tsx b/web/src/components/ui/resizable-split-layout.tsx
index 3dcaf65e00..9fad0b7141 100644
--- a/web/src/components/ui/resizable-split-layout.tsx
+++ b/web/src/components/ui/resizable-split-layout.tsx
@@ -7,6 +7,7 @@ import {
useDefaultLayout,
usePanelRef,
} from "@/src/components/ui/resizable";
+import { withMountedPanel } from "@/src/components/ui/resizable-panel-imperative";
import { cn } from "@/src/utils/tailwind";
interface ResizableSplitLayoutProps {
@@ -97,24 +98,30 @@ export function ResizableSplitLayout({
useLayoutEffect(() => {
if (!keepSecondaryMounted) return;
- const panel = secondaryPanelRef.current;
- if (!panel) return;
-
- if (open) {
- // v4 react-resizable-panel `expand()` depends on internal collapsed bookkeeping.
- // Fallback to default size if the panel remains effectively closed: still
- // collapsed (a no-op expand in rail mode, where the collapsed rail is
- // wider than any fixed percentage threshold) or near-zero width (the
- // "0%"-collapse mode).
- if (panel.isCollapsed()) {
- panel.expand();
- }
- if (panel.isCollapsed() || panel.getSize().asPercentage < 2) {
- panel.resize(`${defaultSecondarySize}%`);
- }
- } else if (!panel.isCollapsed()) {
- panel.collapse();
- }
+ // The panel ref outlives the group's registry entry. After a desktop↔mobile
+ // swap or unmount, isCollapsed / expand / collapse / resize throw
+ // "Group … not found" — treat that as already-unmounted, not an app error.
+ withMountedPanel(
+ secondaryPanelRef.current,
+ (panel) => {
+ if (open) {
+ // v4 react-resizable-panel `expand()` depends on internal collapsed bookkeeping.
+ // Fallback to default size if the panel remains effectively closed: still
+ // collapsed (a no-op expand in rail mode, where the collapsed rail is
+ // wider than any fixed percentage threshold) or near-zero width (the
+ // "0%"-collapse mode).
+ if (panel.isCollapsed()) {
+ panel.expand();
+ }
+ if (panel.isCollapsed() || panel.getSize().asPercentage < 2) {
+ panel.resize(`${defaultSecondarySize}%`);
+ }
+ } else if (!panel.isCollapsed()) {
+ panel.collapse();
+ }
+ },
+ undefined,
+ );
}, [keepSecondaryMounted, open, secondaryPanelRef, defaultSecondarySize]);
// Rail mode: a drag can snap the panel to its collapsed rail (or pull it back
@@ -123,7 +130,7 @@ export function ResizableSplitLayout({
const handleSecondaryResizeCallback = useCallback(() => {
const panel = secondaryPanelRef.current;
if (!panel || !onOpenChange) return;
- const panelOpen = !panel.isCollapsed();
+ const panelOpen = withMountedPanel(panel, (p) => !p.isCollapsed(), open);
if (panelOpen !== open) onOpenChange(panelOpen);
}, [secondaryPanelRef, onOpenChange, open]);
const handleSecondaryResize =