Skip to content

Commit 955343e

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 3ba883e commit 955343e

9 files changed

Lines changed: 167 additions & 14 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,10 @@ export const make = Effect.gen(function* () {
646646
if (input.type === "gestureScrollEnd") window.webContents.send(TRACKPAD_SCROLL_END_CHANNEL);
647647
});
648648

649-
window.on("page-title-updated", (event) => {
649+
// The renderer titles the window after the open thread; only a blank title
650+
// falls back to the app name.
651+
window.on("page-title-updated", (event, title) => {
652+
if (title.trim() !== "") return;
650653
event.preventDefault();
651654
window.setTitle(environment.displayName);
652655
});
@@ -723,7 +726,6 @@ export const make = Effect.gen(function* () {
723726
}
724727
clearDevelopmentLoadRetry();
725728
developmentLoadRetryIndex = 0;
726-
window.setTitle(environment.displayName);
727729
if (environment.platform === "darwin") syncMacosWindowButtons(window);
728730
});
729731
window.webContents.on(

‎apps/web/index.html‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,12 @@
477477
cursor: pointer;
478478
}
479479
</style>
480-
<title>T3 Code (Beta)</title>
480+
<!-- vite.config.ts stamps the web build's channel into this title. -->
481+
<title>T3 Code</title>
482+
<script>
483+
// Desktop's preload injects branding before page scripts, so the window starts on its channel.
484+
document.title = window.desktopBridge?.getAppBranding?.()?.displayName ?? document.title;
485+
</script>
481486
</head>
482487
<body>
483488
<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.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { afterEach, describe, expect, it, vi } from "vite-plus/test";
22
import {
33
resolveServerBackedAppDisplayName,
44
resolveServerBackedAppStageLabel,
5+
resolveWebAppStageLabel,
6+
resolveWindowTitle,
57
} from "./branding.logic";
68

79
const originalWindow = globalThis.window;
@@ -113,4 +115,52 @@ describe("branding logic", () => {
113115
}),
114116
).toBe("T3 Code (Alpha)");
115117
});
118+
119+
it("labels web builds by hosted channel before dev or production", () => {
120+
expect(resolveWebAppStageLabel({ hostedAppChannel: " Nightly", development: true })).toBe(
121+
"Nightly",
122+
);
123+
expect(resolveWebAppStageLabel({ hostedAppChannel: "latest", development: false })).toBe(
124+
"Latest",
125+
);
126+
expect(resolveWebAppStageLabel({ hostedAppChannel: "preview", development: true })).toBe("Dev");
127+
expect(resolveWebAppStageLabel({ hostedAppChannel: "", development: false })).toBe("Beta");
128+
});
129+
});
130+
131+
describe("resolveWindowTitle", () => {
132+
const appDisplayName = "T3 Code (Nightly)";
133+
134+
it("is the app name without a thread", () => {
135+
expect(
136+
resolveWindowTitle({ appDisplayName, projectTitle: null, threadTitle: null, desktop: true }),
137+
).toBe(appDisplayName);
138+
expect(
139+
resolveWindowTitle({
140+
appDisplayName,
141+
projectTitle: "acme",
142+
threadTitle: " ",
143+
desktop: true,
144+
}),
145+
).toBe(appDisplayName);
146+
});
147+
148+
it("names the project and thread, adding the app name only in browser tabs", () => {
149+
const input = { appDisplayName, projectTitle: "acme-web", threadTitle: "Fix login bug" };
150+
expect(resolveWindowTitle({ ...input, desktop: true })).toBe("acme-web / Fix login bug");
151+
expect(resolveWindowTitle({ ...input, desktop: false })).toBe(
152+
"acme-web / Fix login bug — T3 Code (Nightly)",
153+
);
154+
});
155+
156+
it("drops the separator without a project title", () => {
157+
expect(
158+
resolveWindowTitle({
159+
appDisplayName,
160+
projectTitle: " ",
161+
threadTitle: "Fix login bug",
162+
desktop: true,
163+
}),
164+
).toBe("Fix login bug");
165+
});
116166
});

