From a1d79195371808ab8e22131546e77bfecd9d20d6 Mon Sep 17 00:00:00 2001 From: megaproxy Date: Thu, 28 May 2026 23:19:25 +0100 Subject: [PATCH] Context bar: defer OSC7 cwd update out of render phase (was dropped) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The OSC 7 handler runs synchronously inside term.write() as PTY data is processed, which can coincide with React's render phase — calling the parent setState there warned 'cannot update while rendering' and the liveCwd update was dropped, so claude panes never registered their cwd and the bar never showed (backend data + match were fine). Defer the onCwd call via queueMicrotask. Plus a TEMP per-pane match-decision log. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/components/XtermPane.tsx | 7 ++++++- src/lib/layout/LeafPane.tsx | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/components/XtermPane.tsx b/src/components/XtermPane.tsx index 3ebb2a9..a2d3e07 100644 --- a/src/components/XtermPane.tsx +++ b/src/components/XtermPane.tsx @@ -224,7 +224,12 @@ export default function XtermPane({ } catch { /* leave raw if it isn't valid percent-encoding */ } - onCwdRef.current?.(path); + // Defer out of term.write()'s synchronous path: OSC handlers run while + // xterm processes PTY data, which can coincide with React's render + // phase — calling the parent's setState directly there triggers a + // "cannot update while rendering" warning and the update gets dropped. + const reported = path; + queueMicrotask(() => onCwdRef.current?.(reported)); } return true; }); diff --git a/src/lib/layout/LeafPane.tsx b/src/lib/layout/LeafPane.tsx index 010ae3e..25be577 100644 --- a/src/lib/layout/LeafPane.tsx +++ b/src/lib/layout/LeafPane.tsx @@ -199,6 +199,21 @@ export default function LeafPane({ leaf }: { leaf: LeafNode }) { }), [], ); + // TEMP diagnostic — logs the per-pane match decision on change. + useEffect(() => { + if (leaf.shellKind !== "wsl") return; + const c = liveCwd ?? leaf.cwd; + const hit = c ? orch.paneContext.get(c) : undefined; + console.log( + "[ctx] MATCH", + leaf.label ?? leaf.distro, + "cwd=", + c, + hit + ? `→ ${hit.contextTokens}tok ${Math.round((Date.now() - hit.lastActiveMs) / 1000)}s ago` + : "→ no match", + ); + }, [liveCwd, leaf.cwd, leaf.shellKind, leaf.label, leaf.distro, orch.paneContext]); // ---- broadcast --------------------------------------------------------- const onTerminalInput = useCallback(