The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 14:45 UTC
fix(web): show repeated table rows and cells in ODT previews (#36689)
Wout Stiens committed
Nov 14, 2026 at 12:47 UTC
6effe74c59544b8b7971253d3c4f1522d0a365c0
6 files changed
+95
-17
apps/web/src/components/files/FilePreviewPanel.test.ts
+23
@@ -407,6 +407,29 @@ Third}`;
407
},
408
);
409
410
+ const approved = "<text:p>Approved <text:span>now</text:span></text:p>";
411
+ const approvedRow = `<tr>${"<td><p>Approved <span>now</span></p></td>".repeat(2)}</tr>`;
412
+ it.each([
413
+ [
414
+ "expands",
415
+ `<table:table-row>${`<table:table-cell>${approved}</table:table-cell>`.repeat(2)}</table:table-row><table:table-row table:number-rows-repeated="2"><table:table-cell table:number-columns-repeated="2">${approved}</table:table-cell></table:table-row>`,
416
+ approvedRow.repeat(3),
417
+ ],
418
+ [
419
+ "bounds",
420
+ '<table:table-row table:number-rows-repeated="999999999"><table:table-cell table:number-columns-repeated="999999999"><text:p>x</text:p></table:table-cell></table:table-row>',
421
+ `<tr>${"<td><p>x</p></td>".repeat(50)}</tr>`.repeat(500),
422
+ ],
423
+ ])("%s repeated ODT table rows and cells", async (_, rows, html) => {
424
+ const archive = new JSZip().file(
425
+ "content.xml",
426
+ `<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"><office:body><office:text><table:table><table:table-column table:number-columns-repeated="2"/>${rows}</table:table></office:text></office:body></office:document-content>`,
427
+ );
428
+ const result = await openDocument(archive, "odt");
429
+ if (result.type !== "document") throw new Error("Expected document");
430
+ expect(result.pages[0]!.html).toBe(`<table>${html}</table>`);
431
+ });
432
+
433
it.each(["odt", "odp"] as const)("reads %s text and rejects XML entities", async (kind) => {
434
const archive = new JSZip().file(
435
"content.xml",
apps/web/src/components/files/extendedDocumentPreview.ts
+21
-14
@@ -9,8 +9,8 @@ import type JSZip from "jszip";
9
10
import { type OfficeWorkerResult, type NotebookCell } from "./officePreviewProtocol";
11
12
-const ODS_PREVIEW_MAX_ROWS = 500;
13
-const ODS_PREVIEW_MAX_COLUMNS = 50;
12
+const TABLE_PREVIEW_MAX_ROWS = 500;
13
+const TABLE_PREVIEW_MAX_COLUMNS = 50;
14
15
// `text` and `attrs` hold decoded values: escaped text is decoded once, CDATA stays literal.
16
type XmlNode = { name: string; attrs: Record<string, string>; children: XmlNode[]; text: string };
@@ -295,13 +295,20 @@ async function odfHtml(node: XmlNode, archive: JSZip): Promise<string> {
295
};
296
const tag = tags[node.name];
297
if (!tag) return children;
298
- reserveMarkup(tag.length * 2 + 5);
299
- return `<${tag}>${children}</${tag}>`;
298
+ const count =
299
+ tag === "tr"
300
+ ? repeat(node.attrs["table:number-rows-repeated"], TABLE_PREVIEW_MAX_ROWS)
301
+ : tag === "td"
302
+ ? repeat(node.attrs["table:number-columns-repeated"], TABLE_PREVIEW_MAX_COLUMNS)
303
+ : 1;
304
+ const markup = `<${tag}>${children}</${tag}>`;
305
+ reserveMarkup(count * markup.length - children.length);
306
+ return markup.repeat(count);
307
}
308
function repeat(value: string | undefined, max: number) {
309
const count = Number(value ?? 1);
310
if (!Number.isSafeInteger(count) || count < 1)
304
- throw new Error("This spreadsheet contains invalid repeated cells.");
311
+ throw new Error("This document contains invalid repeated content.");
312
return Math.min(count, max);
313
}
314
export async function openDocument(
@@ -337,29 +344,29 @@ export async function openDocument(
344
"";
345
const count = repeat(
346
cell.attrs["table:number-columns-repeated"],
340
- ODS_PREVIEW_MAX_COLUMNS + 1,
347
+ TABLE_PREVIEW_MAX_COLUMNS + 1,
348
);
342
- if (value && cells.length + count > ODS_PREVIEW_MAX_COLUMNS) truncated = true;
343
- for (let i = 0; i < count && cells.length < ODS_PREVIEW_MAX_COLUMNS; i++) {
349
+ if (value && cells.length + count > TABLE_PREVIEW_MAX_COLUMNS) truncated = true;
350
+ for (let i = 0; i < count && cells.length < TABLE_PREVIEW_MAX_COLUMNS; i++) {
351
if (value.length > 10_000)
352
throw new Error("A spreadsheet cell is too large to preview.");
353
cells.push(value);
354
}
355
}
356
while (cells.at(-1) === "") cells.pop();
350
- const count = repeat(row.attrs["table:number-rows-repeated"], ODS_PREVIEW_MAX_ROWS + 1);
357
+ const count = repeat(row.attrs["table:number-rows-repeated"], TABLE_PREVIEW_MAX_ROWS + 1);
358
if (!cells.length) {
352
- pendingEmptyRows = Math.min(ODS_PREVIEW_MAX_ROWS + 1, pendingEmptyRows + count);
359
+ pendingEmptyRows = Math.min(TABLE_PREVIEW_MAX_ROWS + 1, pendingEmptyRows + count);
360
continue;
361
}
355
- while (pendingEmptyRows > 0 && rows.length < ODS_PREVIEW_MAX_ROWS) {
362
+ while (pendingEmptyRows > 0 && rows.length < TABLE_PREVIEW_MAX_ROWS) {
363
rows.push([]);
364
pendingEmptyRows--;
365
}
366
pendingEmptyRows = 0;
360
- if (rows.length + count > ODS_PREVIEW_MAX_ROWS) truncated = true;
361
- if (rows.length >= ODS_PREVIEW_MAX_ROWS) break;
362
- for (let i = 0; i < count && rows.length < ODS_PREVIEW_MAX_ROWS; i++) {
367
+ if (rows.length + count > TABLE_PREVIEW_MAX_ROWS) truncated = true;
368
+ if (rows.length >= TABLE_PREVIEW_MAX_ROWS) break;
369
+ for (let i = 0; i < count && rows.length < TABLE_PREVIEW_MAX_ROWS; i++) {
370
cellBytes += cells.reduce((size, cell) => size + cell.length, 0);
371
if (cellBytes > 8 * 1024 * 1024)
372
throw new Error("This spreadsheet has too much text to preview.");
pnpm-lock.yaml
+3
@@ -2569,6 +2569,9 @@ importers:
2569
esbuild:
2570
specifier: 0.28.2
2571
version: 0.28.2
2572
+ jszip:
2573
+ specifier: 3.10.1
2574
+ version: 3.10.1
2575
postject:
2576
specifier: 1.0.0-alpha.6
2577
version: 1.0.0-alpha.6
scripts/package.json
+1
@@ -29,6 +29,7 @@
29
"@types/plist": "catalog:",
30
"@types/pngjs": "6.0.5",
31
"esbuild": "0.28.2",
32
+ "jszip": "3.10.1",
33
"postject": "1.0.0-alpha.6",
34
"typescript-legacy": "npm:typescript@~6.0.3",
35
"vite-plus": "catalog:"
scripts/scenarios/odt-preview-expands-repeated-table-cells.e2e.ts
new
+39
@@ -0,0 +1,39 @@
1
+import { expect } from "e2e";
2
+import JSZip from "jszip";
3
+
4
+import { test, WEB } from "./t3.ts";
5
+
6
+// A 2 by 2 table stored the compact way ODF allows: one row repeated twice, one cell repeated twice.
7
+async function repeatedTableOdt() {
8
+ const cell =
9
+ '<table:table-cell table:number-columns-repeated="2"><text:p>Approved</text:p></table:table-cell>';
10
+ return new JSZip()
11
+ .file("mimetype", "application/vnd.oasis.opendocument.text", { compression: "STORE" })
12
+ .file(
13
+ "content.xml",
14
+ `<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" office:version="1.3"><office:body><office:text><table:table table:name="Decisions"><table:table-column table:number-columns-repeated="2"/><table:table-row table:number-rows-repeated="2">${cell}</table:table-row></table:table></office:text></office:body></office:document-content>`,
15
+ )
16
+ .generateAsync({ type: "uint8array" });
17
+}
18
+
19
+test(
20
+ "An ODT preview shows every cell of a table stored with repeated rows and cells",
21
+ WEB,
22
+ async ({ t3, app, screen, browser }) => {
23
+ const project = await t3.project("demo", { "decisions.odt": await repeatedTableOdt() });
24
+ const thread = await t3.thread({ project, title: "Review decisions", messages: ["Start"] });
25
+ await t3.open(thread);
26
+ await expect(screen.getByText("fixture turn complete", { exact: false })).toBeVisible();
27
+
28
+ await browser.keyboard.press("Control+p");
29
+ await screen.getByPlaceholder("Search files…").fill("decisions.odt");
30
+ await screen.getByRole("option", "decisions.odt", { exact: false }).tap();
31
+
32
+ // The first document preview loads its worker, which a cold Vite cache optimizes on demand.
33
+ await expect(screen.getByText("1 page", { exact: false })).toBeVisible({ timeout: 120_000 });
34
+ const document = browser.frameLocator('iframe[title^="decisions.odt"]');
35
+ await expect(document.getByRole("cell", "Approved").first()).toBeVisible();
36
+ await app.screenshot("table");
37
+ await expect(document.getByRole("cell", "Approved")).toHaveCount(4);
38
+ },
39
+);
scripts/scenarios/t3.ts
+8
-3
@@ -15,7 +15,10 @@ import { run } from "./shell.ts";
15
16
export interface T3State {
17
/** Creates a git repository holding `files` and adds it as a project. Returns its path. */
18
- readonly project: (title: string, files?: Readonly<Record<string, string>>) => Promise<string>;
18
+ readonly project: (
19
+ title: string,
20
+ files?: Readonly<Record<string, string | Uint8Array>>,
21
+ ) => Promise<string>;
22
/**
23
* Starts a thread in a project and plays one replayed turn per message before returning.
24
* `model` is a dev replay recording: showcase, todo-list, approval, question, multi-turn.
@@ -69,7 +72,7 @@ export function makeState(home: string, env: NodeJS.ProcessEnv = {}) {
72
73
const project = Effect.fn("scenario.project")(function* (
74
title: string,
72
- files: Readonly<Record<string, string>>,
75
+ files: Readonly<Record<string, string | Uint8Array>>,
76
) {
77
const fs = yield* FileSystem.FileSystem;
78
const path = yield* Path.Path;
@@ -82,7 +85,9 @@ export function makeState(home: string, env: NodeJS.ProcessEnv = {}) {
85
const workspace = path.join(parent, title);
86
for (const [file, content] of Object.entries({ "README.md": "", ...files })) {
87
yield* fs.makeDirectory(path.dirname(path.join(workspace, file)), { recursive: true });
85
- yield* fs.writeFileString(path.join(workspace, file), content);
88
+ yield* typeof content === "string"
89
+ ? fs.writeFileString(path.join(workspace, file), content)
90
+ : fs.writeFile(path.join(workspace, file), content);
91
}
92
const git = (args: ReadonlyArray<string>) => run("git", args, { cwd: workspace });
93
const author = ["-c", "user.name=Scenario", "-c", "user.email=scenario@example.invalid"];