‎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
@@ -164,6 +164,7 @@ import {
164164
} from "@t3tools/client-runtime/state/runtime";
165165
import { AsyncResult } from "effect/reactivity";
166166
import { isElectron } from "../env";
167+
import { useWindowTitleThread } from "../windowTitleStore";
167168
import { readLocalApi } from "../localApi";
168169
import { useDiffPanelStore } from "../diffPanelStore";
169170
import { useActiveThreadRef } from "../hooks/useActiveThreadRef";
@@ -1772,6 +1773,7 @@ export default function ChatView(props: ChatViewProps) {
17721773
? scopeProjectRef(activeThreadEnvironmentId, activeThreadProjectId)
17731774
: null;
17741775
const activeProject = useProject(activeProjectRef);
1776+
useWindowTitleThread(activeProject?.title ?? null, activeThread?.title ?? null);
17751777
const activeProjectSettings = resolveProjectSettings(
17761778
settings,
17771779
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";
@@ -63,6 +63,7 @@ import {
6363
selectProjectGroupingSettings,
6464
} from "../logicalProject";
6565
import { useUiStateStore } from "../uiStateStore";
66+
import { useWindowTitleStore } from "../windowTitleStore";
6667
import { syncBrowserChromeTheme } from "../hooks/useTheme";
6768
import { configureClientTracing } from "../observability/clientTracing";
6869
import { resolveInitialServerAuthGateState } from "../environments/primary";
@@ -354,11 +355,18 @@ function BrowserChromeThemeSync() {
354355
function DocumentTitleSync() {
355356
const primaryServerVersion =
356357
useAtomValue(primaryServerConfigAtom)?.environment.serverVersion ?? null;
357-
const title = resolveServerBackedAppDisplayName({
358-
baseName: APP_BASE_NAME,
359-
fallbackDisplayName: APP_DISPLAY_NAME,
360-
fallbackStageLabel: APP_STAGE_LABEL,
361-
primaryServerVersion,
358+
const projectTitle = useWindowTitleStore((store) => store.projectTitle);
359+
const threadTitle = useWindowTitleStore((store) => store.threadTitle);
360+
const title = resolveWindowTitle({
361+
appDisplayName: resolveServerBackedAppDisplayName({
362+
baseName: APP_BASE_NAME,
363+
fallbackDisplayName: APP_DISPLAY_NAME,
364+
fallbackStageLabel: APP_STAGE_LABEL,
365+
primaryServerVersion,
366+
}),
367+
projectTitle,
368+
threadTitle,
369+
desktop: isElectron,
362370
});
363371

364372
useEffect(() => {
@@ -405,6 +413,7 @@ function RootRouteErrorView({ error }: ErrorComponentProps) {
405413

406414
return (
407415
<StandalonePage tone="error">
416+
<DocumentTitleSync />
408417
<StandalonePageHeader
409418
eyebrow={APP_DISPLAY_NAME}
410419
title="Something went wrong."

‎apps/web/src/windowTitleStore.ts‎

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

‎apps/web/vite.config.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
import { loadRepoEnv } from "../../scripts/lib/public-config";
1717
import { thirdPartyLicensesPlugin } from "../../scripts/lib/third-party-licenses";
1818
import { tailwindPlugins } from "./vite/tailwind";
19+
import { formatAppDisplayName, resolveWebAppStageLabel } from "./src/branding.logic";
1920

2021
const repoEnv = loadRepoEnv();
2122
Object.assign(process.env, repoEnv);
@@ -125,6 +126,28 @@ function devCompressionPlugin(): Plugin {
125126
};
126127
}
127128

129+
// Stamps index.html's title with the name branding.ts resolves once the app
130+
// loads, so a tab opens on the right channel instead of flashing another's.
131+
// Desktop swaps in its injected branding from an inline script in index.html.
132+
function bootstrapTitlePlugin(): Plugin {
133+
let development = false;
134+
return {
135+
name: "t3code:bootstrap-title",
136+
configResolved(config) {
137+
// The same flag Vite exposes to the app as import.meta.env.DEV.
138+
development = !config.isProduction;
139+
},
140+
transformIndexHtml(html) {
141+
const stageLabel = resolveWebAppStageLabel({
142+
hostedAppChannel: configuredHostedAppChannel,
143+
development,
144+
});
145+
const title = formatAppDisplayName({ baseName: "T3 Code", stageLabel });
146+
return html.replace(/<title>[^<]*<\/title>/, `<title>${title}</title>`);
147+
},
148+
};
149+
}
150+
128151
// Vite rejects requests whose Host header isn't localhost, which blocks sharing
129152
// a dev server over Tailscale/LAN. Tailnet names are safe to allow wholesale:
130153
// the DNS is controlled by tailscale, so they can't be rebound by an attacker.
@@ -138,6 +161,7 @@ export default defineConfig(() => {
138161
return {
139162
assetsInclude: ["**/*.wasm"],
140163
plugins: [
164+
bootstrapTitlePlugin(),
141165
devCompressionPlugin(),
142166
thirdPartyLicensesPlugin({
143167
bundleName: "web",

0 commit comments

Comments
 (0)