Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(desktop): mobile preserve ordered list start values (#81110)

Tom Owers29583427b6a4
diff --git a/products/desktop/apps/mobile/src/features/chat/components/MarkdownText.test.tsx b/products/desktop/apps/mobile/src/features/chat/components/MarkdownText.test.tsx
new file mode 100644
index 000000000000..2e6a89850377
--- /dev/null
+++ b/products/desktop/apps/mobile/src/features/chat/components/MarkdownText.test.tsx
@@ -0,0 +1,58 @@
+import { createElement } from "react";
+import { act, create } from "react-test-renderer";
+import { describe, expect, it, vi } from "vitest";
+import { MarkdownText } from "./MarkdownText";
+
+vi.mock("./CopyButton", () => ({ CopyButton: () => null }));
+
+vi.mock("@/features/auth", () => ({
+ useAuthStore: (selector: (state: { cloudRegion: null }) => unknown) =>
+ selector({ cloudRegion: null }),
+ getCloudUrlFromRegion: () => null,
+}));
+
+function renderTree(content: string): string {
+ let renderer: ReturnType<typeof create> | null = null;
+ act(() => {
+ renderer = create(createElement(MarkdownText, { content }));
+ });
+ if (!renderer) throw new Error("Renderer not created");
+ return JSON.stringify((renderer as ReturnType<typeof create>).toJSON());
+}
+
+describe("MarkdownText", () => {
+ it.each([
+ {
+ name: "ordered list starting at 1",
+ content: "1. Alpha\n2. Beta\n3. Gamma",
+ present: ["1.", "2.", "3."],
+ absent: ["•"],
+ },
+ {
+ name: "ordered list starting above 1 preserves the source numbers",
+ content: "3. Alpha\n4. Beta\n5. Gamma",
+ present: ["3.", "4.", "5."],
+ absent: ["1.", "2."],
+ },
+ {
+ name: "unordered list uses bullets",
+ content: "- Alpha\n- Beta",
+ present: ["•"],
+ absent: ["1."],
+ },
+ {
+ name: "task list uses checkboxes",
+ content: "- [ ] Alpha\n- [x] Beta",
+ present: ["☐", "☑"],
+ absent: ["•", "1."],
+ },
+ ])("$name", ({ content, present, absent }) => {
+ const tree = renderTree(content);
+ for (const marker of present) {
+ expect(tree).toContain(marker);
+ }
+ for (const marker of absent) {
+ expect(tree).not.toContain(marker);
+ }
+ });
+});
diff --git a/products/desktop/apps/mobile/src/features/chat/components/MarkdownText.tsx b/products/desktop/apps/mobile/src/features/chat/components/MarkdownText.tsx
index 4b569a357ff1..b12b4a386620 100644
--- a/products/desktop/apps/mobile/src/features/chat/components/MarkdownText.tsx
+++ b/products/desktop/apps/mobile/src/features/chat/components/MarkdownText.tsx
@@ -77,6 +77,7 @@ interface Block {
level?: number;
items?: string[];
ordered?: boolean;
+ start?: number;
rows?: string[][];
url?: string;
alt?: string;
@@ -159,13 +160,20 @@ function parseBlocks(text: string): Block[] {
}
// Ordered list (consecutive 1. 2. lines)
- if (/^\s*\d+[.)]\s/.test(line)) {
+ const orderedMatch = line.match(/^\s*(\d+)[.)]\s/);
+ if (orderedMatch) {
const items: string[] = [];
while (i < lines.length && /^\s*\d+[.)]\s/.test(lines[i])) {
items.push(lines[i].replace(/^\s*\d+[.)]\s+/, ""));
i++;
}
- blocks.push({ type: "list", content: "", items, ordered: true });
+ blocks.push({
+ type: "list",
+ content: "",
+ items,
+ ordered: true,
+ start: Number(orderedMatch[1]),
+ });
continue;
}
@@ -519,7 +527,7 @@ export function MarkdownText({
</Text>
) : (
<Text className="mr-2 text-[13px] text-gray-9">
- {block.ordered ? `${idx + 1}.` : "•"}
+ {block.ordered ? `${(block.start ?? 1) + idx}.` : "•"}
</Text>
)}
<Text