Skip to content

Commit 45f4b91

Browse files
tellahoCarl
andauthored
fix(desktop): more compact "compact" link previews (#5629)
**Category:** improvement **User Impact:** Compact link previews now use a single-line title and smaller thumbnail, making conversations easier to scan. **Problem:** Compact previews gave long titles and oversized thumbnails too much visual weight in the message timeline. **Solution:** Keep titles to one ellipsized line and reduce image thumbnails to a 104×64 treatment while preserving the existing wide aspect ratio; Rich previews remain unchanged. <details> <summary>File changes</summary> **desktop/src/shared/ui/compact-link-preview-attachment.tsx** Tightens the Compact presentation with a single-line title and smaller wide thumbnail, leaving Rich previews untouched. **desktop/tests/e2e/messaging.spec.ts** Adds focused coverage for title overflow, exact 64px card and 104×64 thumbnail geometry, and successful decoded-image rendering using a realistic fixture, plus an optional visual capture. **desktop/tests/fixtures/github-pr-5629-og.png** Provides realistic visible image bytes for the compact-preview image-rendering E2E path. </details> ## Reproduction steps 1. Launch the desktop app with link preview style set to Compact. 2. Send a link whose preview has an image and a long title. 3. Confirm the thumbnail renders at the smaller wide size and the title truncates to one line with an ellipsis. 4. Switch link preview style to Rich and confirm its presentation is unchanged. ## Screenshot ![Compact link preview at 64px tall with a decoded real-image thumbnail and one-line truncated title](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/5629/compact-link-preview-real-image-64px.png) --------- Signed-off-by: Taylor Ho <[email protected]> Co-authored-by: Carl <acda9e433d19dcd0e6b6840f7f4b98f3a56f1fab98049d444c087019e6d36560@buzz.block.builderlab.xyz>
1 parent 98d3d77 commit 45f4b91

3 files changed

Lines changed: 61 additions & 6 deletions

File tree

‎desktop/src/shared/ui/compact-link-preview-attachment.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export function CompactLinkPreviewAttachment({
7979
className={cn(
8080
"w-full bg-transparent no-underline shadow-none hover:bg-transparent",
8181
reserveImage
82-
? "h-21 min-h-21 max-h-21 gap-0 border-0 p-0 hover:border-transparent"
82+
? "gap-0 border-0 px-0 py-0 hover:border-transparent"
8383
: "rounded-none border-0 border-l-[3px] border-border px-0 py-1 pl-3 hover:border-border",
8484
)}
8585
data-image-state={preview.imageState}
@@ -89,7 +89,7 @@ export function CompactLinkPreviewAttachment({
8989
{reserveImage ? (
9090
<AttachmentMedia
9191
aria-hidden={showImage ? undefined : "true"}
92-
className="aspect-auto h-full min-h-0 w-30 min-w-30 max-w-30 self-stretch rounded-xl bg-muted sm:w-34 sm:min-w-34 sm:max-w-34"
92+
className="aspect-auto h-16 w-26 rounded-xl bg-muted"
9393
data-link-preview-thumbnail=""
9494
variant="image"
9595
>
@@ -110,7 +110,7 @@ export function CompactLinkPreviewAttachment({
110110
)}
111111
</AttachmentMedia>
112112
) : null}
113-
<AttachmentContent className={reserveImage ? "px-2 py-2" : undefined}>
113+
<AttachmentContent className={reserveImage ? "px-2 py-1.5" : undefined}>
114114
<a
115115
className="relative z-20 flex w-fit max-w-full min-w-0 items-center gap-1.5 text-xs font-normal leading-4 text-muted-foreground/70 group-hover/attachment:underline"
116116
data-link-preview-hostname=""
@@ -145,7 +145,7 @@ export function CompactLinkPreviewAttachment({
145145
) : null}
146146
<span className="truncate">{hostname}</span>
147147
</a>
148-
<AttachmentTitle className="line-clamp-2 whitespace-normal group-hover/attachment:underline">
148+
<AttachmentTitle className="group-hover/attachment:underline">
149149
{preview.title}
150150
</AttachmentTitle>
151151
{preview.description ? (

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

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
import { readFileSync } from "node:fs";
2+
13
import { expect, test, type Locator } from "@playwright/test";
24

35
import { waitForAnimations } from "../helpers/animations";
46
import { installMockBridge, TEST_IDENTITIES } from "../helpers/bridge";
57
import { expectCornerRadiusPx, expectSmoothCorners } from "../helpers/css";
68
import { openSettings } from "../helpers/settings";
79

10+
const LINK_PREVIEW_IMAGE = readFileSync(
11+
new URL("../fixtures/github-pr-5629-og.png", import.meta.url),
12+
);
13+
const LINK_PREVIEW_IMAGE_DATA_URL = `data:image/png;base64,${LINK_PREVIEW_IMAGE.toString("base64")}`;
14+
815
async function waitForReadyComposerSnapshots(
916
page: import("@playwright/test").Page,
1017
count = 1,
@@ -208,8 +215,7 @@ test.beforeEach(async ({ page }, testInfo) => {
208215
siteName: "GitHub",
209216
description:
210217
"A polished, stable preview for shared links.",
211-
imageDataUrl:
212-
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=",
218+
imageDataUrl: LINK_PREVIEW_IMAGE_DATA_URL,
213219
imageDomain: "opengraph.githubassets.com",
214220
faviconDataUrl:
215221
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=",
@@ -1302,6 +1308,55 @@ test("composer link preview embeds stay attachment-sized while loading and ready
13021308
}
13031309
});
13041310

1311+
test("compact link preview image geometry truncates long titles to one line", async ({
1312+
page,
1313+
}) => {
1314+
const previewUrl = "https://github.com/block/buzz/pull/3246?geometry=1";
1315+
await page.route("http://localhost:3000/media/*.png", (route) =>
1316+
route.fulfill({
1317+
body: LINK_PREVIEW_IMAGE,
1318+
contentType: "image/png",
1319+
}),
1320+
);
1321+
await page.setViewportSize({ width: 800, height: 700 });
1322+
await page.goto("/");
1323+
await page.getByTestId("channel-general").click();
1324+
await page.getByTestId("message-input").fill(previewUrl);
1325+
await waitForReadyComposerSnapshots(page);
1326+
await page.getByTestId("send-message").click();
1327+
1328+
const row = page.getByTestId("message-row").last();
1329+
const card = row.locator('[data-link-preview="github-pull-request"]');
1330+
const thumbnail = card.locator("[data-link-preview-thumbnail]");
1331+
const title = card.locator('[data-slot="attachment-title"]');
1332+
const image = thumbnail.locator("img");
1333+
await expect(card).toHaveAttribute("data-image-state", "image");
1334+
await expect(image).toBeVisible();
1335+
await expect
1336+
.poll(() => image.evaluate((element) => element.naturalWidth))
1337+
.toBeGreaterThan(0);
1338+
await expect(card).toHaveCSS("height", "64px");
1339+
await expect(thumbnail).toHaveCSS("height", "64px");
1340+
await expect(thumbnail).toHaveCSS("width", "104px");
1341+
await expect(title).toHaveText(
1342+
"Ship a wider horizontal preview with a two-line title that wraps cleanly",
1343+
);
1344+
await expect(title).toHaveCSS("white-space", "nowrap");
1345+
await expect
1346+
.poll(() =>
1347+
title.evaluate((element) => element.scrollWidth - element.clientWidth),
1348+
)
1349+
.toBeGreaterThan(1);
1350+
1351+
if (process.env.BUZZ_LINK_PREVIEW_SCREENSHOTS_DIR) {
1352+
await waitForAnimations(page);
1353+
await row.screenshot({
1354+
animations: "disabled",
1355+
path: `${process.env.BUZZ_LINK_PREVIEW_SCREENSHOTS_DIR}/recipient-compact-long-title.png`,
1356+
});
1357+
}
1358+
});
1359+
13051360
test("composer no-image link embeds keep the attachment footprint", async ({
13061361
page,
13071362
}) => {
4.3 KB
Loading

0 commit comments

Comments
 (0)