From 35772c21f974f253e3d553cb2229c70fa884e4c2 Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 22 Sep 2026 02:45:43 -0700 Subject: [PATCH 1/3] Fix repository-aware diff viewer titles --- webviews/src/App.tsx | 40 +++++++++++++++++++++++++++++++++++++- webviews/test/app.test.tsx | 36 +++++++++++++++++++++++++++++++--- 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/webviews/src/App.tsx b/webviews/src/App.tsx index d72c3ef4a240..1baf8e2fb5f6 100644 --- a/webviews/src/App.tsx +++ b/webviews/src/App.tsx @@ -315,6 +315,34 @@ export function App({ config, initialStatus }: ConfigProps) { const highlighterOptions = workerHighlighterOptions(state.options, appearance, state.languages); const payloadRepoRoot = typeof payload.repoRoot === "string" && payload.repoRoot !== "" ? payload.repoRoot : null; const commentRepoRoot = diffSourceRepoRoot(resolvedSessionSource ?? activeSessionSource) ?? payloadRepoRoot; + useEffect(() => { + const configuredTitle = + typeof payload.title === "string" ? payload.title.trim() : ""; + if (configuredTitle === "") { + return; + } + + const activeSource = resolvedSessionSource ?? activeSessionSource; + if (activeSource?.kind === "patch") { + document.title = configuredTitle; + return; + } + + const repoRoot = diffSourceRepoRoot(activeSource) ?? payloadRepoRoot; + const repoOption = Array.isArray(payload.repoOptions) + ? payload.repoOptions.find((option) => option?.value === repoRoot) + : undefined; + const repoLabel = + typeof repoOption?.label === "string" ? repoOption.label.trim() : ""; + document.title = + repoLabel === "" ? configuredTitle : `${configuredTitle} — ${repoLabel}`; + }, [ + activeSessionSource, + payload.repoOptions, + payload.title, + payloadRepoRoot, + resolvedSessionSource, + ]); const bridgeAvailable = diffCommentsBridgeAvailable() && commentRepoRoot != null; const commentLabels = resolveCommentLabels(payload); const comments = useDiffComments({ @@ -970,6 +998,7 @@ function SourceControls({ onSelectSessionSource={(source) => onSelectSessionSource( repoSelectionWithActiveSource(source, activeSessionSource), )} + selectedOptionTitle selectedValue={diffSourceRepoRoot(activeSessionSource)} /> ) : null} @@ -1133,6 +1162,7 @@ function NavigationSelect({ onNavigate, onSelectSessionSource, options, + selectedOptionTitle = false, selectedValue, }: { ariaLabel: string; @@ -1141,6 +1171,7 @@ function NavigationSelect({ onNavigate: (url: string) => void; onSelectSessionSource?: (source: DiffSource) => void; options: any[] | undefined; + selectedOptionTitle?: boolean; selectedValue?: string | null; }) { if (!Array.isArray(options) || options.length < 2) { @@ -1149,12 +1180,19 @@ function NavigationSelect({ const selected = options.find((option) => option.value === selectedValue) ?? options.find((option) => option.selected) ?? options.find((option) => !option.disabled); + const selectedTitle = selectedOptionTitle + ? ( + typeof selected?.message === "string" && selected.message.trim() !== "" + ? selected.message + : String(selected?.value ?? fallbackValue || ariaLabel) + ) + : ariaLabel; return (