Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(open-knowledge): keep docked terminal mounted across mid-session navigation (#2027)

serafin-garcia0ef7a5d964f1
diff --git a/.changeset/terminal-persist-cold-nav.md b/.changeset/terminal-persist-cold-nav.md
new file mode 100644
index 000000000..497c5245d
--- /dev/null
+++ b/.changeset/terminal-persist-cold-nav.md
@@ -0,0 +1,5 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+Fix the docked terminal resetting when you close a file or switch to a not-yet-loaded tab. Navigating to a doc whose provider was still loading transiently rendered a full-screen load skeleton outside the persistent editor column, which unmounted the terminal dock and killed the running shell. The skeleton now renders inside the persistent left column on mid-session navigation, so the terminal PTY and scrollback survive tab closes and switches (the cold-start load path is unchanged).
diff --git a/packages/app/src/components/EditorArea.dom.test.tsx b/packages/app/src/components/EditorArea.dom.test.tsx
index d8365fdde..62a7ef1d7 100644
--- a/packages/app/src/components/EditorArea.dom.test.tsx
+++ b/packages/app/src/components/EditorArea.dom.test.tsx
@@ -57,11 +57,23 @@ const ASSET_DOC_CTX = {
docPanelAgentId: null,
docPanelExpandSignal: 0,
};
+const FOLDER_LIVE_CTX = { ...FOLDER_DOC_CTX, activeProvider: {} as never };
+const DOC_COLD_CTX = {
+ activeDocName: null,
+ activeProvider: null,
+ activeTarget: { kind: 'doc', target: 'some-doc', docName: 'some-doc' },
+ recycleDocument: () => {},
+ docPanelMode: 'timeline',
+ docPanelAgentId: null,
+ docPanelExpandSignal: 0,
+};
let docCtx:
| typeof FOLDER_DOC_CTX
+ | typeof FOLDER_LIVE_CTX
| typeof EMPTY_DOC_CTX
| typeof LARGE_FILE_DOC_CTX
- | typeof ASSET_DOC_CTX = FOLDER_DOC_CTX;
+ | typeof ASSET_DOC_CTX
+ | typeof DOC_COLD_CTX = FOLDER_DOC_CTX;
mock.module('@/editor/DocumentContext', () => ({
useDocumentContext: () => docCtx,
useDocumentTransition: () => ({ openDocumentTransition: null }),
@@ -379,10 +391,10 @@ describe('EditorArea terminal persists across view-kind switches', () => {
});
});
-describe('EditorArea hash-load skeleton renders outside the panel group', () => {
+describe('EditorArea hash-load skeleton renders outside the panel group (cold start)', () => {
beforeEach(() => {
cleanup();
- docCtx = EMPTY_DOC_CTX;
+ docCtx = DOC_COLD_CTX;
});
afterEach(() => {
window.location.hash = '';
@@ -408,3 +420,64 @@ describe('EditorArea hash-load skeleton renders outside the panel group', () =>
expect(screen.queryByTestId('terminal-dock')).toBeNull();
});
});
+
+describe('EditorArea terminal persists across a mid-session cold navigation', () => {
+ beforeEach(() => {
+ cleanup();
+ terminalDockMounts = 0;
+ window.location.hash = '';
+ docCtx = FOLDER_LIVE_CTX;
+ });
+ afterEach(() => {
+ window.location.hash = '';
+ });
+
+ test('keeps the dock mounted when a tab close/switch transiently nulls the provider', () => {
+ const props = {
+ editorMode: 'wysiwyg' as const,
+ onModeChange: () => {},
+ activeTab: 'timeline' as const,
+ onActiveTabChange: () => {},
+ terminalBridge: {} as never,
+ terminalVisible: true,
+ onTerminalVisibleChange: () => {},
+ terminalLaunch: null,
+ };
+ const { rerender } = render(<EditorArea {...props} />);
+ const mountsAfterInitial = terminalDockMounts;
+ expect(mountsAfterInitial).toBeGreaterThan(0);
+ expect(
+ screen.getByTestId('terminal-dock').querySelector('[data-testid="folder-overview"]'),
+ ).not.toBeNull();
+
+ act(() => {
+ docCtx = DOC_COLD_CTX;
+ window.location.hash = '#/some-doc';
+ });
+ rerender(<EditorArea {...props} />);
+
+ const dock = screen.getByTestId('terminal-dock');
+ expect(dock.querySelector('[data-testid="editor-skeleton"]')).not.toBeNull();
+ expect(terminalDockMounts).toBe(mountsAfterInitial);
+ expect(screen.getByTestId('resizable-group')).toBeTruthy();
+ });
+
+ test('web host keeps the bare early-return on mid-session cold nav (no dock to preserve)', () => {
+ const webProps = {
+ editorMode: 'wysiwyg' as const,
+ onModeChange: () => {},
+ activeTab: 'timeline' as const,
+ onActiveTabChange: () => {},
+ };
+ const { rerender } = render(<EditorArea {...webProps} />);
+ act(() => {
+ docCtx = DOC_COLD_CTX;
+ window.location.hash = '#/some-doc';
+ });
+ rerender(<EditorArea {...webProps} />);
+
+ expect(screen.getByTestId('editor-skeleton')).toBeTruthy();
+ expect(screen.queryByTestId('resizable-group')).toBeNull();
+ expect(screen.queryByTestId('terminal-dock')).toBeNull();
+ });
+});
diff --git a/packages/app/src/components/EditorArea.tsx b/packages/app/src/components/EditorArea.tsx
index 18ac48643..a3f917c23 100644
--- a/packages/app/src/components/EditorArea.tsx
+++ b/packages/app/src/components/EditorArea.tsx
@@ -54,6 +54,9 @@ const LazyActivityModeContent = lazy(async () => {
return { default: mod.ActivityModeContent };
});
+const DOC_PANEL_MIN_SIZE = '300px';
+const DOC_PANEL_MAX_SIZE = '600px';
+
interface EditorAreaProps {
editorMode: EditorMode;
onModeChange: (mode: EditorMode) => void;
@@ -127,6 +130,10 @@ function EditorAreaInner({
const isConnected = syncStatus === 'connected' || syncStatus === 'synced';
const lifecycleStatus = useLifecycleStatus(activeDocName);
const isConflict = lifecycleStatus === 'conflict';
+ const [everHadProvider, setEverHadProvider] = useState(false);
+ useEffect(() => {
+ if (activeProvider != null && !everHadProvider) setEverHadProvider(true);
+ }, [activeProvider, everHadProvider]);
const deferredActiveDocName = useDeferredValue(activeDocName);
const isNewDoc = activeTarget?.kind === 'missing';
const showStats = !!activeDocName && activeTarget?.kind !== 'folder';
@@ -360,9 +367,36 @@ function EditorAreaInner({
} else if (!activeProvider || !activeDocName) {
const hashDoc = typeof window !== 'undefined' ? docNameFromHash(window.location.hash) : null;
if (hashDoc !== null) {
- return <EditorSkeleton />;
+ if (terminalBridge != null && everHadProvider) {
+ viewContent = <EditorSkeleton />;
+ rightPanel = (
+ <>
+ <ResizableHandle withHandle disabled />
+ <ResizablePanel
+ id="doc-panel"
+ defaultSize={initialRightCollapsed ? 0 : `${initialDocPanelWidthPx}px`}
+ minSize={DOC_PANEL_MIN_SIZE}
+ maxSize={DOC_PANEL_MAX_SIZE}
+ collapsible
+ collapsedSize={0}
+ inert
+ className="flex flex-col bg-muted/20"
+ >
+ {/* Visual-only filler. `inert` removes this subtree from the a11y
+ tree + focus order, so a live-region role/aria-busy here would
+ be dead ARIA — the skeleton in the left column is the announced
+ loading state. Mirrors the real doc-panel (no ARIA on children
+ under its own `inert`). */}
+ <div className="min-h-0 flex-1" />
+ </ResizablePanel>
+ </>
+ );
+ } else {
+ return <EditorSkeleton />;
+ }
+ } else {
+ viewContent = <EmptyEditorState terminalVisible={terminalVisible} />;
}
- viewContent = <EmptyEditorState terminalVisible={terminalVisible} />;
} else {
const isSourceMode = editorMode === 'source';
const sourceDisabled = !isConnected;
@@ -486,8 +520,8 @@ function EditorAreaInner({
id="doc-panel"
panelRef={panelRef}
defaultSize={initialRightCollapsed ? 0 : `${initialDocPanelWidthPx}px`}
- minSize="300px"
- maxSize="600px"
+ minSize={DOC_PANEL_MIN_SIZE}
+ maxSize={DOC_PANEL_MAX_SIZE}
collapsible
collapsedSize={0}
onResize={(size) => {