Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-5928: fix(issues): bound board description previews (#6634)
epolevov-nspe6013e83e466
diff --git a/packages/views/issues/components/description-preview.test.ts b/packages/views/issues/components/description-preview.test.tsindex ae3326469b..42ea5ccfb3 100644--- a/packages/views/issues/components/description-preview.test.ts+++ b/packages/views/issues/components/description-preview.test.ts@@ -70,4 +70,23 @@ describe("descriptionPreview", () => {"open C:\\Users\\zain to continue",);});++ // The board mounts one preview per card, so an unbounded description makes+ // every card carry text the clamp will never show. (#6633)+ it("bounds a long description before it reaches the DOM", () => {+ const preview = descriptionPreview("a".repeat(600));++ expect(preview).toBe(`${"a".repeat(299)}…`);+ expect(preview).toHaveLength(300);+ });++ it("does not split a Unicode surrogate pair at the preview boundary", () => {+ expect(descriptionPreview(`${"a".repeat(298)}🙂${"b".repeat(300)}`)).toBe(+ `${"a".repeat(298)}…`,+ );+ });++ it("leaves a description at the boundary untouched", () => {+ expect(descriptionPreview("a".repeat(300))).toBe("a".repeat(300));+ });});diff --git a/packages/views/issues/components/description-preview.ts b/packages/views/issues/components/description-preview.tsindex a3812729c1..245ece691f 100644--- a/packages/views/issues/components/description-preview.ts+++ b/packages/views/issues/components/description-preview.ts@@ -1,5 +1,12 @@import { stripChannelMediaMarkers } from "@multica/core/types";+// A preview surface shows one or two clamped lines, but the clamp is CSS:+// the full description still mounts into the DOM and the accessibility+// tree of every card on the board. This ceiling is a DOM-weight bound, not+// a line-width promise — it sits far above what any preview surface can+// display, so the visible text is still decided by the clamp. (#6633)+const PREVIEW_MAX_LENGTH = 300;+/*** Flatten description Markdown into a one-line plain-text preview. Shared by* every surface that shows a description snippet next to an issue.@@ -10,7 +17,7 @@ import { stripChannelMediaMarkers } from "@multica/core/types";* remaining pass and becomes visible preview text.*/export function descriptionPreview(markdown: string): string {- return (+ const preview = (stripChannelMediaMarkers(markdown)// Backslash-escaped punctuation is unescaped first, and the order is// load-bearing. The editor serializes a link as `\[label\](url)`, so the@@ -36,4 +43,16 @@ export function descriptionPreview(markdown: string): string {.replace(/\s+/g, " ").trim());++ if (preview.length <= PREVIEW_MAX_LENGTH) return preview;++ // The ellipsis occupies the last code unit of the budget. Slicing by code+ // unit can land between the two halves of a surrogate pair, which renders as+ // a lone replacement glyph, so an emoji straddling the cut is dropped whole.+ const maxContentLength = PREVIEW_MAX_LENGTH - 1;+ const lastCodeUnit = preview.charCodeAt(maxContentLength - 1);+ const endsOnHighSurrogate = lastCodeUnit >= 0xd800 && lastCodeUnit <= 0xdbff;+ const safeEnd = endsOnHighSurrogate ? maxContentLength - 1 : maxContentLength;++ return `${preview.slice(0, safeEnd).trimEnd()}…`;}