Skip to content

Commit f79d346

Browse files
tellahoCarl
andauthored
fix(composer): wrap Buzz chip labels without orphaning icons (#6581)
**Category:** fix **User Impact:** Long Buzz link chips now wrap without overflowing in composers and sent messages; icon-bearing stubs use at most five graphemes when no earlier separator exists, so some sent chips attach the icon to a shorter prefix than before. Labels over 48 graphemes are visibly truncated in the composer while their full identity remains available to assistive technology and in the tooltip. **Problem:** Long repository, issue, pull request, and channel chip labels could orphan their icon or overflow narrow composers and sent messages. **Solution:** Keep the icon with a bounded, grapheme-safe leading fragment while allowing the remaining text to break anywhere; cap visible labels at 48 graphemes without changing the full tooltip or accessible identity. <details> <summary>File changes</summary> **desktop/src/features/messages/lib/composerMessageLinkNode.ts** Splits composer chip content into an icon-bearing leading fragment and a freely wrapping remainder while preserving the semantic label and link metadata. **desktop/src/features/messages/lib/composerMessageLinkNode.test.mjs** Updates renderer assertions for the fragment structure and verifies every supported Buzz link kind retains the intended visible label. **desktop/src/shared/styles/globals/composer.css** Keeps ordinary composer mention decorations inline while relying on the existing shared markdown chip wrapping rules for Buzz links. **desktop/src/shared/ui/mentionChip.ts** Centralizes grapheme-aware leading-fragment boundaries and label truncation so composer and sent chips share the same visible identity. **desktop/src/shared/ui/markdown/BuzzLinkChip.tsx** Uses the shared grapheme-aware boundary when rendering sent-message chip fragments. **desktop/tests/e2e/navigation.spec.ts** Covers increasing wrap depth across constrained widths, icon attachment, the sent-message wrap, accessible labeling, and tooltip positioning over both edge fragments. </details> ## Reproduction steps 1. Open a desktop channel and paste a Buzz link with a long repository or channel name into the composer. 2. Narrow the composer until the chip spans two or more lines. 3. Confirm the label breaks mid-string while the icon remains attached to the first label fragment. 4. Send the message, hover both the first and last rendered fragments, and confirm the tooltip follows the hovered fragment. ## Screenshots **Before — the icon drops onto a separate line from its chip label** ![Composer chip with an orphaned icon before the fix](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6581/00-before-inline-chip-icon-wrap.png) **After — the icon stays attached while the remaining label wraps** The same long repository chip at three composer widths. Its label gains line breaks as space contracts, while the icon remains attached to the leading fragment. **420px — one line** ![Long repository chip on one line at 420px](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6581/01-wide-420px.png) **210px — two lines** ![Long repository chip on two lines at 210px](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6581/02-medium-210px.png) **150px — three lines** ![Long repository chip on three lines at 150px](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6581/03-narrow-150px.png) --------- Signed-off-by: Taylor Ho <[email protected]> Co-authored-by: Carl <acda9e433d19dcd0e6b6840f7f4b98f3a56f1fab98049d444c087019e6d36560@buzz.block.builderlab.xyz>
1 parent f6e6617 commit f79d346

10 files changed

Lines changed: 545 additions & 37 deletions

File tree

‎desktop/src/features/messages/lib/composerMessageLinkNode.test.mjs‎

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const CHANNEL_MESSAGE_ID = "a".repeat(64);
1919
const CHANNEL_MESSAGE_HREF = `buzz://channel/${CHANNEL_ID}/${CHANNEL_MESSAGE_ID}`;
2020
const OWNER = "a".repeat(64);
2121
const REPO_HREF = `buzz://repo?owner=${OWNER}&d=buzz-world`;
22+
const PROJECT_HREF = `buzz://project?owner=${OWNER}&d=buzz-world`;
2223
const ISSUE_ID = "b".repeat(64);
2324
const ISSUE_HREF = `buzz://issue?id=${ISSUE_ID}&owner=${OWNER}&d=buzz-world`;
2425
const PR_ID = "c".repeat(64);
@@ -188,6 +189,10 @@ test("markdown parsing stops message links before emphasis delimiters", () => {
188189
assert.deepEqual(token.meta, { channelName: "general", href: HREF });
189190
});
190191

192+
function renderedChipLabel(rendered) {
193+
return `${rendered[2][2]}${rendered[3]}`;
194+
}
195+
191196
test("composer node uses the sent-message chip presentation", () => {
192197
const node = {
193198
attrs: { channelName: "general", href: HREF },
@@ -209,7 +214,44 @@ test("composer node uses the sent-message chip presentation", () => {
209214
assert.equal(rendered[1]["data-buzz-link"], "");
210215
// Channel label only — no event hash, so the chip does not change width when
211216
// the draft is sent and the rendered chip resolves its metadata.
212-
assert.equal(rendered[2], "general");
217+
assert.match(rendered[1].class, /wrapping-inline-chip/);
218+
assert.match(rendered[2][1].class, /inline-chip-leading-fragment/);
219+
assert.equal(renderedChipLabel(rendered), "general");
220+
});
221+
222+
test("composer node truncates and preserves grapheme-safe leading fragments", () => {
223+
const render = ComposerMessageLinkNode.configure({
224+
resolveChannelName: () => undefined,
225+
}).config.renderHTML;
226+
assert.ok(render);
227+
228+
const longName = `relay-${"observability".repeat(5)}`;
229+
const longRendered = render.call(
230+
{ options: { resolveChannelName: () => undefined } },
231+
{
232+
node: { attrs: { channelName: longName, href: HREF } },
233+
HTMLAttributes: {},
234+
},
235+
);
236+
assert.equal(renderedChipLabel(longRendered), `${longName.slice(0, 47)}…`);
237+
238+
for (const [label, expectedLeading] of [
239+
["🇺🇸channel", "🇺🇸chan"],
240+
["e\u0301quipe", "e\u0301quip"],
241+
["relaytoolsobservabilityconsole-main", "relay"],
242+
[" leading-space", ""],
243+
]) {
244+
const rendered = render.call(
245+
{ options: { resolveChannelName: () => undefined } },
246+
{
247+
node: { attrs: { channelName: label, href: HREF } },
248+
HTMLAttributes: {},
249+
},
250+
);
251+
assert.equal(rendered[2][2], expectedLeading);
252+
assert.match(rendered[2][1].class, /inline-chip-with-icon/);
253+
assert.equal(renderedChipLabel(rendered), label);
254+
}
213255
});
214256

215257
test("composer node renders channel and entity chip presentations", () => {
@@ -227,24 +269,29 @@ test("composer node renders channel and entity chip presentations", () => {
227269
const channel = render(CHANNEL_HREF);
228270
assert.equal(channel[1]["data-channel-deep-link"], "");
229271
assert.match(channel[1].class, /inline-chip-icon-channel/);
230-
assert.equal(channel[2], "general");
272+
assert.equal(renderedChipLabel(channel), "general");
231273

232274
const repo = render(REPO_HREF);
233275
assert.equal(repo[1]["data-buzz-link-kind"], "repo");
234276
assert.match(repo[1].class, /inline-chip-icon-repo/);
235-
assert.equal(repo[2], "buzz-world");
277+
assert.equal(renderedChipLabel(repo), "buzz-world");
278+
279+
const project = render(PROJECT_HREF);
280+
assert.equal(project[1]["data-buzz-link-kind"], "project");
281+
assert.match(project[1].class, /inline-chip-icon-project/);
282+
assert.equal(renderedChipLabel(project), "buzz-world");
236283

237284
const issue = render(ISSUE_HREF);
238285
assert.equal(issue[1]["data-buzz-link-kind"], "issue");
239286
assert.match(issue[1].class, /inline-chip-icon-issue/);
240287
// Repository name only — the rendered chip never widens into the issue
241288
// title, so the composer must not widen into the event hash either.
242-
assert.equal(issue[2], "buzz-world");
289+
assert.equal(renderedChipLabel(issue), "buzz-world");
243290

244291
const pullRequest = render(PR_HREF);
245292
assert.equal(pullRequest[1]["data-buzz-link-kind"], "pr");
246293
assert.match(pullRequest[1].class, /inline-chip-icon-pr/);
247-
assert.equal(pullRequest[2], "buzz-world");
294+
assert.equal(renderedChipLabel(pullRequest), "buzz-world");
248295
});
249296

250297
test("markdown rendering stores identity in attributes, not visible id text", () => {

‎desktop/src/features/messages/lib/composerMessageLinkNode.ts‎

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ import {
1212
} from "@/shared/lib/entityLink";
1313
import {
1414
inlineChipIconClasses,
15+
inlineChipLeadingEnd,
1516
type InlineChipIconKind,
1617
MENTION_CHIP_BASE_CLASSES,
18+
truncateInlineChipLabel,
19+
WRAPPING_INLINE_CHIP_CLASSES,
1720
} from "@/shared/ui/mentionChip";
1821
import { buildChannelLink, parseChannelLink } from "./channelLink";
1922
import { getMessageLinkLabel } from "./messageLinkLabel";
@@ -285,6 +288,38 @@ function composerLinkPresentation(
285288
};
286289
}
287290

291+
function wrappingComposerChipContent(
292+
label: string,
293+
icon: InlineChipIconKind,
294+
): { leading: [string, Record<string, string>, string]; remainder: string } {
295+
const leadingEnd = inlineChipLeadingEnd(label);
296+
if (!leadingEnd) {
297+
return {
298+
leading: [
299+
"span",
300+
{
301+
"aria-hidden": "true",
302+
class: `inline-chip-leading-fragment ${inlineChipIconClasses(icon)}`,
303+
},
304+
"",
305+
],
306+
remainder: label,
307+
};
308+
}
309+
310+
return {
311+
leading: [
312+
"span",
313+
{
314+
"aria-hidden": "true",
315+
class: `inline-chip-leading-fragment ${inlineChipIconClasses(icon)}`,
316+
},
317+
label.slice(0, leadingEnd),
318+
],
319+
remainder: label.slice(leadingEnd),
320+
};
321+
}
322+
288323
export const ComposerMessageLinkNode =
289324
Node.create<ComposerMessageLinkNodeOptions>({
290325
name: COMPOSER_MESSAGE_LINK_NODE_NAME,
@@ -328,19 +363,25 @@ export const ComposerMessageLinkNode =
328363
String(node.attrs.channelName ?? ""),
329364
this.options.resolveChannelName,
330365
);
366+
const visibleLabel = truncateInlineChipLabel(presentation.label);
367+
const content = wrappingComposerChipContent(
368+
visibleLabel,
369+
presentation.icon,
370+
);
331371
return [
332372
"span",
333373
mergeAttributes(HTMLAttributes, {
334374
"aria-label": presentation.ariaLabel,
335-
class: `${MENTION_CHIP_BASE_CLASSES} ${inlineChipIconClasses(presentation.icon)} cursor-text`,
375+
class: `${MENTION_CHIP_BASE_CLASSES} ${WRAPPING_INLINE_CHIP_CLASSES} ${inlineChipIconClasses(presentation.icon)} cursor-text`,
336376
"data-buzz-link": "",
337377
"data-channel-name": presentation.channelName,
338378
"data-composer-buzz-link": "",
339379
"data-href": href,
340380
...presentation.dataAttributes,
341381
title: presentation.ariaLabel,
342382
}),
343-
presentation.label,
383+
content.leading,
384+
content.remainder,
344385
];
345386
},
346387

‎desktop/src/shared/styles/globals/composer.css‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,11 @@
256256
Body copy is text-sm; inline code labels sit one step down (text-xs).
257257
All chip variants share one box height so mono labels stay balanced.
258258
259-
Rendered-message chips use inline-flex. The same decoration in the
260-
composer pulls the caret into the chip and swallows the trailing
261-
space after an @mention, so typing "hello" after @quinn becomes
262-
"@quinnhello". Keep composer chips inline; leave ::before icons in
263-
place. */
259+
Plain-text mention decorations stay inline because inline-flex pulls the
260+
caret into their decorated range and swallows the trailing space after an
261+
@mention. Composer Buzz links are atom nodes, but their labels may still
262+
fragment between characters; only the icon and leading label fragment stay
263+
together. */
264264
.rich-text-composer .tiptap .mention-chip {
265265
display: inline;
266266
min-height: 0;

‎desktop/src/shared/styles/globals/markdown.css‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@
211211
white-space: nowrap;
212212
}
213213

214+
.message-markdown
215+
.inline-chip-leading-fragment.inline-chip-with-icon:empty::after {
216+
content: "\200b";
217+
}
218+
214219
.message-markdown .inline-chip-leading-fragment.inline-chip-with-icon::before {
215220
display: block;
216221
left: 0;

‎desktop/src/shared/ui/markdown.test.mjs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ test("bare Buzz permalinks render cohesive icon-prefixed chips", () => {
11211121
assert.equal((html.match(/data-channel-deep-link=""/g) ?? []).length, 1);
11221122
assert.match(html, /inline-chip-icon-channel/);
11231123
assert.match(html, /wrapping-inline-chip/);
1124-
assert.match(html, /inline-chip-leading-fragment[^>]*>e</);
1124+
assert.match(html, /inline-chip-leading-fragment[^>]*>engin</);
11251125
assert.match(html, /inline-chip-icon-pr/);
11261126
assert.match(html, /inline-chip-icon-issue/);
11271127
assert.match(html, /inline-chip-icon-repo/);
@@ -1299,7 +1299,7 @@ test("bare Buzz permalinks shorten unavailable channel identifiers", () => {
12991299
);
13001300

13011301
assert.equal(
1302-
(html.match(/inline-chip-leading-fragment[^>]*>5<\/span>80ca78b/g) ?? [])
1302+
(html.match(/inline-chip-leading-fragment[^>]*>580ca<\/span>78b/g) ?? [])
13031303
.length,
13041304
2,
13051305
);
@@ -1332,7 +1332,7 @@ test("channel references replace the authored hash with the channel icon", () =>
13321332

13331333
assert.match(html, /inline-chip-icon-channel/);
13341334
assert.match(html, /wrapping-inline-chip/);
1335-
assert.match(html, /inline-chip-leading-fragment[^>]*>e</);
1335+
assert.match(html, /inline-chip-leading-fragment[^>]*>engin</);
13361336
assert.match(html.replace(/<[^>]+>/g, ""), /engineering/);
13371337
assert.doesNotMatch(html, />#engineering</);
13381338
});

‎desktop/src/shared/ui/markdown/BuzzLinkChip.tsx‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { cn } from "@/shared/lib/cn";
55
import { InlineChip } from "@/shared/ui/InlineChip";
66
import {
77
inlineChipIconClasses,
8+
inlineChipLeadingEnd,
89
type InlineChipIconKind,
910
truncateInlineChipLabel,
1011
WRAPPING_INLINE_CHIP_CLASSES,
@@ -72,12 +73,21 @@ function wrappingChipContent(
7273
): React.ReactNode {
7374
if (typeof children !== "string" || children.length === 0) return children;
7475

75-
const separatorIndex = children.search(/[-\s]/u);
76-
const leadingEnd =
77-
separatorIndex < 0
78-
? Array.from(children)[0]?.length
79-
: separatorIndex + (children[separatorIndex] === "-" ? 1 : 0);
80-
if (!leadingEnd) return children;
76+
const leadingEnd = inlineChipLeadingEnd(children);
77+
if (!leadingEnd) {
78+
return (
79+
<>
80+
<span
81+
aria-hidden="true"
82+
className={cn(
83+
"inline-chip-leading-fragment",
84+
inlineChipIconClasses(icon),
85+
)}
86+
/>
87+
{children}
88+
</>
89+
);
90+
}
8191

8292
return (
8393
<>

0 commit comments

Comments
 (0)