The best way to control Claude Code, Codex and more from any computer or phone
fix(web): keep draft project names readable (#22177)
Yash Singh committed
Oct 20, 2026 at 02:04 UTC
02b899bcde04c19039e4d25eecd947a9bd408553
6 files changed
+224
-189
apps/web/src/components/chat/DraftHeroHeadline.tsx
+20
-19
@@ -41,6 +41,7 @@ import {
41
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
42
import { InlineButton } from "../ui/button";
43
import { DraftProjectName } from "./DraftProjectName";
44
+import { DraftHeroProjectHeading } from "./DraftHeroProjectHeading";
45
import { resolveProjectSettings } from "@t3tools/shared/projectSettings";
46
47
const ADD_PROJECT_VALUE = "add-project";
@@ -254,13 +255,13 @@ export function DraftHeroHeadline({
255
<ComboboxTrigger
256
render={<InlineButton tone="picker" />}
257
data-draft-project-trigger=""
257
- // Leaves room for the trailing "?" so a truncated name keeps it on its line.
258
- className="pointer-events-auto max-w-[calc(100%-1em)] align-baseline"
258
+ className="pointer-events-auto min-w-0 max-w-full align-baseline"
259
/>
260
}
261
>
262
<DraftProjectName
263
value={isScratchDraft ? "No project" : (activeProjectDisplayName ?? "Choose a project")}
264
+ singleLine
265
/>
266
</TooltipTrigger>
267
{activeProjectDisplayName && !isScratchDraft ? (
@@ -308,9 +309,9 @@ export function DraftHeroHeadline({
309
<button
310
type="button"
311
onClick={openAddProject}
311
- className="pointer-events-auto inline cursor-pointer border-muted-foreground/35 border-b border-dotted text-muted-foreground/60 transition-colors hover:border-muted-foreground/60 hover:text-muted-foreground/80 focus-visible:rounded-sm focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
312
+ className="pointer-events-auto inline min-w-0 max-w-full cursor-pointer border-muted-foreground/35 border-b border-dotted text-muted-foreground/60 transition-colors hover:border-muted-foreground/60 hover:text-muted-foreground/80 focus-visible:rounded-sm focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
313
>
313
- {activeProjectTitle ?? "Add a project"}
314
+ <DraftProjectName value={activeProjectTitle ?? "Add a project"} singleLine />
315
</button>
316
);
317
@@ -341,21 +342,21 @@ export function DraftHeroHeadline({
342
343
return (
344
<div className="mx-auto flex w-full max-w-5xl flex-col items-center">
344
- {/* An explicit heading label hides the inline project picker in NVDA browse mode. */}
345
- <h1 className="w-full text-center font-normal text-2xl text-foreground tracking-tight sm:text-3xl">
346
- {isScratchDraft ? (
347
- <>What should we work on?</>
348
- ) : hasResolvedProject ? (
349
- <>
350
- What should we build in <span className="whitespace-nowrap">{projectSelector}?</span>
351
- </>
352
- ) : canChooseProject ? (
353
- <>{projectSelector} to start</>
354
- ) : (
355
- <>Add a project to start</>
356
- )}
357
- </h1>
358
- {}
345
+ {hasResolvedProject && !isScratchDraft ? (
346
+ <DraftHeroProjectHeading projectName={activeProjectDisplayName ?? "Choose a project"}>
347
+ {projectSelector}
348
+ </DraftHeroProjectHeading>
349
+ ) : (
350
+ <h1 className="w-full text-center font-normal text-2xl text-foreground tracking-tight sm:text-3xl">
351
+ {isScratchDraft ? (
352
+ <>What should we work on?</>
353
+ ) : canChooseProject ? (
354
+ <>{projectSelector} to start</>
355
+ ) : (
356
+ <>Add a project to start</>
357
+ )}
358
+ </h1>
359
+ )}
360
{scratchWorkspaceRoot === null ? null : (
361
<p className="mt-2 flex h-6 w-full items-center justify-center text-sm">
362
{isScratchDraft ? projectSelector : orStartWithoutProject}
apps/web/src/components/chat/DraftHeroProjectHeading.tsx
new
+60
@@ -0,0 +1,60 @@
1
+import { useLayoutEffect, useRef, useState, type ReactNode } from "react";
2
+
3
+import { observeResize } from "~/lib/observeResize";
4
+
5
+export function DraftHeroProjectHeading({
6
+ children,
7
+ projectName,
8
+}: {
9
+ children: ReactNode;
10
+ projectName: string;
11
+}) {
12
+ const containerRef = useRef<HTMLDivElement>(null);
13
+ const inlineRef = useRef<HTMLSpanElement>(null);
14
+ const [fitsInline, setFitsInline] = useState(false);
15
+
16
+ useLayoutEffect(() => {
17
+ const container = containerRef.current;
18
+ const inline = inlineRef.current;
19
+ if (!container || !inline) return;
20
+
21
+ // Measure the full inline heading independently of its current layout, so
22
+ // moving the name below it cannot make the fit check oscillate.
23
+ const update = () =>
24
+ setFitsInline(
25
+ inline.getBoundingClientRect().width <= container.getBoundingClientRect().width,
26
+ );
27
+ update();
28
+ return observeResize([container, inline], update);
29
+ }, []);
30
+
31
+ return (
32
+ <div ref={containerRef} className="group/draft-hero relative w-full" data-inline={fitsInline}>
33
+ <span
34
+ aria-hidden="true"
35
+ className="pointer-events-none invisible absolute inset-x-0 top-0 h-0 overflow-hidden"
36
+ >
37
+ <span
38
+ ref={inlineRef}
39
+ className="flex w-max items-baseline gap-2 whitespace-nowrap font-normal text-3xl tracking-tight"
40
+ >
41
+ <span>What should we build in</span>
42
+ <span>
43
+ <span className="font-medium">{projectName}</span>?
44
+ </span>
45
+ </span>
46
+ </span>
47
+ <h1 className="flex w-full flex-col items-center justify-center gap-2 text-center font-normal text-2xl text-foreground tracking-tight sm:text-3xl lg:group-data-[inline=true]/draft-hero:flex-row">
48
+ <span className="max-w-full lg:group-data-[inline=true]/draft-hero:shrink-0">
49
+ What should we build
50
+ <span className="lg:group-data-[inline=true]/draft-hero:hidden">?</span>
51
+ <span className="hidden lg:group-data-[inline=true]/draft-hero:inline"> in</span>
52
+ </span>
53
+ <span className="flex min-w-0 max-w-full items-baseline justify-center text-base tracking-normal lg:group-data-[inline=true]/draft-hero:text-3xl lg:group-data-[inline=true]/draft-hero:tracking-tight">
54
+ <span className="min-w-0">{children}</span>
55
+ <span className="hidden shrink-0 lg:group-data-[inline=true]/draft-hero:inline">?</span>
56
+ </span>
57
+ </h1>
58
+ </div>
59
+ );
60
+}
apps/web/src/components/chat/DraftProjectName.browser.test.tsx
+134
-52
@@ -3,8 +3,10 @@ import "~/index.css";
3
import { act } from "react";
4
import { createRoot, type Root } from "react-dom/client";
5
import { afterEach, beforeEach, expect, it, vi } from "vite-plus/test";
6
+import { page } from "vite-plus/test/browser";
7
8
import { InlineButton } from "../ui/button";
9
+import { DraftHeroProjectHeading } from "./DraftHeroProjectHeading";
10
import { DraftProjectName } from "./DraftProjectName";
11
12
let root: Root;
@@ -14,30 +16,29 @@ beforeEach(() => {
16
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
17
host = document.body.appendChild(document.createElement("div"));
18
host.style.width = "700px";
17
- host.style.zoom = "1.31";
19
+ host.style.maxWidth = "100%";
20
root = createRoot(host);
21
});
22
23
afterEach(async () => {
24
await act(async () => root.unmount());
25
host.remove();
24
- vi.restoreAllMocks();
26
vi.unstubAllGlobals();
27
});
28
28
-async function render(value: string, placement: "headline" | "row") {
29
+async function render(value: string, placement: "headline" | "row" = "headline") {
30
await act(async () => {
31
root.render(
32
placement === "headline" ? (
32
- <h1 className="w-full text-center text-3xl tracking-tight">
33
- What should we build in{" "}
34
- <span className="whitespace-nowrap">
35
- <InlineButton tone="picker" className="max-w-[calc(100%-1em)] align-baseline">
36
- <DraftProjectName value={value} />
37
- </InlineButton>
38
- ?
39
- </span>
40
- </h1>
33
+ <div data-testid="composer" className="relative mt-64 h-32 w-full">
34
+ <div className="absolute inset-x-0 bottom-full pb-4">
35
+ <DraftHeroProjectHeading projectName={value}>
36
+ <InlineButton tone="picker" className="min-w-0 max-w-full align-baseline">
37
+ <DraftProjectName value={value} singleLine />
38
+ </InlineButton>
39
+ </DraftHeroProjectHeading>
40
+ </div>
41
+ </div>
42
) : (
43
<div className="flex w-full items-center gap-2 text-sm font-medium">
44
<span className="size-4 shrink-0" />
@@ -50,54 +51,135 @@ async function render(value: string, placement: "headline" | "row") {
51
});
52
}
53
53
-function label() {
54
- return host.querySelector<HTMLSpanElement>("span[aria-label]")!;
54
+const label = () => host.querySelector<HTMLSpanElement>("span[aria-label]")!;
55
+const title = () => host.querySelector<HTMLSpanElement>("h1 > span")!;
56
+
57
+function expectWithinHost(element: Element) {
58
+ const bounds = element.getBoundingClientRect();
59
+ const hostBounds = host.getBoundingClientRect();
60
+ expect(bounds.left).toBeGreaterThanOrEqual(hostBounds.left);
61
+ expect(bounds.right).toBeLessThanOrEqual(hostBounds.right);
62
+}
63
+
64
+function expectAboveComposer() {
65
+ const heading = host.querySelector("h1")!;
66
+ const composer = host.querySelector('[data-testid="composer"]')!;
67
+ expectWithinHost(heading);
68
+ expectWithinHost(label());
69
+ expect(heading.getBoundingClientRect().bottom).toBeLessThan(composer.getBoundingClientRect().top);
70
}
71
57
-it.each(["headline", "row"] as const)(
58
- "keeps fitting names in the %s even when canvas metrics disagree with layout",
59
- async (placement) => {
60
- host.style.zoom = "1";
61
- const measureText = CanvasRenderingContext2D.prototype.measureText;
62
- vi.spyOn(CanvasRenderingContext2D.prototype, "measureText").mockImplementation(function (
63
- this: CanvasRenderingContext2D,
64
- text,
65
- ) {
66
- const metrics = measureText.call(this, text);
67
- Object.defineProperty(metrics, "width", { value: metrics.width + 8 });
68
- return metrics;
69
- });
70
-
71
- for (const value of ["t3code", "mozart_v2", "No project", "Add project"]) {
72
- await render(value, placement);
72
+it.each([320, 390, 822])(
73
+ "places the full short project name below the title in smaller text at %ipx",
74
+ async (width) => {
75
+ await page.viewport(width, 800);
76
+ host.style.width = `${width - 32}px`;
77
+ for (const value of ["t3code", "obsidian-arr", "No project"]) {
78
+ await render(value);
79
+ expect(title().innerText).toBe("What should we build?");
80
expect(label().textContent).toBe(value);
81
+ expect(label().scrollWidth).toBeLessThanOrEqual(label().clientWidth);
82
+ expect(label().scrollHeight).toBeLessThanOrEqual(label().clientHeight);
83
+ expect(label().getBoundingClientRect().top).toBeGreaterThanOrEqual(
84
+ title().getBoundingClientRect().bottom,
85
+ );
86
+ expect(Number.parseFloat(getComputedStyle(label()).fontSize)).toBeLessThan(
87
+ Number.parseFloat(getComputedStyle(title()).fontSize),
88
+ );
89
+ expectAboveComposer();
90
}
91
},
92
);
93
78
-it.each(["headline", "row"] as const)(
79
- "fits long names in the %s and restores them when the available space grows",
80
- async (placement) => {
81
- const value = "ExampleCompany-CustomerPortal-App";
82
- await render(value, placement);
83
- expect(label().textContent).toBe(value);
94
+it("uses the inline heading only when the viewport and chat lane both have room", async () => {
95
+ await page.viewport(1440, 900);
96
+ await render("obsidian-arr");
97
+ expect(title().innerText).toBe("What should we build in");
98
+ expect(label().getBoundingClientRect().top).toBeLessThan(title().getBoundingClientRect().bottom);
99
+ expectAboveComposer();
100
85
- await act(async () => {
86
- host.style.width = "180px";
87
- await expect.poll(() => label().textContent).toContain("…");
88
- });
89
- const shortened = label().textContent!;
90
- expect(shortened.startsWith("Ex")).toBe(true);
91
- expect(shortened.endsWith("App")).toBe(true);
92
- const text = document.createRange();
93
- text.selectNodeContents(label());
94
- expect(text.getBoundingClientRect().width).toBeLessThanOrEqual(
95
- label().getBoundingClientRect().width,
96
- );
101
+ host.style.width = "350px";
102
+ await expect.poll(() => title().innerText).toBe("What should we build?");
103
+ expect(label().getBoundingClientRect().top).toBeGreaterThanOrEqual(
104
+ title().getBoundingClientRect().bottom,
105
+ );
106
+ expectAboveComposer();
107
+});
108
98
- await act(async () => {
99
- host.style.width = "700px";
100
- await expect.poll(() => label().textContent).toBe(value);
101
- });
109
+it.each([390, 1440])(
110
+ "uses a single smaller row and truncates only its remaining overflow at %ipx",
111
+ async (width) => {
112
+ await page.viewport(width, 900);
113
+ host.style.width = `${Math.min(width - 32, 700)}px`;
114
+ const value = "ExampleCompany-CustomerPortal-Production-".repeat(5);
115
+ await render(value);
116
+ expect(label().textContent).toBe(value);
117
+ expect(label().getAttribute("aria-label")).toBe(value);
118
+ expect(title().innerText).toBe("What should we build?");
119
+ expect(label().getBoundingClientRect().top).toBeGreaterThanOrEqual(
120
+ title().getBoundingClientRect().bottom,
121
+ );
122
+ expect(Number.parseFloat(getComputedStyle(label()).fontSize)).toBeLessThan(
123
+ Number.parseFloat(getComputedStyle(title()).fontSize),
124
+ );
125
+ expect(label().scrollWidth).toBeGreaterThan(label().clientWidth);
126
+ expect(label().clientHeight).toBe(Number.parseFloat(getComputedStyle(label()).lineHeight));
127
+ expect(getComputedStyle(label()).textOverflow).toBe("ellipsis");
128
+ expect(document.documentElement.scrollWidth).toBeLessThanOrEqual(window.innerWidth);
129
+ expectAboveComposer();
130
},
131
);
132
+
133
+it("keeps short picker rows intact and bounds long rows at fractional zoom", async () => {
134
+ await page.viewport(1280, 800);
135
+ host.style.width = "240px";
136
+ host.style.zoom = "1.31";
137
+ for (const value of ["t3code", "obsidian-arr", "Add project", "LongProjectName-".repeat(10)]) {
138
+ await render(value, "row");
139
+ expect(label().textContent).toBe(value);
140
+ expectWithinHost(label());
141
+ expect(label().clientHeight).toBeLessThanOrEqual(
142
+ Number.parseFloat(getComputedStyle(label()).lineHeight) * 2,
143
+ );
144
+ }
145
+});
146
+
147
+it("moves a name below the heading when it stops fitting and returns it inline when space recovers", async () => {
148
+ await page.viewport(1440, 900);
149
+ host.style.width = "900px";
150
+ const value = "CustomerPortal-Production";
151
+ await render(value);
152
+ expect(title().innerText).toBe("What should we build in");
153
+
154
+ await act(async () => {
155
+ host.style.width = "650px";
156
+ await expect.poll(() => title().innerText).toBe("What should we build?");
157
+ });
158
+ expect(label().textContent).toBe(value);
159
+ expect(label().scrollWidth).toBeLessThanOrEqual(label().clientWidth);
160
+ expect(label().scrollHeight).toBeLessThanOrEqual(label().clientHeight);
161
+ expectAboveComposer();
162
+
163
+ await act(async () => {
164
+ host.style.width = "900px";
165
+ await expect.poll(() => title().innerText).toBe("What should we build in");
166
+ });
167
+ expect(label().textContent).toBe(value);
168
+ expectAboveComposer();
169
+});
170
+
171
+it("rechecks inline fit when the selected project changes", async () => {
172
+ await page.viewport(1440, 900);
173
+ await render("ExampleCompany-CustomerPortal-Production-Environment");
174
+ expect(title().innerText).toBe("What should we build?");
175
+
176
+ await render("obsidian-arr");
177
+ await expect.poll(() => title().innerText).toBe("What should we build in");
178
+ expect(label().textContent).toBe("obsidian-arr");
179
+
180
+ await render("ExampleCompany-CustomerPortal-Production-Environment");
181
+ await expect.poll(() => title().innerText).toBe("What should we build?");
182
+ expect(label().scrollWidth).toBeLessThanOrEqual(label().clientWidth);
183
+ expect(label().scrollHeight).toBeLessThanOrEqual(label().clientHeight);
184
+ expectAboveComposer();
185
+});
apps/web/src/components/chat/DraftProjectName.logic.test.ts
deleted
-39
@@ -1,39 +0,0 @@
1
-import { describe, expect, it } from "vite-plus/test";
2
-
3
-import { truncateProjectName } from "./DraftProjectName.logic";
4
-
5
-const measure = (text: string) => Array.from(text).length;
6
-
7
-describe("truncateProjectName", () => {
8
- it("keeps distinguishing suffixes in one string without adding whitespace", () => {
9
- expect(truncateProjectName("ExampleCompany-CustomerPortal-App", 19, measure)).toBe(
10
- "ExampleCo…ortal-App",
11
- );
12
- expect(truncateProjectName("ExampleCompany-CustomerPortal-Env", 19, measure)).toBe(
13
- "ExampleCo…ortal-Env",
14
- );
15
- });
16
-
17
- it("leaves names that fit unchanged", () => {
18
- expect(truncateProjectName("ShortRepo", 9, measure)).toBe("ShortRepo");
19
- });
20
-
21
- it("fits proportional character widths", () => {
22
- const proportional = (text: string) =>
23
- Array.from(text).reduce((width, character) => width + (character === "W" ? 3 : 1), 0);
24
- expect(truncateProjectName("WWWW-project-App", 12, proportional)).toBe("WW…App");
25
- });
26
-
27
- it("keeps combining marks and emoji sequences intact", () => {
28
- const value = "e\u0301👩💻-customer-portal-App";
29
- const result = truncateProjectName(value, 18, measure);
30
- expect(result.startsWith("e\u0301👩💻")).toBe(true);
31
- expect(result.endsWith("App")).toBe(true);
32
- expect(measure(result)).toBeLessThanOrEqual(18);
33
- });
34
-
35
- it("handles space for only the ellipsis or no text", () => {
36
- expect(truncateProjectName("ExampleCompany", 1, measure)).toBe("…");
37
- expect(truncateProjectName("ExampleCompany", 0, measure)).toBe("");
38
- });
39
-});
apps/web/src/components/chat/DraftProjectName.logic.ts
deleted
-27
@@ -1,27 +0,0 @@
1
-const graphemes = new Intl.Segmenter(undefined, { granularity: "grapheme" });
2
-
3
-export function truncateProjectName(
4
- value: string,
5
- availableWidth: number,
6
- measure: (text: string) => number,
7
-): string {
8
- if (measure(value) <= availableWidth) return value;
9
- if (measure("…") > availableWidth) return "";
10
-
11
- const characters = Array.from(graphemes.segment(value), (part) => part.segment);
12
- const candidate = (count: number) => {
13
- const head = characters.slice(0, Math.floor(count / 2)).join("");
14
- const tailCount = Math.ceil(count / 2);
15
- const tail = tailCount > 0 ? characters.slice(-tailCount).join("") : "";
16
- return `${head}…${tail}`;
17
- };
18
-
19
- let low = 0;
20
- let high = characters.length - 1;
21
- while (low < high) {
22
- const count = Math.ceil((low + high) / 2);
23
- if (measure(candidate(count)) <= availableWidth) low = count;
24
- else high = count - 1;
25
- }
26
- return candidate(low);
27
-}
apps/web/src/components/chat/DraftProjectName.tsx
+10
-52
@@ -1,58 +1,16 @@
1
-import { useLayoutEffect, useRef, useState } from "react";
2
-
3
-import { observeResize } from "~/lib/observeResize";
4
-
5
-import { truncateProjectName } from "./DraftProjectName.logic";
6
-
7
-export function DraftProjectName({ value }: { value: string }) {
8
- const containerRef = useRef<HTMLSpanElement>(null);
9
- const measurementRef = useRef<HTMLSpanElement>(null);
10
- const [displayName, setDisplayName] = useState(value);
11
-
12
- useLayoutEffect(() => {
13
- const container = containerRef.current;
14
- const measurement = measurementRef.current;
15
- if (!container || !measurement) return;
16
-
17
- const update = () => {
18
- // Canvas text metrics can differ from layout for the same font, weight, and zoom.
19
- // Measure in the DOM so a name that fits never loses characters to that mismatch.
20
- setDisplayName(
21
- truncateProjectName(value, container.getBoundingClientRect().width, (text) => {
22
- measurement.textContent = text;
23
- return measurement.getBoundingClientRect().width;
24
- }),
25
- );
26
- };
27
- update();
28
- const stopObserving = observeResize(container, update);
29
- document.fonts.addEventListener("loadingdone", update);
30
- return () => {
31
- stopObserving();
32
- document.fonts.removeEventListener("loadingdone", update);
33
- };
34
- }, [value]);
35
-
1
+export function DraftProjectName({
2
+ value,
3
+ singleLine = false,
4
+}: {
5
+ value: string;
6
+ singleLine?: boolean;
7
+}) {
8
return (
9
<span
38
- ref={containerRef}
39
- className="relative inline-grid min-w-0 max-w-full overflow-hidden align-baseline whitespace-nowrap"
10
+ aria-label={value}
11
+ className={`min-w-0 ${singleLine ? "block truncate text-left" : "line-clamp-2 whitespace-normal [overflow-wrap:anywhere]"}`}
12
>
41
- {/* Keep the full name's intrinsic width so fitting the visible text cannot shrink its budget. */}
42
- <span
43
- aria-hidden="true"
44
- className="invisible col-start-1 row-start-1 min-w-0 overflow-hidden select-none"
45
- >
46
- {value}
47
- </span>
48
- <span aria-label={value} className="col-start-1 row-start-1 min-w-0 overflow-hidden">
49
- {displayName}
50
- </span>
51
- <span
52
- ref={measurementRef}
53
- aria-hidden="true"
54
- className="invisible absolute top-0 left-0 w-max select-none"
55
- />
13
+ {value}
14
</span>
15
);
16
}