Skip to content

Commit 9e53d18

Browse files
chasemakesclaude
andcommitted
fix(clients): show the right app name and thread context
The window title flashed "T3 Code (Alpha)" on every channel before the real name landed, and never said what you were working on, so window switchers, browser tabs, and time trackers only ever saw the app name. index.html now ships a neutral title. A Vite plugin stamps the web build's channel into it from the same stage-label logic branding.ts uses, and desktop swaps in its preload-injected branding before first paint. ChatView publishes the open project and thread to a small store that DocumentTitleSync renders: `project / thread` on desktop, with ` — <app name>` added in browser tabs, and the app name with no thread open. The desktop window now keeps the renderer's title instead of resetting it to the app name, falling back only for blank titles. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 03d1a90 commit 9e53d18

9 files changed

Lines changed: 124 additions & 15 deletions

File tree

‎apps/desktop/src/window/DesktopWindow.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,10 @@ export const make = Effect.gen(function* () {
660660
runFork(zoomWindow(window, direction));
661661
});
662662

663-
window.on("page-title-updated", (event) => {
663+
// The renderer titles the window after the open thread; only a blank title
664+
// falls back to the app name.
665+
window.on("page-title-updated", (event, title) => {
666+
if (title.trim() !== "") return;
664667
event.preventDefault();
665668
window.setTitle(environment.displayName);
666669
});
@@ -737,7 +740,6 @@ export const make = Effect.gen(function* () {
737740
}
738741
clearDevelopmentLoadRetry();
739742
developmentLoadRetryIndex = 0;
740-
window.setTitle(environment.displayName);
741743
if (environment.platform === "darwin") syncMacosWindowButtons(window);
742744
});
743745
window.webContents.on(

‎apps/web/index.html‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,12 @@
463463
cursor: pointer;
464464
}
465465
</style>
466-
<title>T3 Code (Beta)</title>
466+
<!-- vite.config.ts stamps the web build's channel into this title. -->
467+
<title>T3 Code</title>
468+
<script>
469+
// Desktop's preload injects branding before page scripts, so the window starts on its channel.
470+
document.title = window.desktopBridge?.getAppBranding?.()?.displayName ?? document.title;
471+
</script>
467472
</head>
468473
<body>
469474
<div id="root">

‎apps/web/src/branding.logic.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ export function formatAppDisplayName(input: {
1111
return `${input.baseName} (${input.stageLabel})`;
1212
}
1313

14+
export function resolveHostedAppChannelLabel(channel: string | null | undefined): string | null {
15+
const normalized = channel?.trim().toLowerCase();
16+
return normalized === "nightly" ? "Nightly" : normalized === "latest" ? "Latest" : null;
17+
}
18+
19+
/** Stage label of a web build. vite.config.ts stamps it into index.html's title too. */
20+
export function resolveWebAppStageLabel(input: {
21+
readonly hostedAppChannel: string | null | undefined;
22+
readonly development: boolean;
23+
}): string {
24+
return (
25+
resolveHostedAppChannelLabel(input.hostedAppChannel) ?? (input.development ? "Dev" : "Beta")
26+
);
27+
}
28+
1429
export function resolveServerBackedAppStageLabel(input: {
1530
readonly primaryServerVersion: string | null | undefined;
1631
readonly fallbackStageLabel: string;
@@ -36,3 +51,23 @@ export function resolveServerBackedAppDisplayName(input: {
3651
? input.fallbackDisplayName
3752
: formatAppDisplayName({ baseName: input.baseName, stageLabel });
3853
}
54+
55+
/**
56+
* Names the open thread: `project / thread` on desktop, where the OS already
57+
* shows the app, with the app name appended in browser tabs.
58+
*/
59+
export function resolveWindowTitle(input: {
60+
readonly appDisplayName: string;
61+
readonly projectTitle: string | null;
62+
readonly threadTitle: string | null;
63+
readonly desktop: boolean;
64+
}): string {
65+
const threadTitle = input.threadTitle?.trim() ?? "";
66+
if (threadTitle === "") {
67+
return input.appDisplayName;
68+
}
69+
70+
const projectTitle = input.projectTitle?.trim() ?? "";
71+
const context = projectTitle === "" ? threadTitle : `${projectTitle} / ${threadTitle}`;
72+
return input.desktop ? context : `${context} - ${input.appDisplayName}`;
73+
}

‎apps/web/src/branding.ts‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import type { DesktopAppBranding } from "@t3tools/contracts";
2-
import { formatAppDisplayName } from "./branding.logic";
2+
import {
3+
formatAppDisplayName,
4+
resolveHostedAppChannelLabel,
5+
resolveWebAppStageLabel,
6+
} from "./branding.logic";
37

48
function readInjectedDesktopAppBranding(): DesktopAppBranding | null {
59
if (typeof window === "undefined") {
@@ -14,13 +18,14 @@ const hostedAppChannel = import.meta.env.VITE_HOSTED_APP_CHANNEL?.trim().toLower
1418

1519
export const HOSTED_APP_CHANNEL =
1620
hostedAppChannel === "latest" || hostedAppChannel === "nightly" ? hostedAppChannel : null;
17-
export const HOSTED_APP_CHANNEL_LABEL =
18-
HOSTED_APP_CHANNEL === "nightly" ? "Nightly" : HOSTED_APP_CHANNEL === "latest" ? "Latest" : null;
21+
export const HOSTED_APP_CHANNEL_LABEL = resolveHostedAppChannelLabel(HOSTED_APP_CHANNEL);
1922
export const APP_BASE_NAME = injectedDesktopAppBranding?.baseName ?? "T3 Code";
2023
export const APP_STAGE_LABEL =
2124
injectedDesktopAppBranding?.stageLabel ??
22-
HOSTED_APP_CHANNEL_LABEL ??
23-
(import.meta.env.DEV ? "Dev" : "Beta");
25+
resolveWebAppStageLabel({
26+
hostedAppChannel: HOSTED_APP_CHANNEL,
27+
development: import.meta.env.DEV,
28+
});
2429
export const APP_DISPLAY_NAME =
2530
injectedDesktopAppBranding?.displayName ??
2631
formatAppDisplayName({ baseName: APP_BASE_NAME, stageLabel: APP_STAGE_LABEL });

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ import {
119119
} from "@t3tools/client-runtime/state/runtime";
120120
import { AsyncResult } from "effect/reactivity";
121121
import { isElectron } from "../env";
122+
import { useWindowTitleThread } from "../windowTitleStore";
122123
import { useDiffPanelStore } from "../diffPanelStore";
123124
import { useActiveThreadRef } from "../hooks/useActiveThreadRef";
124125
import { composerRequiresModifier } from "../composer-logic";
@@ -1048,6 +1049,7 @@ export default function ChatView(props: ChatViewProps) {
10481049
? scopeProjectRef(activeThreadEnvironmentId, activeThreadProjectId)
10491050
: null;
10501051
const activeProject = useProject(activeProjectRef);
1052+
useWindowTitleThread(activeProject?.title ?? null, activeThread?.title ?? null);
10511053
const activeProjectSettings = resolveProjectSettings(
10521054
settings,
10531055
activeProject?.id ?? null,

‎apps/web/src/routes/__root.tsx‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { Check, Copy } from "lucide";
1515
import { useEffect, useEffectEvent, useRef, useState } from "react";
1616

1717
import { APP_BASE_NAME, APP_DISPLAY_NAME, APP_STAGE_LABEL, APP_VERSION } from "../branding";
18-
import { resolveServerBackedAppDisplayName } from "../branding.logic";
18+
import { resolveServerBackedAppDisplayName, resolveWindowTitle } from "../branding.logic";
1919
import { AppSidebarLayout } from "../components/AppSidebarLayout";
2020
import { CommandPalette } from "../components/CommandPalette";
2121
import { CustomSnoozeDialogHost } from "../components/CustomSnoozeDialog";
@@ -65,6 +65,7 @@ import {
6565
selectProjectGroupingSettings,
6666
} from "../logicalProject";
6767
import { useUiStateStore } from "../uiStateStore";
68+
import { useWindowTitleStore } from "../windowTitleStore";
6869
import { syncBrowserChromeTheme } from "../hooks/useTheme";
6970
import { configureClientTracing } from "../observability/clientTracing";
7071
import { resolveInitialServerAuthGateState } from "../environments/primary";
@@ -373,11 +374,18 @@ function BrowserChromeThemeSync() {
373374
function DocumentTitleSync() {
374375
const primaryServerVersion =
375376
useAtomValue(primaryServerConfigAtom)?.environment.serverVersion ?? null;
376-
const title = resolveServerBackedAppDisplayName({
377-
baseName: APP_BASE_NAME,
378-
fallbackDisplayName: APP_DISPLAY_NAME,
379-
fallbackStageLabel: APP_STAGE_LABEL,
380-
primaryServerVersion,
377+
const projectTitle = useWindowTitleStore((store) => store.projectTitle);
378+
const threadTitle = useWindowTitleStore((store) => store.threadTitle);
379+
const title = resolveWindowTitle({
380+
appDisplayName: resolveServerBackedAppDisplayName({
381+
baseName: APP_BASE_NAME,
382+
fallbackDisplayName: APP_DISPLAY_NAME,
383+
fallbackStageLabel: APP_STAGE_LABEL,
384+
primaryServerVersion,
385+
}),
386+
projectTitle,
387+
threadTitle,
388+
desktop: isElectron,
381389
});
382390

383391
useEffect(() => {
@@ -424,6 +432,7 @@ function RootRouteErrorView({ error }: ErrorComponentProps) {
424432

425433
return (
426434
<StandalonePage tone="error">
435+
<DocumentTitleSync />
427436
<StandalonePageHeader
428437
eyebrow={APP_DISPLAY_NAME}
429438
title="Something went wrong."

‎apps/web/src/windowTitleStore.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { use, useEffect } from "react";
2+
import { create } from "zustand";
3+
4+
import { BackgroundThreadContext } from "./components/chat/backgroundThread";
5+
6+
interface WindowTitleContext {
7+
readonly projectTitle: string | null;
8+
readonly threadTitle: string | null;
9+
}
10+
11+
/** The open thread's context, which the root layout's DocumentTitleSync renders. */
12+
export const useWindowTitleStore = create<WindowTitleContext>()(() => ({
13+
projectTitle: null,
14+
threadTitle: null,
15+
}));
16+
17+
/** Puts a thread in the window title while the calling view is mounted in front. */
18+
export function useWindowTitleThread(projectTitle: string | null, threadTitle: string | null) {
19+
// A thread kept behind Settings or Usage leaves the title to them.
20+
const background = use(BackgroundThreadContext);
21+
useEffect(() => {
22+
if (background) return;
23+
useWindowTitleStore.setState({ projectTitle, threadTitle });
24+
return () => useWindowTitleStore.setState({ projectTitle: null, threadTitle: null });
25+
}, [background, projectTitle, threadTitle]);
26+
}

‎apps/web/vite.config.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { loadRepoEnv } from "../../scripts/lib/public-config";
1919
import { thirdPartyLicensesPlugin } from "../../scripts/lib/third-party-licenses";
2020
import { tailwindPlugins } from "./vite/tailwind";
2121
import { warmBundledDevPlugin } from "./vite/warmBundledDev";
22+
import { formatAppDisplayName, resolveWebAppStageLabel } from "./src/branding.logic";
2223

2324
const repoEnv = loadRepoEnv();
2425
Object.assign(process.env, repoEnv);
@@ -169,6 +170,28 @@ function devCompressionPlugin(): Plugin {
169170
};
170171
}
171172

173+
// Stamps index.html's title with the name branding.ts resolves once the app
174+
// loads, so a tab opens on the right channel instead of flashing another's.
175+
// Desktop swaps in its injected branding from an inline script in index.html.
176+
function bootstrapTitlePlugin(): Plugin {
177+
let development = false;
178+
return {
179+
name: "t3code:bootstrap-title",
180+
configResolved(config) {
181+
// The same flag Vite exposes to the app as import.meta.env.DEV.
182+
development = !config.isProduction;
183+
},
184+
transformIndexHtml(html) {
185+
const stageLabel = resolveWebAppStageLabel({
186+
hostedAppChannel: configuredHostedAppChannel,
187+
development,
188+
});
189+
const title = formatAppDisplayName({ baseName: "T3 Code", stageLabel });
190+
return html.replace(/<title>[^<]*<\/title>/, `<title>${title}</title>`);
191+
},
192+
};
193+
}
194+
172195
// Allow Tailnet hosts for sharing; Tailscale-controlled DNS prevents attacker rebinding.
173196
const configuredAllowedHosts = (process.env.T3CODE_DEV_ALLOWED_HOSTS ?? "")
174197
.split(",")
@@ -189,6 +212,7 @@ export default defineConfig(() => {
189212
},
190213
assetsInclude: ["**/*.wasm"],
191214
plugins: [
215+
bootstrapTitlePlugin(),
192216
devCompressionPlugin(),
193217
builtDev
194218
? undefined

‎scripts/effect-budget.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,5 +429,6 @@
429429
"apps/web/src/state/olderSettledShelf.ts": 2,
430430
"apps/web/src/state/pullRequests.ts": 2,
431431
"apps/web/src/state/queries.ts": 2,
432-
"apps/web/src/state/threads.ts": 1
432+
"apps/web/src/state/threads.ts": 1,
433+
"apps/web/src/windowTitleStore.ts": 1
433434
}

0 commit comments

Comments
 (0)