The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 18:30 UTC
fix(web): branch labels keep the space before a middle-truncated name (#23627)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Artem Gurianov committed
Nov 13, 2026 at 02:49 UTC
c6995622d5a03db27058ede399dc79acb21409c1
2 files changed
+41
-3
apps/web/src/components/ui/middle-truncate.browser.test.tsx
+25
@@ -23,4 +23,29 @@ describe("MiddleTruncate", () => {
23
expect(label()).not.toHaveAttribute("data-overflow");
24
expect(label()).toHaveStyle({ clipPath: "none" });
25
});
26
+
27
+ it.each([
28
+ ["Fix the sidebar", 7],
29
+ ["report\u2003\u2003draft.txt", 9],
30
+ ])("renders %j split as wide as whole", async (value, tail) => {
31
+ await using screen = await render(
32
+ <div>
33
+ <MiddleTruncate value={value} tail={tail} data-testid="split" />
34
+ <span data-testid="whole" className="whitespace-nowrap">
35
+ {value}
36
+ </span>
37
+ </div>,
38
+ );
39
+ const width = (id: string) => screen.getByTestId(id).element().getBoundingClientRect().width;
40
+
41
+ expect(width("split")).toBeCloseTo(width("whole"), 0);
42
+ });
43
+
44
+ it("keeps the raw value's tail when collapsing its spaces", async () => {
45
+ await using screen = await render(<MiddleTruncate value={"longprefix a b.txt"} />);
46
+
47
+ expect(screen.container.querySelector("[title] > span:last-child")?.textContent).toBe(
48
+ "x a b.txt",
49
+ );
50
+ });
51
});
apps/web/src/components/ui/middle-truncate.tsx
+16
-3
@@ -16,7 +16,8 @@ export function MiddleTruncate({
16
showTitle?: boolean;
17
variant?: "default" | "cap-aligned";
18
}) {
19
- const split = splitForMiddleTruncate(value, tail);
19
+ const raw = splitForMiddleTruncate(value, tail);
20
+ const split = raw && collapseSegments(raw);
21
const headRef = useRef<HTMLSpanElement>(null);
22
const head = split?.head;
23
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- fits the head span's DOM text and refits it through a ResizeObserver
@@ -42,10 +43,12 @@ export function MiddleTruncate({
43
{split ? (
44
<>
45
{/* The tail carries the ellipsis so it sits flush; a CSS ellipsis leaves a ragged gap. */}
45
- <span ref={headRef} className="peer min-w-0 overflow-hidden">
46
+ <span ref={headRef} className="peer min-w-0 overflow-hidden whitespace-pre">
47
{split.head}
48
</span>
48
- <span className="shrink-0 peer-data-overflow:before:content-['…']">{split.tail}</span>
49
+ <span className="shrink-0 whitespace-pre peer-data-overflow:before:content-['…']">
50
+ {split.tail}
51
+ </span>
52
</>
53
) : (
54
// Keyed so React does not reuse the head node and its imperative clip.
@@ -89,6 +92,16 @@ function fitHead(head: HTMLElement) {
92
if (tail instanceof HTMLElement) tail.style.translate = slack > 0 ? `-${slack}px 0` : "";
93
}
94
95
+// The segments render pre so the space at the cut survives, so collapse here what CSS
96
+// would have (not \s: em and no-break spaces are kept). Split first, so the tail length
97
+// still counts the raw value.
98
+function collapseSegments(split: { head: string; tail: string }) {
99
+ const collapse = (text: string) => text.replace(/[ \t\n\r\f]+/g, " ");
100
+ const head = collapse(split.head).replace(/^ /, "");
101
+ const tail = collapse(split.tail).replace(/ $/, "");
102
+ return { head, tail: head.endsWith(" ") ? tail.replace(/^ /, "") : tail };
103
+}
104
+
105
const DEFAULT_TAIL = 10;
106
const MAX_SEGMENT_TAIL = 16;
107
const MIN_WORD_TAIL = 4;