Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(ok): hide phantom rail columns from flex flow (PRD-8047) (#3646)

Abrahamaecafdd8ab8b
diff --git a/.changeset/prd-8047-agents-panel-phantom-gap.md b/.changeset/prd-8047-agents-panel-phantom-gap.md
new file mode 100644
index 000000000..bd7456cea
--- /dev/null
+++ b/.changeset/prd-8047-agents-panel-phantom-gap.md
@@ -0,0 +1,5 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+The right-side rail no longer paints an empty phantom column between the editor and the agents chat panel. Both the terminal-right column and the agents column are permanent members of the resizable group (a workaround for a react-resizable-panels layout-cache bug), so a proportional-layout tick could hand a hidden column non-zero `flexGrow` in the paint window between its `defaultSize={0}` and the next `reclaimHiddenRailColumn` clamp — visible as a large empty gap that made the chat panel look like it had drifted off to the side. Two changes close it. The hidden panel now sets `maxSize="0px"` alongside its `defaultSize={0}` — RRP's own layout validator applies `Math.min(maxSize, size)` last (after the collapsible halfway snap), so the outer `data-panel` flex item is hard-clamped to zero share every redistribution pass and never wins the transient share the reclaim microtask was chasing. The preceding drag handle gets `display: none` so its 1px separator bar and tab-stop drop out of the flow while hidden. The panel stays registered with the group (its width state stays coherent for the next toggle-visible) and re-inflates from persisted width when it comes back.
diff --git a/packages/app/src/components/EditorArea.tsx b/packages/app/src/components/EditorArea.tsx
index 07db5cc41..1ee9c2e3a 100644
--- a/packages/app/src/components/EditorArea.tsx
+++ b/packages/app/src/components/EditorArea.tsx
@@ -1944,6 +1944,7 @@ function EditorAreaInner({
<ResizableHandle
withHandle={terminalColumnPresent}
className={terminalColumnPresent ? undefined : 'pointer-events-none'}
+ style={terminalColumnPresent ? undefined : { display: 'none' }}
onPointerDown={(event) => {
trackHandleDrag(
event.pointerId,
@@ -1966,6 +1967,14 @@ function EditorAreaInner({
panelRef={terminalColumnPanelRef}
defaultSize={terminalColumnPresent ? `${terminalDefaultWidthPx}px` : 0}
minSize={`${RIGHT_TERMINAL_PANEL_MIN_WIDTH_PX}px`}
+ // Clamp the outer flex item to zero while hidden. RRP's own layout
+ // validator applies `Math.min(maxSize, size)` last (after the collapsible
+ // halfway snap), so a `maxSize` of `0` hard-clamps every redistribution
+ // pass to zero even while `minSize` stays at its normal value — RRP
+ // never assigns nonzero flex share to a hidden column. `style` cannot do
+ // this: `Panel` spreads it onto the inner content div, not the outer
+ // `data-panel` flex item that carries the group-computed `flexGrow`.
+ maxSize={terminalColumnPresent ? undefined : '0px'}
collapsible
collapsedSize={0}
onResize={(size) => {
@@ -1995,6 +2004,7 @@ function EditorAreaInner({
<ResizableHandle
withHandle={agentsColumnPresent}
className={agentsColumnPresent ? undefined : 'pointer-events-none'}
+ style={agentsColumnPresent ? undefined : { display: 'none' }}
onPointerDown={(event) => {
trackHandleDrag(
event.pointerId,
@@ -2017,11 +2027,15 @@ function EditorAreaInner({
panelRef={agentsColumnPanelRef}
defaultSize={agentsColumnPresent ? `${initialAgentsWidthPx}px` : 0}
minSize={`${MIN_AGENTS_PANEL_WIDTH}px`}
- // The panel can be dragged wide — up to 95% of the group — leaving the
- // editor a 5% sliver (its panel `minSize` while this column is mounted).
- // Pair the two: this max plus the editor's min must sum to 100% or the
- // drag can't reach it. Mirrors the bottom dock's 95%/5% split.
- maxSize="95%"
+ // While present the panel can be dragged wide — up to 95% of the group —
+ // leaving the editor a 5% sliver (its panel `minSize` while this column
+ // is mounted). Pair the two: this max plus the editor's min must sum to
+ // 100% or the drag can't reach it. Mirrors the bottom dock's 95%/5% split.
+ // While hidden the same knob doubles as the flex-flow clamp: RRP applies
+ // `Math.min(maxSize, size)` last in its layout validator, so `0px` hard-
+ // clamps the outer flex item to zero share every redistribution pass —
+ // the paint window `reclaimHiddenRailColumn` alone couldn't close.
+ maxSize={agentsColumnPresent ? '95%' : '0px'}
// Collapsible so a drag past half the min width snaps the column shut —
// the pointerup handler above turns that into a real hide.
collapsible
diff --git a/packages/app/src/components/rail-hidden-column-clamps-to-zero.dom.test.tsx b/packages/app/src/components/rail-hidden-column-clamps-to-zero.dom.test.tsx
new file mode 100644
index 000000000..1cc980d99
--- /dev/null
+++ b/packages/app/src/components/rail-hidden-column-clamps-to-zero.dom.test.tsx
@@ -0,0 +1,213 @@
+import { act, cleanup, render } from '@testing-library/react';
+import { Group, Panel, Separator, useGroupRef } from 'react-resizable-panels';
+import { afterEach, describe, expect, test } from 'vitest';
+
+// Regression guard for the phantom-column paint: the terminal-right
+// and agents rail columns are permanent members of the resizable group (the
+// mount/unmount layout-cache bug we work around elsewhere), and while hidden
+// they must not be able to hold a non-zero flex share for even one
+// redistribute-then-reclaim frame. RRP's own `validatePanelSize` applies
+// `Math.min(maxSize, size)` LAST (after the collapsible halfway snap), so a
+// `maxSize` of `0px` hard-clamps every layout pass to zero even though
+// `minSize` still declares the natural width for when the column comes back.
+//
+// The counter-test below documents the shape that DOES NOT hold the flex
+// share to zero — a hidden panel carrying `style={{ display: 'none' }}` alone.
+// RRP's `Panel` spreads `style` onto its inner content div; the outer
+// `data-panel` flex item that carries the group-computed `flexGrow` keeps
+// `display: flex` hardcoded and accepts whatever share `setLayout` assigns.
+// If a future refactor drops `maxSize` and leans on `style` again, the first
+// test flips green→red and the counter-test flips red→green in one commit.
+
+function withOffsetWidth(px: number, fn: () => Promise<void>) {
+ const proto = window.HTMLElement.prototype;
+ const original = Object.getOwnPropertyDescriptor(proto, 'offsetWidth');
+ Object.defineProperty(proto, 'offsetWidth', { configurable: true, get: () => px });
+ const restore = () => {
+ if (original) Object.defineProperty(proto, 'offsetWidth', original);
+ else Reflect.deleteProperty(proto, 'offsetWidth');
+ };
+ return fn().finally(restore);
+}
+
+let capturedGroupRef: ReturnType<typeof useGroupRef> | null = null;
+
+afterEach(() => {
+ cleanup();
+ capturedGroupRef = null;
+});
+
+function ClampedRailGroup() {
+ const groupRef = useGroupRef();
+ capturedGroupRef = groupRef;
+ return (
+ <Group orientation="horizontal" groupRef={groupRef} style={{ width: 1200 }}>
+ <Panel id="editor" minSize="10%">
+ editor
+ </Panel>
+ <Separator />
+ <Panel
+ id="hidden-rail"
+ defaultSize={0}
+ minSize="320px"
+ maxSize="0px"
+ collapsible
+ collapsedSize={0}
+ >
+ hidden
+ </Panel>
+ </Group>
+ );
+}
+
+function PresenceToggleRailGroup({ present }: { present: boolean }) {
+ const groupRef = useGroupRef();
+ capturedGroupRef = groupRef;
+ return (
+ <Group orientation="horizontal" groupRef={groupRef} style={{ width: 1200 }}>
+ <Panel id="editor" minSize="10%">
+ editor
+ </Panel>
+ <Separator />
+ <Panel
+ id="toggle-rail"
+ defaultSize={present ? '400px' : 0}
+ minSize="320px"
+ maxSize={present ? undefined : '0px'}
+ collapsible
+ collapsedSize={0}
+ >
+ toggleable
+ </Panel>
+ </Group>
+ );
+}
+
+function StyleHiddenRailGroup() {
+ const groupRef = useGroupRef();
+ capturedGroupRef = groupRef;
+ return (
+ <Group orientation="horizontal" groupRef={groupRef} style={{ width: 1200 }}>
+ <Panel id="editor" minSize="10%">
+ editor
+ </Panel>
+ <Separator />
+ <Panel
+ id="hidden-rail"
+ defaultSize={0}
+ minSize="320px"
+ collapsible
+ collapsedSize={0}
+ style={{ display: 'none' }}
+ >
+ hidden
+ </Panel>
+ </Group>
+ );
+}
+
+describe('hidden rail column cannot hold non-zero flex share', () => {
+ test('maxSize="0px" hard-clamps a hidden column to zero share after setLayout', async () => {
+ await withOffsetWidth(1200, async () => {
+ await act(async () => {
+ render(<ClampedRailGroup />);
+ });
+ const group = capturedGroupRef?.current;
+ if (!group) throw new Error('group imperative handle was not attached');
+
+ // Baseline: at mount the hidden panel already sits at 0.
+ const initial = group.getLayout();
+ expect(initial['hidden-rail']).toBeCloseTo(0, 1);
+ expect(initial.editor).toBeCloseTo(100, 1);
+
+ // Try to hand the hidden column a real share the way a proportional
+ // redistribute would — the frame the original bug painted in.
+ await act(async () => {
+ group.setLayout({ editor: 73, 'hidden-rail': 27 });
+ });
+
+ const recovered = group.getLayout();
+
+ // If `maxSize` did not clamp, `hidden-rail` would come back as 27
+ // (or as `minSize`-clamped 320px≈26.67%) and paint an empty gap.
+ expect(recovered['hidden-rail']).toBeCloseTo(0, 1);
+ expect(recovered.editor).toBeCloseTo(100, 1);
+
+ // And the outer `[data-panel]` flex item — the one that actually holds
+ // `flexGrow` — reflects the clamp. This is the DOM axis the panel-half
+ // of a `style={{display:'none'}}` fix cannot influence, since Panel
+ // spreads `style` onto its inner content div.
+ const hiddenPanel = document.querySelector<HTMLElement>('[data-panel][id="hidden-rail"]');
+ if (!hiddenPanel) throw new Error('hidden panel outer div was not rendered');
+ const flexGrow = hiddenPanel.style.flexGrow;
+ // RRP writes `flexGrow` as a string on the outer div's inline style.
+ // An empty string means the panel is not being expanded at all — which
+ // is what we want. Any positive number means the phantom can paint.
+ expect(flexGrow === '' || Number(flexGrow) === 0).toBe(true);
+ });
+ });
+
+ test('present arm: lifting maxSize lets the same panel accept a non-zero share', async () => {
+ // The visible-arm counterpart. Without this an accidental inversion of
+ // the conditional (`maxSize` returning `'0px'` even while present) would
+ // still keep both other tests green — the hidden-clamp test would pass
+ // by construction and the counter-test below is on a separate config.
+ // Here the same panel starts hidden (clamped) and transitions to present
+ // (unclamped) between renders; the assertion is that once `maxSize` is
+ // lifted the panel actually accepts the share `setLayout` assigns.
+ await withOffsetWidth(1200, async () => {
+ const { rerender } = await (async () => {
+ let handle: ReturnType<typeof render> | undefined;
+ await act(async () => {
+ handle = render(<PresenceToggleRailGroup present={false} />);
+ });
+ if (!handle) throw new Error('render did not complete');
+ return handle;
+ })();
+
+ const group = capturedGroupRef?.current;
+ if (!group) throw new Error('group imperative handle was not attached');
+
+ // Baseline while hidden — maxSize="0px" clamps regardless of layout ask.
+ await act(async () => {
+ group.setLayout({ editor: 73, 'toggle-rail': 27 });
+ });
+ expect(group.getLayout()['toggle-rail']).toBeCloseTo(0, 1);
+
+ // Flip present=true — maxSize lifts to undefined. The same panel that
+ // was pinned at 0 must now accept a real share.
+ await act(async () => {
+ rerender(<PresenceToggleRailGroup present />);
+ });
+ await act(async () => {
+ group.setLayout({ editor: 60, 'toggle-rail': 40 });
+ });
+
+ const recovered = group.getLayout();
+ expect(recovered['toggle-rail']).toBeGreaterThan(10);
+ expect(recovered.editor + recovered['toggle-rail']).toBeCloseTo(100, 1);
+ });
+ });
+
+ test('style={{ display: "none" }} alone does NOT clamp a hidden column to zero share', async () => {
+ // Counter-test — documents the mechanism the earlier attempt missed. If
+ // this ever starts passing, RRP began spreading `style` onto the outer
+ // `data-panel` div and the `maxSize` clamp above is no longer the only
+ // path — but until then, `style` alone cannot carry this fix.
+ await withOffsetWidth(1200, async () => {
+ await act(async () => {
+ render(<StyleHiddenRailGroup />);
+ });
+ const group = capturedGroupRef?.current;
+ if (!group) throw new Error('group imperative handle was not attached');
+
+ await act(async () => {
+ group.setLayout({ editor: 73, 'hidden-rail': 27 });
+ });
+
+ const recovered = group.getLayout();
+ // The hidden column keeps a real share — this is the phantom-paint window.
+ expect(recovered['hidden-rail']).toBeGreaterThan(0);
+ });
+ });
+});