Skip to content

Commit 092c6a7

Browse files
tellahoRizzCarl
authored
fix(markdown): align mention chip wrapping (#7501)
**Category:** fix **User Impact:** Human and agent mentions now break across lines with the same cloned chip treatment as repository and permalink chips while preserving the conversation text rhythm. **Problem:** Profile-backed rendered mentions sat inside an `inline-flex` popover trigger, unlike entity chips, so the wrapper interfered with true inline fragmentation. The browser-layout test measured text-range rows rather than the painted chip rectangles, allowing touching decorations to pass as “separate” fragments. **Solution:** Keep the profile trigger interactive but override its layout to true `inline`, then give mention fragments 18px computed leading inside the message’s 20px prose rhythm. Chromium paints each fragment at 17px and advances it by 20px, leaving a visible gap between cloned rounded rectangles. The browser test now measures the chip’s own `getClientRects()` and asserts fragment count, height, gap, and step; entity links retain their existing 22px leading. <details> <summary>File changes</summary> **desktop/src/features/profile/ui/UserProfilePopover.tsx** Allows inline consumers to override the trigger wrapper’s layout without changing other profile-popover call sites. **desktop/src/shared/styles/globals/markdown.css** Keeps one shared wrapping-chip mechanic and gives mention decorations enough room to separate visibly within 20px prose. **desktop/src/shared/ui/markdown.test.mjs** Pins both rendered mentions and entity links to the shared wrapping-chip contract. **desktop/src/shared/ui/markdown/MarkdownMention.tsx** Makes the profile-popover trigger truly inline so the nested mention chip can fragment with surrounding prose. **desktop/src/shared/ui/mentionChip.ts** Keeps `wrapping-inline-chip` as the single contract for fragmenting decorated chips. **desktop/tests/e2e/mentions.spec.ts** Measures the painted chip rectangles, requires a positive fragment gap, and verifies the inline trigger remains mouse- and keyboard-operable. **desktop/tests/e2e/navigation.spec.ts** Keeps a wrapped repository chip as the control, asserting its existing 22px line height and fragment advance. </details> ## Reproduction steps 1. Open a channel in Buzz Desktop using dark theme. 2. Send a message containing a human mention and another containing an agent mention; both chips should remain aligned with adjacent text on a 20px line. 3. Render a collision-qualified mention in a narrow message width; it should break into separately decorated fragments exactly like another wrapping chip, while each fragment follows the 20px prose rhythm. 4. Render a long repository or permalink chip in the same constrained width; it should retain its roomier 22px fragment spacing. ## Screenshot The dark-theme production renderer shows the real qualified label (`bob (npub1hv3…tpuc)`) at an 8rem width. The two lines now paint as visibly separate rounded fragments rather than one continuous rectangle. ![Qualified human mention wrapping into two visibly separate rounded fragments in the dark-theme Buzz timeline](https://github.com/user-attachments/assets/ee6e7be5-937e-4022-9c82-cf71f8203470) ## Validation At commit `2b063e1b4ade30e11f1616269ad4ba4190366885`: - Pre-push desktop gates — file-size check, Biome/checks, typecheck, and 6,483 unit tests passed - `pnpm --dir desktop build` — passed - Focused Playwright coverage for single-line agent mention, single-line human mention, wrapped qualified mention including keyboard profile activation, and timeline mention click — 4 passed - `git diff --check` — passed --------- Signed-off-by: Taylor Ho <[email protected]> Co-authored-by: Rizz <[email protected]> Co-authored-by: Carl <acda9e433d19dcd0e6b6840f7f4b98f3a56f1fab98049d444c087019e6d36560@buzz.block.builderlab.xyz>
1 parent 0020907 commit 092c6a7

6 files changed

Lines changed: 145 additions & 10 deletions

File tree

‎desktop/src/features/profile/ui/UserProfilePopover.tsx‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ type UserProfilePopoverProps = {
5050
pubkey: string;
5151
triggerElement?: "div" | "span";
5252
/**
53-
* Extra classes for the inline-flex trigger wrapper. The wrapper is a flex
54-
* item at most call sites, and its `min-width: auto` refuses to shrink below
55-
* the nowrap width of truncating children — pass `min-w-0 max-w-full` when
56-
* the trigger wraps truncating text so the ellipsis can engage.
53+
* Extra classes for the trigger wrapper, which defaults to inline-flex.
54+
* Use `min-w-0 max-w-full` when truncating flex content must shrink, or
55+
* `inline` when prose content must fragment across lines.
5756
*/
5857
triggerClassName?: string;
5958
/** Accessible name for interactive trigger content that is visually hidden. */

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@
100100
white-space: normal;
101101
}
102102

103+
/* Mentions use the prose rhythm while retaining cloned chip decoration. */
104+
.message-markdown [data-mention].wrapping-inline-chip {
105+
padding-block: 0;
106+
line-height: calc(var(--conversation-message-line-height) - 2px);
107+
}
108+
103109
.message-markdown .mention-chip.buzz-link-unavailable,
104110
.message-markdown .mention-chip.buzz-link-unavailable:hover,
105111
.message-markdown .mention-chip.buzz-link-deleted,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,6 +1400,7 @@ test("resolved human mentions replace the authored at-sign with the shared icon"
14001400
);
14011401

14021402
assert.match(html, /data-mention=""/);
1403+
assert.match(html, /wrapping-inline-chip/);
14031404
assert.match(
14041405
html,
14051406
/inline-chip-leading-fragment[^>]*inline-chip-icon-human[^>]*>alice<\/span>/,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export function createMarkdownMention(interactive: boolean) {
7777
pubkey={pubkey}
7878
role={isAgentMention ? "bot" : undefined}
7979
triggerElement="span"
80+
triggerClassName="inline"
8081
>
8182
{mentionNode}
8283
</UserProfilePopover>

‎desktop/tests/e2e/mentions.spec.ts‎

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect, test } from "@playwright/test";
1+
import { expect, test, type Locator } from "@playwright/test";
22

33
import { truncateNpub } from "../../src/shared/lib/pubkey";
44
import { waitForAnimations } from "../helpers/animations";
@@ -88,6 +88,43 @@ const JOIN_COLLAPSE_CAPTURE_WIDTH = 560;
8888
const JOIN_COLLAPSE_CAPTURE_HEIGHT = 260;
8989
const JOIN_COLLAPSE_CAPTURE_VERTICAL_PADDING = 24;
9090

91+
async function timelineChipLayout(chip: Locator) {
92+
return chip.evaluate((element) => {
93+
const paragraph = element.closest("p");
94+
if (!paragraph) throw new Error("Timeline chip is missing its paragraph");
95+
const chipBounds = element.getBoundingClientRect();
96+
const paragraphBounds = paragraph.getBoundingClientRect();
97+
const chipFragmentRects = Array.from(element.getClientRects())
98+
.filter((rect) => rect.width > 0 && rect.height > 0)
99+
.sort((a, b) => a.top - b.top);
100+
const chipStyle = getComputedStyle(element);
101+
return {
102+
boxDecorationBreak:
103+
chipStyle.getPropertyValue("box-decoration-break") ||
104+
chipStyle.getPropertyValue("-webkit-box-decoration-break"),
105+
chipHeight: chipBounds.height,
106+
chipLineHeight: Number.parseFloat(chipStyle.lineHeight),
107+
fragmentCount: chipFragmentRects.length,
108+
fragmentGap:
109+
chipFragmentRects.length > 1
110+
? Math.round(chipFragmentRects[1].top - chipFragmentRects[0].bottom)
111+
: null,
112+
fragmentHeight:
113+
chipFragmentRects.length > 0
114+
? Math.round(chipFragmentRects[0].height)
115+
: null,
116+
fragmentStep:
117+
chipFragmentRects.length > 1
118+
? Math.round(chipFragmentRects[1].top - chipFragmentRects[0].top)
119+
: null,
120+
paragraphHeight: paragraphBounds.height,
121+
paragraphLineHeight: Number.parseFloat(
122+
getComputedStyle(paragraph).lineHeight,
123+
),
124+
};
125+
});
126+
}
127+
91128
/** Locator scoped to the mention autocomplete dropdown inside the composer. */
92129
function autocomplete(page: import("@playwright/test").Page) {
93130
return page
@@ -1583,6 +1620,19 @@ test("selecting a persona mention creates a channel agent before sending and sta
15831620
.locator("[data-mention].agent-mention-highlight", { hasText: "Fizz" });
15841621
await expect(mentionChip).toBeVisible();
15851622
await expect(mentionChip).toHaveText("Fizz");
1623+
await expect(mentionChip).toHaveClass(/wrapping-inline-chip/);
1624+
const timelineLayout = await timelineChipLayout(mentionChip);
1625+
expect(timelineLayout).toMatchObject({
1626+
boxDecorationBreak: "clone",
1627+
chipHeight: 17,
1628+
chipLineHeight: 18,
1629+
fragmentCount: 1,
1630+
fragmentGap: null,
1631+
fragmentHeight: 17,
1632+
fragmentStep: null,
1633+
paragraphHeight: 20,
1634+
paragraphLineHeight: 20,
1635+
});
15861636
});
15871637

15881638
test("selecting a persona mention reuses an existing persona agent", async ({
@@ -4518,6 +4568,67 @@ test("mention text is highlighted in sent messages", async ({ page }) => {
45184568
await expect(mentionChip).toBeVisible();
45194569
await expect(mentionChip).toHaveText("bob");
45204570
await expect(mentionChip).toHaveClass(/inline-chip-icon-human/);
4571+
await expect(mentionChip).toHaveClass(/wrapping-inline-chip/);
4572+
4573+
const timelineLayout = await timelineChipLayout(mentionChip);
4574+
expect(timelineLayout).toMatchObject({
4575+
boxDecorationBreak: "clone",
4576+
chipHeight: 17,
4577+
chipLineHeight: 18,
4578+
fragmentCount: 1,
4579+
fragmentGap: null,
4580+
fragmentHeight: 17,
4581+
fragmentStep: null,
4582+
paragraphHeight: 20,
4583+
paragraphLineHeight: 20,
4584+
});
4585+
});
4586+
4587+
test("qualified mentions wrap without changing message line rhythm", async ({
4588+
page,
4589+
}) => {
4590+
const pubkey = TEST_IDENTITIES.bob.pubkey;
4591+
const qualifiedLabel = `bob (${pubkey})`;
4592+
4593+
await page.goto("/");
4594+
await page.getByTestId("channel-general").click();
4595+
await expect(page.getByTestId("chat-title")).toHaveText("general");
4596+
await waitForMockLiveSubscription(page, "general");
4597+
await emitMockMessage(page, "general", `@${qualifiedLabel}`, {
4598+
mentionPubkeys: [pubkey],
4599+
});
4600+
await waitForTimelineSettled(page);
4601+
4602+
const row = page.getByTestId("message-row").filter({ hasText: "bob" }).last();
4603+
await row.evaluate((element) => {
4604+
const prose = element.querySelector<HTMLElement>(".message-markdown");
4605+
if (!prose)
4606+
throw new Error("Qualified mention is missing its prose wrapper");
4607+
prose.style.width = "8rem";
4608+
});
4609+
const mentionChip = row.locator("[data-mention]", { hasText: "bob" });
4610+
await expect(mentionChip).toHaveText(/bob \(npub1hv3…tpuc\)/);
4611+
await expect(mentionChip).toHaveClass(/wrapping-inline-chip/);
4612+
4613+
const layout = await timelineChipLayout(mentionChip);
4614+
expect(layout.boxDecorationBreak).toBe("clone");
4615+
expect(layout.chipLineHeight).toBe(18);
4616+
expect(layout.fragmentCount).toBe(2);
4617+
expect(layout.fragmentHeight).toBe(17);
4618+
expect(layout.fragmentGap).toBeGreaterThanOrEqual(1);
4619+
expect(layout.fragmentStep).toBe(20);
4620+
expect(layout.paragraphLineHeight).toBe(20);
4621+
expect(layout.chipHeight).toBeLessThanOrEqual(
4622+
layout.fragmentCount * layout.paragraphLineHeight,
4623+
);
4624+
4625+
const trigger = mentionChip.locator("xpath=..");
4626+
await expect(trigger).toHaveCSS("display", "inline");
4627+
await expect(trigger).toHaveAttribute("role", "button");
4628+
await trigger.focus();
4629+
await expect(trigger).toBeFocused();
4630+
await trigger.press("Enter");
4631+
await expect(page.getByTestId("user-profile-panel")).toBeVisible();
45214632
});
45224633

45234634
test("clicking author name opens user profile panel", async ({ page }) => {

‎desktop/tests/e2e/navigation.spec.ts‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -577,21 +577,38 @@ test("composer Buzz chip labels wrap without orphaning their icons", async ({
577577
name: "Open repository relaytoolsobservabilityconsole-main",
578578
});
579579
await expect(sentChip).toBeVisible();
580+
await expect(sentChip).toHaveClass(/wrapping-inline-chip/);
580581
await sentChip.evaluate((element) => {
581582
const container = element.parentElement;
582583
if (container) container.style.width = "220px";
583584
});
584-
const fragmentRects = await sentChip.evaluate((element) =>
585-
Array.from(element.getClientRects(), (rect) => ({
585+
const fragmentMetrics = await sentChip.evaluate((element) => {
586+
const chipStyle = getComputedStyle(element);
587+
const rects = Array.from(element.getClientRects(), (rect) => ({
586588
bottom: rect.bottom,
587589
height: rect.height,
588590
left: rect.left,
589591
right: rect.right,
590592
top: rect.top,
591593
width: rect.width,
592-
})).filter((rect) => rect.width > 0 && rect.height > 0),
593-
);
594-
expect(fragmentRects.length).toBeGreaterThanOrEqual(2);
594+
})).filter((rect) => rect.width > 0 && rect.height > 0);
595+
const fragmentTops = Array.from(
596+
new Set(rects.map((rect) => Math.round(rect.top))),
597+
).sort((a, b) => a - b);
598+
return {
599+
boxDecorationBreak:
600+
chipStyle.getPropertyValue("box-decoration-break") ||
601+
chipStyle.getPropertyValue("-webkit-box-decoration-break"),
602+
fragmentStep:
603+
fragmentTops.length > 1 ? fragmentTops[1] - fragmentTops[0] : null,
604+
lineHeight: Number.parseFloat(chipStyle.lineHeight),
605+
rects,
606+
};
607+
});
608+
expect(fragmentMetrics.boxDecorationBreak).toBe("clone");
609+
expect(fragmentMetrics.lineHeight).toBe(22);
610+
expect(fragmentMetrics.fragmentStep).toBe(22);
611+
expect(fragmentMetrics.rects.length).toBeGreaterThanOrEqual(2);
595612

596613
const tooltip = page.getByRole("tooltip");
597614
await sentChip.focus();

0 commit comments

Comments
 (0)