Skip to content

Commit 723affe

Browse files
tellahoRizzMongo
authored
fix(desktop): remove Buzz entity link previews (#6512)
**Category:** improvement **User Impact:** Buzz-native project, repository, issue, and pull request links now appear once as compact inline chips, with their details available on hover. **Problem:** Buzz-native entity links rendered both an inline chip and a standalone preview card, repeating the same metadata and adding visual noise to conversations. **Solution:** Exclude Buzz-native links from the shared standalone-preview extractor while leaving entity parsing intact for chip tooltips and preserving external web previews and attachment cards. <details> <summary>File changes</summary> **desktop/src/shared/lib/linkPreview.ts** Stops Buzz-native preview candidates after parsing, including same-relay git clone URLs that normalize to repository entities, while allowing external URLs through the existing snapshot path. **desktop/src/shared/lib/linkPreview.test.mjs** Covers project, repository, issue, pull request, markdown-labeled, same-relay clone, and mixed external-link extraction behavior. **desktop/src/shared/ui/markdown/useMessageLinkPreviews.test.mjs** Confirms sent messages no longer merge a standalone Buzz entity card while external sender snapshots still render. </details> ## Reproduction steps 1. Open a desktop channel containing a `buzz://project`, `buzz://repo`, `buzz://issue`, or `buzz://pr` link. 2. Confirm the link renders as an inline entity chip without a second standalone Buzz card below the message. 3. Hover the chip and confirm its entity metadata remains available. 4. Post an external HTTPS link and confirm its web preview still renders. 5. Paste a same-relay `/git/<owner>/<repo>` clone URL and confirm it uses the repository chip without a duplicate card. ## Screenshots | Before | After | | --- | --- | | Inline chip plus redundant standalone Project card | Inline chip is now the sole presentation | | ![Before: project chip and duplicate standalone card](https://raw.githubusercontent.com/block/buzz/7e1a0d6cfb52382ef636d7331cf30ea334429c4d/pr-6512--before.png) | ![After: project chip without a standalone card](https://raw.githubusercontent.com/block/buzz/7e1a0d6cfb52382ef636d7331cf30ea334429c4d/pr-6512--after.png) | **After — rich metadata stays available on hover** ![After: dark theme with pink accent and Project tooltip showing description and repository count](https://raw.githubusercontent.com/block/buzz/7e1a0d6cfb52382ef636d7331cf30ea334429c4d/pr-6512--after-tooltip-rich.png) ## Verification At commit `3fa74cdd342ac1f6721b7d56a7f111af31e0e6e9`: - focused link-preview + Markdown unit suites — 119/119 passed - targeted registered smoke E2E — 8/8 passed, including labeled same-relay clone metadata, ordinary-link presentation, and in-app navigation - `cd desktop && pnpm exec tsc --noEmit` — passed - `git diff --check origin/main...HEAD` — passed - pre-push hooks — desktop check, TypeScript, and full desktop unit suite passed --------- Signed-off-by: Rizz <302abe414ca6e3134763d2539bfcf145aea2a63fe5f8455204ed602fd40cf381@buzz.block.builderlab.xyz> Signed-off-by: Taylor Ho <[email protected]> Co-authored-by: Rizz <302abe414ca6e3134763d2539bfcf145aea2a63fe5f8455204ed602fd40cf381@buzz.block.builderlab.xyz> Co-authored-by: Mongo <5398c5fd039b963ce132b3e078e7c4af097dd997517bb5e14c2682fe68c25197@buzz.block.builderlab.xyz>
1 parent 0745612 commit 723affe

11 files changed

Lines changed: 391 additions & 253 deletions

‎desktop/src/features/messages/ui/useComposerLinkPreviews.test.mjs‎

Lines changed: 116 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,18 @@ test("composer input versions retain only active hrefs while re-entry advances",
7070
nextHrefVersion: 0,
7171
};
7272

73-
input = updateComposerLinkPreviewInput(input, `see ${HREF}`);
73+
input = updateComposerLinkPreviewInput(input, `see ${HREF}`, null);
7474
const firstVersion = input.hrefVersions.get(HREF);
7575
assert.equal(input.hrefVersions.size, 1);
7676

77-
input = updateComposerLinkPreviewInput(input, `see ${secondHref}`);
77+
input = updateComposerLinkPreviewInput(input, `see ${secondHref}`, null);
7878
assert.deepEqual(
7979
[...input.hrefVersions.keys()],
8080
[secondHref],
8181
"departed href history is pruned instead of retained for the composer lifetime",
8282
);
8383

84-
input = updateComposerLinkPreviewInput(input, `see ${HREF}`);
84+
input = updateComposerLinkPreviewInput(input, `see ${HREF}`, null);
8585
assert.deepEqual([...input.hrefVersions.keys()], [HREF]);
8686
assert.ok(
8787
input.hrefVersions.get(HREF) > firstVersion,
@@ -159,6 +159,7 @@ test("composer forces a refetch and drops the stale tag on a fast clear+re-paste
159159
nextHrefVersion: 0,
160160
},
161161
`see ${HREF}`,
162+
null,
162163
);
163164
const { result, rerender, unmount } = renderHook(
164165
({ content, hrefVersions }) =>
@@ -183,10 +184,11 @@ test("composer forces a refetch and drops the stale tag on a fast clear+re-paste
183184
// href set equals the previous commit, but the update-boundary version has
184185
// advanced because the URL left and re-entered between those updates.
185186
await act(async () => {
186-
previewInput = updateComposerLinkPreviewInput(previewInput, "see ");
187+
previewInput = updateComposerLinkPreviewInput(previewInput, "see ", null);
187188
previewInput = updateComposerLinkPreviewInput(
188189
previewInput,
189190
`see ${HREF}`,
191+
null,
190192
);
191193
rerender(previewInput);
192194
});
@@ -318,6 +320,7 @@ test("a removed blocked re-entry can later use metadata that resolved while abse
318320
nextHrefVersion: 0,
319321
},
320322
`see ${HREF}`,
323+
null,
321324
);
322325
const { result, rerender, unmount } = renderHook(
323326
({ content, hrefVersions }) =>
@@ -330,10 +333,11 @@ test("a removed blocked re-entry can later use metadata that resolved while abse
330333

331334
// Re-enter the cached negative and wait until its forced refetch is in flight.
332335
await act(async () => {
333-
previewInput = updateComposerLinkPreviewInput(previewInput, "see ");
336+
previewInput = updateComposerLinkPreviewInput(previewInput, "see ", null);
334337
previewInput = updateComposerLinkPreviewInput(
335338
previewInput,
336339
`see ${HREF}`,
340+
null,
337341
);
338342
rerender(previewInput);
339343
});
@@ -345,7 +349,7 @@ test("a removed blocked re-entry can later use metadata that resolved while abse
345349
// Remove the blocked href, then let its refetch populate healthy metadata
346350
// while no candidate is active.
347351
await act(async () => {
348-
previewInput = updateComposerLinkPreviewInput(previewInput, "see ");
352+
previewInput = updateComposerLinkPreviewInput(previewInput, "see ", null);
349353
rerender(previewInput);
350354
});
351355
await settle();
@@ -359,6 +363,7 @@ test("a removed blocked re-entry can later use metadata that resolved while abse
359363
previewInput = updateComposerLinkPreviewInput(
360364
previewInput,
361365
`see ${HREF}`,
366+
null,
362367
);
363368
rerender(previewInput);
364369
});
@@ -486,6 +491,7 @@ test("a stale in-flight upload cannot publish after the URL re-enters and a fres
486491
nextHrefVersion: 0,
487492
},
488493
`see ${HREF}`,
494+
null,
489495
);
490496
const { result, rerender, unmount } = renderHook(
491497
({ content, hrefVersions }) =>
@@ -510,10 +516,11 @@ test("a stale in-flight upload cannot publish after the URL re-enters and a fres
510516

511517
// 2. Fast gesture: clear then re-paste the SAME URL inside the debounce.
512518
await act(async () => {
513-
previewInput = updateComposerLinkPreviewInput(previewInput, "see ");
519+
previewInput = updateComposerLinkPreviewInput(previewInput, "see ", null);
514520
previewInput = updateComposerLinkPreviewInput(
515521
previewInput,
516522
`see ${HREF}`,
523+
null,
517524
);
518525
rerender(previewInput);
519526
});
@@ -750,3 +757,105 @@ test("an abandoned concurrent render cannot invalidate the committed snapshot ta
750757
ipcHandlers.clear();
751758
}
752759
});
760+
761+
// ── Composer clone-URL classification ────────────────────────────────────────
762+
//
763+
// A same-relay `/git/<owner>/<repo>` clone URL is a Buzz repository entity: the
764+
// renderer normalizes it onto `buzz://repo` and shows it as an inline chip, not
765+
// a standalone card. The composer must reach the same verdict from the same
766+
// active relay origin — without it the URL is classified as an external
767+
// generic-link, enters snapshot fetching, and shows a card the sent message
768+
// then contradicts.
769+
770+
const CLONE_OWNER = "a".repeat(64);
771+
const RELAY_ORIGIN = "https://relay.example.com";
772+
const CLONE_HREF = `${RELAY_ORIGIN}/git/${CLONE_OWNER}/relay-tools.git`;
773+
774+
test("composer input classifies a same-relay clone URL as a Buzz entity", async () => {
775+
const { updateComposerLinkPreviewInput } = await import(
776+
"./useComposerLinkPreviews.tsx"
777+
);
778+
const empty = {
779+
content: "",
780+
hrefs: new Set(),
781+
hrefVersions: new Map(),
782+
nextHrefVersion: 0,
783+
};
784+
785+
assert.deepEqual(
786+
[
787+
...updateComposerLinkPreviewInput(
788+
empty,
789+
`clone ${CLONE_HREF}`,
790+
RELAY_ORIGIN,
791+
).hrefs,
792+
],
793+
[],
794+
"a same-relay clone URL is a chip-only entity, never a preview candidate",
795+
);
796+
// A different origin sharing the path shape stays an ordinary external link.
797+
assert.deepEqual(
798+
[
799+
...updateComposerLinkPreviewInput(
800+
empty,
801+
`clone ${CLONE_HREF}`,
802+
"https://evil.example.com",
803+
).hrefs,
804+
],
805+
[CLONE_HREF],
806+
);
807+
});
808+
809+
test("composer never fetches a snapshot for a same-relay clone URL", async () => {
810+
const { act, cleanup, renderHook } = await import("@testing-library/react");
811+
const { getCachedRelayOrigin } = await import("@/shared/lib/mediaUrl.ts");
812+
const { resetLinkPreviewMetadataCache } = await import(
813+
"@/shared/lib/useResolvedLinkPreviews.ts"
814+
);
815+
const { useComposerLinkPreviews } = await import(
816+
"./useComposerLinkPreviews.tsx"
817+
);
818+
819+
resetLinkPreviewMetadataCache();
820+
ipcHandlers.clear();
821+
ipcHandlers.set("get_relay_http_url", () => Promise.resolve(RELAY_ORIGIN));
822+
let fetchCalls = 0;
823+
ipcHandlers.set("fetch_link_preview_metadata", () => {
824+
fetchCalls += 1;
825+
return Promise.resolve(metadata());
826+
});
827+
828+
try {
829+
// The origin resolves asynchronously; the classification under test only
830+
// exists once it is known, so wait for the shared cache to publish it.
831+
const deadline = Date.now() + 5000;
832+
while (getCachedRelayOrigin() !== RELAY_ORIGIN && Date.now() < deadline) {
833+
await new Promise((resolve) => setTimeout(resolve, 25));
834+
}
835+
assert.equal(getCachedRelayOrigin(), RELAY_ORIGIN);
836+
837+
const { result, unmount } = renderHook(() =>
838+
useComposerLinkPreviews(`clone ${CLONE_HREF}`),
839+
);
840+
await act(async () => {
841+
await new Promise((resolve) => setTimeout(resolve, DEBOUNCE_WAIT_MS));
842+
});
843+
await act(async () => {
844+
await new Promise((resolve) => setTimeout(resolve, 50));
845+
});
846+
847+
assert.equal(
848+
fetchCalls,
849+
0,
850+
"a Buzz repository entity must not enter external snapshot fetching",
851+
);
852+
assert.equal(result.current.previewList, null);
853+
assert.deepEqual(result.current.getReadyTags(), []);
854+
assert.deepEqual(result.current.getLiveCandidates(), []);
855+
assert.equal(result.current.hasPendingSnapshots, false);
856+
unmount();
857+
} finally {
858+
cleanup();
859+
ipcHandlers.clear();
860+
}
861+
});

‎desktop/src/features/messages/ui/useComposerLinkPreviews.tsx‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
beginRelayOriginFetch,
1313
getCachedRelayOrigin,
1414
} from "@/shared/lib/mediaUrl";
15+
import { useRelayOrigin } from "@/shared/lib/useRelayOrigin";
1516
import {
1617
isBuzzEntityPreview,
1718
type ResolvedLinkPreview,
@@ -199,9 +200,10 @@ export interface ComposerLinkPreviewInput {
199200
export function updateComposerLinkPreviewInput(
200201
current: ComposerLinkPreviewInput,
201202
content: string,
203+
relayOrigin: string | null,
202204
): ComposerLinkPreviewInput {
203205
const nextHrefs = new Set(
204-
extractSupportedLinkPreviews(content)
206+
extractSupportedLinkPreviews(content, relayOrigin)
205207
.filter((preview) =>
206208
preview.href.startsWith("buzz://")
207209
? true
@@ -235,11 +237,28 @@ export function useComposerLinkPreviewInput() {
235237
hrefVersions: new Map(),
236238
nextHrefVersion: 0,
237239
}));
240+
// Read the origin through the store subscription so a paste that lands
241+
// before the async lookup resolves is reclassified — an href set frozen at
242+
// first-render time would keep a same-relay clone URL versioned as an
243+
// external candidate for the life of the composer.
244+
const relayOrigin = useRelayOrigin();
238245
const update = React.useCallback(
239246
(content: string) =>
240-
setInput((current) => updateComposerLinkPreviewInput(current, content)),
241-
[],
247+
setInput((current) =>
248+
updateComposerLinkPreviewInput(current, content, relayOrigin),
249+
),
250+
[relayOrigin],
242251
);
252+
// Re-classify already-entered content when the origin resolves or changes.
253+
// An empty draft has nothing to reclassify; returning `current` lets React
254+
// bail out of the mount-time pass instead of re-rendering the composer.
255+
React.useEffect(() => {
256+
setInput((current) =>
257+
current.content
258+
? updateComposerLinkPreviewInput(current, current.content, relayOrigin)
259+
: current,
260+
);
261+
}, [relayOrigin]);
243262
return [input, update] as const;
244263
}
245264

@@ -273,16 +292,17 @@ export function useComposerLinkPreviews(
273292
);
274293
return () => window.clearTimeout(timer);
275294
}, [content]);
295+
const relayOrigin = useRelayOrigin();
276296
const extractCandidates = React.useCallback(
277297
(source: string) =>
278298
enabled
279-
? extractSupportedLinkPreviews(source).filter((preview) =>
299+
? extractSupportedLinkPreviews(source, relayOrigin).filter((preview) =>
280300
preview.href.startsWith("buzz://")
281301
? true
282302
: isValidLinkPreviewSnapshotCanonicalUrl(preview.href),
283303
)
284304
: [],
285-
[enabled],
305+
[enabled, relayOrigin],
286306
);
287307
const candidates = React.useMemo(
288308
() => extractCandidates(debounced),

‎desktop/src/features/projects/hooks.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,12 +662,13 @@ export const PROJECT_WORK_ITEMS_STALE_TIME_MS = 2 * 60_000;
662662
export const PROJECT_ACTIVITY_STALE_TIME_MS = 2 * 60_000;
663663
export const PROJECT_LOCAL_REPOS_STALE_TIME_MS = 2 * 60_000;
664664

665-
export function useProjectsQuery() {
665+
export function useProjectsQuery(enabled = true) {
666666
return useQuery({
667667
queryKey: projectsQueryKey,
668668
queryFn: ({ signal }) => fetchProjects(undefined, signal),
669669
staleTime: PROJECTS_STALE_TIME_MS,
670670
gcTime: PROJECTS_GC_TIME_MS,
671+
enabled,
671672
});
672673
}
673674

0 commit comments

Comments
 (0)