Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(views): keep huge comment bodies from freezing the page (MUL-10197) (#11656)

Bohan Jiangf047cccc7c04
diff --git a/apps/docs/content/docs/comments.fr.mdx b/apps/docs/content/docs/comments.fr.mdx
index 63cb03fcdb..8ce7242afc 100644
--- a/apps/docs/content/docs/comments.fr.mdx
+++ b/apps/docs/content/docs/comments.fr.mdx
@@ -12,7 +12,7 @@ Membres et agents ajoutent du contexte, posent des questions et publient leurs r
## Publier des commentaires et des réponses
-Saisissez votre texte dans la zone Activité de la tâche et envoyez-le pour créer un commentaire. Les commentaires prennent en charge la mise en forme, les blocs de code, les liens et les pièces jointes.
+Saisissez votre texte dans la zone Activité de la tâche et envoyez-le pour créer un commentaire. Les commentaires prennent en charge la mise en forme, les blocs de code, les liens et les pièces jointes. Un texte de plus de 200 000 caractères, comme un journal ou un export JSON collé, n’est pas mis en forme : il s’affiche en texte brut dans un cadre défilant, avec un bouton pour le télécharger en fichier `.txt`.
Un bloc de code `html` ou `mermaid` s’affiche directement sous forme de graphique ou de diagramme, avec un bouton pour voir sa source. Les pièces jointes s’affichent sous forme de cartes qui s’ouvrent dans la visionneuse, y compris les fichiers HTML.
diff --git a/apps/docs/content/docs/comments.ja.mdx b/apps/docs/content/docs/comments.ja.mdx
index f9e39d21e4..9e26262955 100644
--- a/apps/docs/content/docs/comments.ja.mdx
+++ b/apps/docs/content/docs/comments.ja.mdx
@@ -12,7 +12,7 @@ import { ResolveThreadDemo } from "@/components/demos/resolve-thread-demo";
## コメントと返信の投稿
-タスクのアクティビティ欄に入力して送信すると、コメントが作成されます。コメントは書式、コードブロック、リンク、添付ファイルに対応しています。
+タスクのアクティビティ欄に入力して送信すると、コメントが作成されます。コメントは書式、コードブロック、リンク、添付ファイルに対応しています。20 万文字を超えるテキスト(貼り付けたログや JSON エクスポートなど)は書式化されず、スクロールできる枠内にプレーンテキストで表示され、`.txt` ファイルとしてダウンロードできます。
`html` または `mermaid` のコードブロックは、その場でグラフや図として表示され、ソース表示に切り替えられます。添付ファイルはカードとして表示され、ビューアーで開きます。HTML ファイルも同様です。
diff --git a/apps/docs/content/docs/comments.ko.mdx b/apps/docs/content/docs/comments.ko.mdx
index f912d36a35..7510532e23 100644
--- a/apps/docs/content/docs/comments.ko.mdx
+++ b/apps/docs/content/docs/comments.ko.mdx
@@ -12,7 +12,7 @@ import { ResolveThreadDemo } from "@/components/demos/resolve-thread-demo";
## 댓글 작성 및 답글
-태스크의 활동 영역에 내용을 입력하고 보내면 댓글이 만들어집니다. 댓글에는 서식, 코드 블록, 링크, 첨부 파일을 사용할 수 있습니다.
+태스크의 활동 영역에 내용을 입력하고 보내면 댓글이 만들어집니다. 댓글에는 서식, 코드 블록, 링크, 첨부 파일을 사용할 수 있습니다. 20만 자를 넘는 텍스트(붙여 넣은 로그나 JSON 내보내기 등)는 서식을 적용하지 않고 스크롤할 수 있는 상자에 일반 텍스트로 표시하며, `.txt` 파일로 다운로드할 수 있습니다.
`html` 또는 `mermaid` 코드 블록은 댓글 안에서 바로 차트나 다이어그램으로 표시되며, 소스 보기로 전환할 수 있습니다. 첨부 파일은 카드로 표시되고 뷰어에서 열리며, HTML 파일도 마찬가지입니다.
diff --git a/apps/docs/content/docs/comments.mdx b/apps/docs/content/docs/comments.mdx
index 84917296e2..987b3dbcce 100644
--- a/apps/docs/content/docs/comments.mdx
+++ b/apps/docs/content/docs/comments.mdx
@@ -12,7 +12,7 @@ Members and agents add background, ask questions, and post results in the commen
## Post comments and replies
-Type into the issue's activity area and send, and a comment is created. Comments support formatting, code blocks, links, and attachments.
+Type into the issue's activity area and send, and a comment is created. Comments support formatting, code blocks, links, and attachments. Text over 200,000 characters, such as a pasted log or JSON export, is not formatted: it shows as plain text in a scrollable box, with a button to download it as a `.txt` file.
An `html` or `mermaid` code block renders in place as a chart or diagram, with a switch to its source. Attached files show as cards that open in the viewer; that includes HTML files.
diff --git a/apps/docs/content/docs/comments.zh-Hant.mdx b/apps/docs/content/docs/comments.zh-Hant.mdx
index d965460152..0277cbe26b 100644
--- a/apps/docs/content/docs/comments.zh-Hant.mdx
+++ b/apps/docs/content/docs/comments.zh-Hant.mdx
@@ -12,7 +12,7 @@ import { ResolveThreadDemo } from "@/components/demos/resolve-thread-demo";
## 發表評論和回覆
-在任務的動態區輸入內容併傳送,就會建立一條評論。評論支援格式、程式碼塊、連結和附件。
+在任務的動態區輸入內容併傳送,就會建立一條評論。評論支援格式、程式碼塊、連結和附件。超過 20 萬字元的內容(例如貼上的日誌或 JSON 匯出)不做格式化,以純文字顯示在可捲動的框內,並可下載為 `.txt` 檔案。
`html` 或 `mermaid` 程式碼塊會直接在評論裡渲染成圖表或圖示,可以切換檢視原始碼。附件以卡片顯示,點選在檢視器中開啟,HTML 檔案也是如此。
diff --git a/apps/docs/content/docs/comments.zh.mdx b/apps/docs/content/docs/comments.zh.mdx
index 22b1e68eb0..ce5bc7a684 100644
--- a/apps/docs/content/docs/comments.zh.mdx
+++ b/apps/docs/content/docs/comments.zh.mdx
@@ -12,7 +12,7 @@ import { ResolveThreadDemo } from "@/components/demos/resolve-thread-demo";
## 发表评论和回复
-在任务的动态区输入内容并发送,就会创建一条评论。评论支持格式、代码块、链接和附件。
+在任务的动态区输入内容并发送,就会创建一条评论。评论支持格式、代码块、链接和附件。超过 20 万字符的内容(比如粘贴的日志或 JSON 导出)不做格式化,以纯文本显示在可滚动的框里,并可下载为 `.txt` 文件。
`html` 或 `mermaid` 代码块会直接在评论里渲染成图表或图示,可以切换查看源码。附件以卡片显示,点击在查看器中打开,HTML 文件也是如此。
diff --git a/package.json b/package.json
index 889ce520ea..beb7c2d8c5 100644
--- a/package.json
+++ b/package.json
@@ -65,7 +65,8 @@
},
"patchedDependencies": {
"[email protected]": "apps/mobile/patches/[email protected]",
- "@tiptap/[email protected]": "patches/@[email protected]"
+ "@tiptap/[email protected]": "patches/@[email protected]",
}
},
"devDependencies": {
diff --git a/packages/views/issues/utils/timeline-height-estimates.test.ts b/packages/views/issues/utils/timeline-height-estimates.test.ts
index 3a3f2f6015..aa3f1fe399 100644
--- a/packages/views/issues/utils/timeline-height-estimates.test.ts
+++ b/packages/views/issues/utils/timeline-height-estimates.test.ts
@@ -8,6 +8,7 @@ import {
timelineCharsPerLine,
} from "./timeline-height-estimates";
import type { TimelineFolds, TimelineRowItem } from "./timeline-row-content";
+import { MAX_MARKDOWN_CHARS } from "../../rich-content/markdown-limit";
function comment(id: string, content: string, overrides: Partial<TimelineEntry> = {}): TimelineEntry {
return { id, type: "comment", actor_type: "member", actor_id: "user", created_at: "2026-09-07T00:00:00Z", content, ...overrides };
@@ -30,6 +31,13 @@ describe("estimateMarkdownHeight", () => {
expect(estimateMarkdownHeight("| a | b |\n| --- | --- |\n| 1 | 2 |", 80))
.toBe(estimateMarkdownHeight("| a | b |\n| 1 | 2 |", 80));
});
+
+ it("sizes a body too long to format as its bounded plain-text box", () => {
+ const atLimit = estimateMarkdownHeight("x\n".repeat(MAX_MARKDOWN_CHARS / 2), 80);
+ const past = estimateMarkdownHeight("x\n".repeat(MAX_MARKDOWN_CHARS), 80);
+ expect(past).toBeLessThan(1_000);
+ expect(past).toBeLessThan(atLimit);
+ });
});
describe("estimateTimelineItemHeights", () => {
diff --git a/packages/views/issues/utils/timeline-height-estimates.ts b/packages/views/issues/utils/timeline-height-estimates.ts
index 187c543635..616a171f06 100644
--- a/packages/views/issues/utils/timeline-height-estimates.ts
+++ b/packages/views/issues/utils/timeline-height-estimates.ts
@@ -1,6 +1,7 @@
import type { TimelineEntry } from "@multica/core/types";
import type { CommentRun } from "../components/comment-runs";
import { timelineRowContent, type TimelineFolds, type TimelineRowItem } from "./timeline-row-content";
+import { rendersAsPlainText } from "../../rich-content/markdown-limit";
/**
* Estimated rendered height of each timeline row, for Virtuoso's
@@ -40,6 +41,8 @@ const COLLAPSED_THREAD = 70;
const THREAD_FRAME = 30;
const THREAD_ROW = 75;
const RUN_BLOCK = 70;
+/** A body too long to format: its notice line plus the plain-text box, capped at 60vh (~900px viewport). */
+const PLAIN_TEXT_BODY = 560;
/** Characters per rendered line for a timeline in a scroll container `width` px wide. */
export function timelineCharsPerLine(width: number): number {
@@ -51,6 +54,7 @@ const MAX_CACHED = 4_000;
/** Rendered height of a Markdown body, from its lines. Cached per content and width. */
export function estimateMarkdownHeight(markdown: string, charsPerLine: number): number {
+ if (rendersAsPlainText(markdown)) return PLAIN_TEXT_BODY;
const key = `${charsPerLine}:${markdown}`;
const cached = cache.get(key);
if (cached !== undefined) return cached;
diff --git a/packages/views/locales/en/editor.json b/packages/views/locales/en/editor.json
index edf207f7fe..962031aebf 100644
--- a/packages/views/locales/en/editor.json
+++ b/packages/views/locales/en/editor.json
@@ -259,5 +259,9 @@
"turn_into": "Turn into",
"duplicate": "Duplicate",
"delete": "Delete"
+ },
+ "plain_text": {
+ "notice": "Too long to format, shown as plain text.",
+ "download": "Download as .txt"
}
}
diff --git a/packages/views/locales/es/editor.json b/packages/views/locales/es/editor.json
index 000d72c9f5..6444e177a7 100644
--- a/packages/views/locales/es/editor.json
+++ b/packages/views/locales/es/editor.json
@@ -259,5 +259,9 @@
"turn_into": "Convertir en",
"duplicate": "Duplicar",
"delete": "Eliminar"
+ },
+ "plain_text": {
+ "notice": "Demasiado largo para darle formato; se muestra como texto sin formato.",
+ "download": "Descargar como .txt"
}
}
diff --git a/packages/views/locales/fr/editor.json b/packages/views/locales/fr/editor.json
index 3742cee3a4..46db48ca46 100644
--- a/packages/views/locales/fr/editor.json
+++ b/packages/views/locales/fr/editor.json
@@ -259,5 +259,9 @@
"turn_into": "Transformer en",
"duplicate": "Dupliquer",
"delete": "Supprimer"
+ },
+ "plain_text": {
+ "notice": "Trop long pour être mis en forme, affiché en texte brut.",
+ "download": "Télécharger en .txt"
}
}
diff --git a/packages/views/locales/ja/editor.json b/packages/views/locales/ja/editor.json
index 4384ff703a..8595fce3c1 100644
--- a/packages/views/locales/ja/editor.json
+++ b/packages/views/locales/ja/editor.json
@@ -255,5 +255,9 @@
"turn_into": "変換",
"duplicate": "複製",
"delete": "削除"
+ },
+ "plain_text": {
+ "notice": "長すぎるため、プレーンテキストで表示しています。",
+ "download": ".txt でダウンロード"
}
}
diff --git a/packages/views/locales/ko/editor.json b/packages/views/locales/ko/editor.json
index 92a94d0db4..3f7b367871 100644
--- a/packages/views/locales/ko/editor.json
+++ b/packages/views/locales/ko/editor.json
@@ -255,5 +255,9 @@
"turn_into": "변환",
"duplicate": "복제",
"delete": "삭제"
+ },
+ "plain_text": {
+ "notice": "내용이 너무 길어 일반 텍스트로 표시합니다.",
+ "download": ".txt로 다운로드"
}
}
diff --git a/packages/views/locales/ru/editor.json b/packages/views/locales/ru/editor.json
index 06ea1ce36a..6274925100 100644
--- a/packages/views/locales/ru/editor.json
+++ b/packages/views/locales/ru/editor.json
@@ -267,5 +267,9 @@
"turn_into": "Преобразовать в",
"duplicate": "Дублировать",
"delete": "Удалить"
+ },
+ "plain_text": {
+ "notice": "Слишком длинный текст для форматирования, показан как обычный текст.",
+ "download": "Скачать как .txt"
}
}
diff --git a/packages/views/locales/zh-Hans/editor.json b/packages/views/locales/zh-Hans/editor.json
index c21cff1871..c0b236bfb6 100644
--- a/packages/views/locales/zh-Hans/editor.json
+++ b/packages/views/locales/zh-Hans/editor.json
@@ -255,5 +255,9 @@
"turn_into": "转换为",
"duplicate": "创建副本",
"delete": "删除"
+ },
+ "plain_text": {
+ "notice": "内容过长,以纯文本显示。",
+ "download": "下载为 .txt"
}
}
diff --git a/packages/views/locales/zh-Hant/editor.json b/packages/views/locales/zh-Hant/editor.json
index 1951425a30..7d4107880f 100644
--- a/packages/views/locales/zh-Hant/editor.json
+++ b/packages/views/locales/zh-Hant/editor.json
@@ -255,5 +255,9 @@
"turn_into": "轉換為",
"duplicate": "建立副本",
"delete": "刪除"
+ },
+ "plain_text": {
+ "notice": "內容過長,以純文字顯示。",
+ "download": "下載為 .txt"
}
}
diff --git a/packages/views/rich-content/markdown-limit.ts b/packages/views/rich-content/markdown-limit.ts
new file mode 100644
index 0000000000..0a55e37d1f
--- /dev/null
+++ b/packages/views/rich-content/markdown-limit.ts
@@ -0,0 +1,19 @@
+/**
+ * Content longer than this renders as plain text instead of Markdown (#11547).
+ *
+ * Formatting time is not linear in the length of one paragraph: GFM's
+ * autolink-literal extension rescans the paragraph as it goes, so a pasted log
+ * or JSON export of a megabyte takes several seconds to parse and freezes
+ * whatever surface shows it, even with our patch for its worst case
+ * (`patches/[email protected]`). Below this
+ * size every shape we measured (prose, logs, single-line JSON) parses in about
+ * 100 ms. Bodies past it are dumps, which read no worse as text.
+ *
+ * Kept apart from the renderer so data-only code (timeline height estimates)
+ * can apply the same rule without importing it.
+ */
+export const MAX_MARKDOWN_CHARS = 200_000;
+
+export function rendersAsPlainText(content: string): boolean {
+ return content.length > MAX_MARKDOWN_CHARS;
+}
diff --git a/packages/views/rich-content/rich-content-long-content.test.tsx b/packages/views/rich-content/rich-content-long-content.test.tsx
new file mode 100644
index 0000000000..7e29ea3b59
--- /dev/null
+++ b/packages/views/rich-content/rich-content-long-content.test.tsx
@@ -0,0 +1,146 @@
+/**
+ * Long bodies (#11547): a pasted log or JSON export must not freeze the
+ * surface that shows it. Past the Markdown limit the body is plain text and
+ * never parsed; below it, the patched GFM autolink-literal extension keeps a
+ * long paragraph that opens with an unclosed `[` linear, and still links what
+ * it linked before.
+ */
+import { describe, expect, it, vi } from "vitest";
+import { fireEvent, render, screen } from "@testing-library/react";
+import ReactMarkdown from "react-markdown";
+vi.mock("../issues/hooks", () => ({
+ useResolveIssueIdentifier: () => null,
+}));
+
+vi.mock("../i18n", async () => {
+ const editor = (await import("../locales/en/editor.json")).default;
+ return {
+ useT: () => ({
+ t: (select: (bundle: typeof editor) => string) => select(editor),
+ }),
+ useTimeAgo: () => "just now",
+ };
+});
+
+vi.mock("@multica/core/api", () => ({
+ api: { getAttachmentTextContent: vi.fn() },
+ PreviewTooLargeError: class extends Error {},
+ PreviewUnsupportedError: class extends Error {},
+}));
+
+vi.mock("@multica/core/paths", () => ({
+ useWorkspacePaths: () => ({
+ issueDetail: (id: string) => `/acme/issues/${id}`,
+ projectDetail: (id: string) => `/acme/projects/${id}`,
+ }),
+ useWorkspaceSlug: () => "acme",
+}));
+
+vi.mock("../navigation", () => ({
+ useNavigation: () => ({ push: vi.fn(), openInNewTab: vi.fn() }),
+ useOptionalNavigation: () => ({ push: vi.fn(), openInNewTab: vi.fn() }),
+ resolveClickIntent: () => "push",
+ useAppOrigin: () => null,
+ AppLink: ({ href, children }: { href: string; children: React.ReactNode }) => (
+ <a href={href}>{children}</a>
+ ),
+}));
+
+vi.mock("../issues/components/issue-mention-card", () => ({
+ IssueMentionCard: ({ issueId }: { issueId: string }) => <span>{issueId}</span>,
+}));
+
+vi.mock("../projects/components/project-chip", () => ({
+ ProjectChip: ({ projectId }: { projectId: string }) => <span>{projectId}</span>,
+}));
+
+vi.mock("../editor/link-hover-card", () => ({
+ useLinkHover: () => ({}),
+ LinkHoverCard: () => null,
+}));
+
+// Surface what the file-card renderer received, so the assertion is about the
+// emitted attachment rather than incidental chrome.
+vi.mock("../editor/attachment", () => ({
+ Attachment: ({ attachment }: { attachment: { url: string; filename: string } }) => (
+ <span data-testid="file-card" data-url={attachment.url}>
+ {attachment.filename}
+ </span>
+ ),
+}));
+
+vi.mock("react-markdown", async (importOriginal) => {
+ const actual = await importOriginal<typeof import("react-markdown")>();
+ return { ...actual, default: vi.fn(actual.default) };
+});
+
+const downloadBlob = vi.hoisted(() => vi.fn());
+vi.mock("../editor/utils/mermaid-export", () => ({ downloadBlob }));
+
+import { RichContent } from "./rich-content";
+import { MAX_MARKDOWN_CHARS } from "./markdown-limit";
+
+const parses = () => vi.mocked(ReactMarkdown).mock.calls.length;
+
+/** A JSON export on one line: one paragraph that opens with an unclosed `[`. */
+function jsonExport(chars: number): string {
+ const rows: string[] = [];
+ let length = 2;
+ for (let i = 0; length < chars; i++) {
+ const row = JSON.stringify({ id: i, title: `Row ${i}: when the page loads, see https://example.com/${i} or write to [email protected]`, labels: ["perf", `area-${i % 9}`] });
+ rows.push(row);
+ length += row.length + 1;
+ }
+ return `[${rows.join(",")}]`;
+}
+
+describe("RichContent past the Markdown limit", () => {
+ const huge = `# Not a heading\n\n**not bold** ${"x".repeat(MAX_MARKDOWN_CHARS)}`;
+
+ it("shows the raw text without parsing it", () => {
+ const before = parses();
+ const { container } = render(<RichContent content={huge} />);
+
+ expect(parses()).toBe(before);
+ expect(screen.getByTestId("rich-content-plain-text").textContent).toBe(huge);
+ expect(container.querySelector("h1, strong")).toBeNull();
+ expect(screen.getByText("Too long to format, shown as plain text.")).toBeTruthy();
+ });
+
+ it("downloads the full text", () => {
+ render(<RichContent content={huge} />);
+ fireEvent.click(screen.getByRole("button", { name: "Download as .txt" }));
+
+ expect(downloadBlob).toHaveBeenCalledTimes(1);
+ const [blob, filename] = downloadBlob.mock.calls[0]!;
+ expect((blob as Blob).size).toBe(huge.length);
+ expect(filename).toBe("content.txt");
+ });
+
+ it("formats content at the limit as Markdown", () => {
+ const content = `**bold** ${"x".repeat(MAX_MARKDOWN_CHARS - 9)}`;
+ const { container } = render(<RichContent content={content} />);
+
+ expect(screen.queryByTestId("rich-content-plain-text")).toBeNull();
+ expect(container.querySelector("strong")?.textContent).toBe("bold");
+ });
+});
+
+describe("GFM autolink literals in a long paragraph", () => {
+ it("formats a JSON export below the limit without rescanning the paragraph", () => {
+ // Unpatched, a 150k-character export takes seconds here (quadratic);
+ // patched, well under a second. The bound leaves room for slow CI.
+ const content = jsonExport(150_000);
+ const start = performance.now();
+ render(<RichContent content={content} />);
+
+ expect(performance.now() - start).toBeLessThan(2_000);
+ });
+
+ it("still links a URL that follows a label which became a link", () => {
+ const { container } = render(<RichContent content="[(b)](https://e.com)https://example.com/a" />);
+ const hrefs = [...container.querySelectorAll("a")].map((a) => a.getAttribute("href"));
+
+ expect(hrefs).toEqual(["https://e.com", "https://example.com/a"]);
+ });
+});
diff --git a/packages/views/rich-content/rich-content.tsx b/packages/views/rich-content/rich-content.tsx
index d1559ef392..ce9ada3788 100644
--- a/packages/views/rich-content/rich-content.tsx
+++ b/packages/views/rich-content/rich-content.tsx
@@ -83,6 +83,10 @@ import {
} from "./rich-code-block";
import { RichTable, RichTableSourceContext } from "./rich-table";
import { getTextContent } from "./rich-table-model";
+import { rendersAsPlainText } from "./markdown-limit";
+import { downloadBlob } from "../editor/utils/mermaid-export";
+import { useT } from "../i18n";
+import { Download } from "@multica/ui/icons";
import "katex/dist/katex.min.css";
import "../editor/styles/index.css";
import "./rich-content.css";
@@ -599,13 +603,58 @@ export interface RichContentProps {
className?: string;
}
-export const RichContent = memo(function RichContent({
- content,
- attachments,
- density = "document",
- phase = "settled",
- className,
-}: RichContentProps) {
+export const RichContent = memo(function RichContent(props: RichContentProps) {
+ return rendersAsPlainText(props.content) ? <PlainTextContent {...props} /> : <MarkdownContent {...props} />;
+});
+
+/** The wrapper both renderings share: density, phase and the readonly styles. */
+function contentWrapperProps({ density = "document", phase = "settled", className }: RichContentProps) {
+ return {
+ "data-rich-content": "",
+ "data-mc": "content",
+ "data-density": density,
+ "data-phase": phase,
+ className: cn(
+ "rich-text-editor readonly text-body",
+ density === "compact" && "rich-content-compact",
+ className,
+ ),
+ };
+}
+
+/**
+ * A body too long to format (see `./markdown-limit`), shown as its raw text in
+ * a bounded, scrollable code block so it neither freezes the page nor makes it
+ * thousands of screens tall.
+ */
+function PlainTextContent(props: RichContentProps) {
+ const { content } = props;
+ const { t } = useT("editor");
+ return (
+ <div {...contentWrapperProps(props)}>
+ <div
+ data-find-ignore
+ className="flex flex-wrap items-center gap-x-3 gap-y-1 text-caption text-muted-foreground"
+ >
+ <span>{t(($) => $.plain_text.notice)}</span>
+ <button
+ type="button"
+ onClick={() => downloadBlob(new Blob([content], { type: "text/plain;charset=utf-8" }), "content.txt")}
+ className="flex items-center gap-1 transition-colors hover:text-foreground"
+ >
+ <Download className="size-3 shrink-0" />
+ {t(($) => $.plain_text.download)}
+ </button>
+ </div>
+ <pre data-testid="rich-content-plain-text" className="max-h-[60vh] overflow-y-auto [overflow-wrap:anywhere]">
+ <code>{content}</code>
+ </pre>
+ </div>
+ );
+}
+
+function MarkdownContent(props: RichContentProps) {
+ const { content, attachments, phase = "settled" } = props;
// Subscribed, not read once. The CDN config is fetched asynchronously after
// auth, so content that renders first would otherwise keep its legacy CDN
// links as plain anchors permanently — the preprocess step that turns them
@@ -644,21 +693,10 @@ export const RichContent = memo(function RichContent({
return (
<AttachmentDownloadProvider attachments={attachments}>
- <div
- ref={wrapperRef}
- data-rich-content=""
- data-mc="content"
- data-density={density}
- data-phase={phase}
- className={cn(
- "rich-text-editor readonly text-body",
- density === "compact" && "rich-content-compact",
- className,
- )}
- >
+ <div ref={wrapperRef} {...contentWrapperProps(props)}>
{markdown}
<LinkHoverCard {...hover} />
</div>
</AttachmentDownloadProvider>
);
-});
+}
diff --git a/patches/[email protected] b/patches/[email protected]
new file mode 100644
index 0000000000..c652e59e08
--- /dev/null
+++ b/patches/[email protected]
@@ -0,0 +1,117 @@
+diff --git a/dev/index.d.ts b/dev/index.d.ts
+index 36f53b55bf7d7494d1ed6a8b21564825e385142f..f98ac643bf744ad71c006205b33d4c6230cfa8a6 100644
+--- a/dev/index.d.ts
++++ b/dev/index.d.ts
+@@ -6,10 +6,14 @@ export {gfmAutolinkLiteralHtml} from './lib/html.js'
+ */
+ declare module 'micromark-util-types' {
+ /**
+- * Augment token with a field to improve performance.
++ * Augment token with fields to improve performance.
+ */
+ interface Token {
+ _gfmAutolinkLiteralWalkedInto?: boolean
++ _gfmAutolinkLiteralSkipTo?: {
++ index: number
++ token: Token
++ }
+ }
+
+ /**
+diff --git a/dev/lib/syntax.js b/dev/lib/syntax.js
+index 904e27200ae4980183beda525d33feef70c2e7f7..e37da95b897fcc8d1c6a8bdbc8a5b79462a92812 100644
+--- a/dev/lib/syntax.js
++++ b/dev/lib/syntax.js
+@@ -971,12 +971,32 @@ function previousUnbalanced(events) {
+ result = false
+ break
+ }
++
++ // Resume at a previously found unbalanced label if that event still holds
++ // the same token. `_balanced` is not enough: a label that becomes a link
++ // keeps `_balanced === false` while its events are spliced out.
++ const skip = token._gfmAutolinkLiteralSkipTo
++ if (
++ skip !== undefined &&
++ skip.index < index &&
++ events[skip.index] !== undefined &&
++ events[skip.index][1] === skip.token
++ ) {
++ index = skip.index + 1
++ }
+ }
+
+- if (events.length > 0 && !result) {
+- // Mark the last token as “walked into” w/o finding
+- // anything.
+- events[events.length - 1][1]._gfmAutolinkLiteralWalkedInto = true
++ if (events.length > 0) {
++ if (!result) {
++ // Mark the last token as “walked into” w/o finding
++ // anything.
++ events[events.length - 1][1]._gfmAutolinkLiteralWalkedInto = true
++ } else if (index >= 0) {
++ events[events.length - 1][1]._gfmAutolinkLiteralSkipTo = {
++ index,
++ token: events[index][1]
++ }
++ }
+ }
+
+ return result
+diff --git a/index.d.ts b/index.d.ts
+index 36f53b55bf7d7494d1ed6a8b21564825e385142f..f98ac643bf744ad71c006205b33d4c6230cfa8a6 100644
+--- a/index.d.ts
++++ b/index.d.ts
+@@ -6,10 +6,14 @@ export {gfmAutolinkLiteralHtml} from './lib/html.js'
+ */
+ declare module 'micromark-util-types' {
+ /**
+- * Augment token with a field to improve performance.
++ * Augment token with fields to improve performance.
+ */
+ interface Token {
+ _gfmAutolinkLiteralWalkedInto?: boolean
++ _gfmAutolinkLiteralSkipTo?: {
++ index: number
++ token: Token
++ }
+ }
+
+ /**
+diff --git a/lib/syntax.js b/lib/syntax.js
+index dffbaf15146b34d3b3f634286629ccb148866f4c..d8b39e6e2649198c91ca614742e55aa0b134565a 100644
+--- a/lib/syntax.js
++++ b/lib/syntax.js
+@@ -844,11 +844,26 @@ function previousUnbalanced(events) {
+ result = false;
+ break;
+ }
++
++ // Resume at a previously found unbalanced label if that event still holds
++ // the same token. `_balanced` is not enough: a label that becomes a link
++ // keeps `_balanced === false` while its events are spliced out.
++ const skip = token._gfmAutolinkLiteralSkipTo;
++ if (skip !== undefined && skip.index < index && events[skip.index] !== undefined && events[skip.index][1] === skip.token) {
++ index = skip.index + 1;
++ }
+ }
+- if (events.length > 0 && !result) {
+- // Mark the last token as “walked into” w/o finding
+- // anything.
+- events[events.length - 1][1]._gfmAutolinkLiteralWalkedInto = true;
++ if (events.length > 0) {
++ if (!result) {
++ // Mark the last token as “walked into” w/o finding
++ // anything.
++ events[events.length - 1][1]._gfmAutolinkLiteralWalkedInto = true;
++ } else if (index >= 0) {
++ events[events.length - 1][1]._gfmAutolinkLiteralSkipTo = {
++ index,
++ token: events[index][1]
++ };
++ }
+ }
+ return result;
+ }
+\ No newline at end of file
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 918aba1c6a..4dc93ccad6 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -231,6 +231,9 @@ patchedDependencies:
hash: 52e0bb7a9afc2d62b773afaf938f3be85fde749ce4047635e71547c1ba8cde0e
path: apps/mobile/patches/[email protected]
+ hash: 20676bd882c25278e01dfb34676096201fab3bc6682ec1a65f62c021d84889c6
+ path: patches/[email protected]
importers:
@@ -21761,7 +21764,7 @@ snapshots:
optionalDependencies:
micromark-util-types: 2.0.2
+ [email protected](patch_hash=20676bd882c25278e01dfb34676096201fab3bc6682ec1a65f62c021d84889c6):
dependencies:
micromark-util-character: 2.1.1
micromark-util-sanitize-uri: 2.0.1
@@ -21818,7 +21821,7 @@ snapshots:
dependencies:
- micromark-extension-gfm-autolink-literal: 2.1.0
+ micromark-extension-gfm-autolink-literal: 2.1.0(patch_hash=20676bd882c25278e01dfb34676096201fab3bc6682ec1a65f62c021d84889c6)
micromark-extension-gfm-footnote: 2.1.0
micromark-extension-gfm-strikethrough: 2.1.0
micromark-extension-gfm-table: 2.1.1