Skip to content

Handle invalid table widths in DOCX and PDF export - #3465

Open
yucheng-du wants to merge 1 commit into
TypeCellOS:mainfrom
yucheng-du:fix/export-table-widths
Open

yucheng-du wants to merge 1 commit into
TypeCellOS:mainfrom
yucheng-du:fix/export-table-widths

Conversation

@yucheng-du

@yucheng-du yucheng-du commented Dec 2, 2026 •

Copy link
Copy Markdown

Summary

Fixes #3433. A table supplied directly to an exporter can contain a missing or invalid column width. DOCX export threw on NaN and infinity. The default PDF exporter already handled NaN, but infinity and sparse arrays produced invalid Typst and stopped the download.

Changes

  • Use the existing missing-width fallback for non-finite and negative values. Preserve valid widths and each exporter's existing handling of zero.
  • Keep a grid track for sparse entries. When no width list is supplied, DOCX can derive the grid from the rows.
  • Read the original widths without modifying the caller's table.

Testing

The two new regression tests failed on main and pass with the fix. All 60 DOCX, Typst and PDF package tests passed, along with lint on the changed files and the two affected package builds.

I also ran both exporters on 18 in-memory tables with and without merged cells. All 36 files exported. For a merged table, invalid widths produced the same PDF bytes and Word document XML as an explicit missing width. The valid, missing and zero controls matched their main-branch output byte for byte for PDF and in word/document.xml for DOCX.

Summary by CodeRabbit

  • Bug Fixes
    • Improved table layout when exporting to DOCX or Typst. Invalid, missing, or unusable column widths now avoid disrupting the table’s column structure.
    • DOCX tables use a default width for columns without a usable width, while zero-width columns remain zero width.
    • Typst exports use automatic column sizing for invalid or missing widths and retain point-based sizing for valid widths.

@vercel

vercel Bot commented Dec 2, 2026

Copy link
Copy Markdown

@yucheng-du is attempting to deploy a commit to the TypeCell Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The DOCX and Typst exporters now handle invalid table column widths during export. DOCX uses default widths for unset grid tracks, while Typst emits automatic tracks. Tests cover valid, invalid, missing, and zero widths.

Changes: Table Width Export Normalization

Layer / File(s) Summary
DOCX width conversion and fallback
packages/xl-docx-exporter/src/docx/util/Table.tsx, packages/xl-docx-exporter/src/docx/docxExporter.test.ts
DOCX converts supplied widths to twips and leaves undefined, negative, and non-finite values unset. Unset grid tracks use the converted 120-pixel default. Zero remains zero in the grid and does not set a cell width. The test checks these cases and an eight-column spanning header.
Typst automatic tracks
packages/xl-typst-exporter/src/defaultSchema/blocks.ts, packages/xl-typst-exporter/src/typstExporter.test.ts
Typst converts finite positive widths to points and emits auto for zero, negative, missing, or non-finite widths. The test checks valid and fallback tracks.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: yousefed, nperez0111

Merge Risk: Minimal · up to c4853

This change makes DOCX and PDF exports of tables with invalid column widths succeed instead of failing, and valid widths are unchanged. No merge-blocking risk was identified.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Description check Inconclusive The description follows the template well. It has a Summary, a Changes list, Testing details, and an Impact-free but substantive rest. It names the fix, the affected exporters, and the regression test… Add a Rationale section that explains why invalid widths must not break export and what benefit users get. Add an Impact section that states the effect on valid widths, zero widths, and existing output. Add the Checklist from the template a…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title names the two exporters (DOCX and PDF) and the core change, handling invalid table widths. The changeset adds invalid-width fallbacks in the DOCX Table and Typst block schema and adds tests …
Linked Issues check Passed Issue #3433 is the only active direct link. Its coding requirements are: (1) preserve valid widths, (2) define handling for other non-finite values, (3) avoid mutating the caller's blocks, (4) test ac…
Out of Scope Changes check Passed All changed files are in the DOCX exporter table utility and test, the Typst default schema block mapping, and their tests. Each change maps to the width-normalization objective of #3433. The PR does …
Full details: Title check

Explanation

The title names the two exporters (DOCX and PDF) and the core change, handling invalid table widths. The changeset adds invalid-width fallbacks in the DOCX Table and Typst block schema and adds tests for them. The title is specific and matches the main change. It is 9 words and 50 characters, so it stays concise.

Full details: Linked Issues check

Explanation

Issue #3433 is the only active direct link. Its coding requirements are: (1) preserve valid widths, (2) define handling for other non-finite values, (3) avoid mutating the caller's blocks, (4) test actual NaN and infinite values passed to the API, including valid, missing, and merged-cell tables. The PR summary shows the following coverage. DOCX: Table.tsx converts pixel widths through a shared helper. Undefined, negative, or non-finite converted widths become undefined, and missing entries fall back to a default width. Valid widths are kept. Zero keeps its existing handling. Typst: blocks.ts emits a point width only when the width is defined, finite, and greater than zero. Otherwise the column track uses auto. Valid widths still convert to points. Mutation: the PR description states that widths are read without modifying the caller's table. Tests: docxExporter.test.ts covers an eight-column table with a spanning header, valid, invalid, missing, and zero widths. typstExporter.test.ts covers invalid and missing widths as auto tracks and valid widths as points. The PR description reports two regression tests that fail on main and pass with the fix. Limits: I did not read the diff hunks. The verdict relies on the PR summary and the PR description. The Typst test does not show a merged-cell case in the summary. The merged-cell check was run manually, as the PR description states. The DOCX test covers the spanning-header case. The issue lists merged cells in its test scope, and the DOCX test meets that scope.

Full details: Out of Scope Changes check

Explanation

All changed files are in the DOCX exporter table utility and test, the Typst default schema block mapping, and their tests. Each change maps to the width-normalization objective of #3433. The PR does not change PDF page-fitting policy, which the issue excludes. It does not change the merged-cell HTML round trip addressed by #3383. The summary shows no unrelated refactoring or documentation churn. Limits: the assessment uses the file-level summary, not the full diff. No unrelated change is shown in that summary.

Full details: Description check

Explanation

The description follows the template well. It has a Summary, a Changes list, Testing details, and an Impact-free but substantive rest. It names the fix, the affected exporters, and the regression tests, and it links issue #3433. Several template sections are missing or only partly filled. The description has no Rationale section, no Impact section, no Screenshots/Video section (which may not apply), no Checklist, and no Additional Notes. The Summary describes the problem but does not state the feature change in a single line. The Testing section is detailed.

Resolution

Add a Rationale section that explains why invalid widths must not break export and what benefit users get. Add an Impact section that states the effect on valid widths, zero widths, and existing output. Add the Checklist from the template and mark each item. Mark the Screenshots/Video section as not applicable, or remove it. Add an Additional Notes section if relevant, for example the link to #3383 and the note that PDF page-fitting is out of scope.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks each column’s measure,
And marks the sound widths at their leisure.
When numbers fail or tracks are bare,
DOCX sets defaults; Typst uses auto there.
Eight neat columns hop into view,
With spans and widths checked through and through.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 70f44358-bf13-4cd0-8f4f-d9db6b88fc82
Commits

Reviewing files that changed from the base of the PR and between 99aff4b and c4853ef.

Files selected for processing: 4

  • packages/xl-docx-exporter/src/docx/docxExporter.test.ts
  • packages/xl-docx-exporter/src/docx/util/Table.tsx
  • packages/xl-typst-exporter/src/defaultSchema/blocks.ts
  • packages/xl-typst-exporter/src/typstExporter.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Normalize invalid table column widths before export

1 participant