Skip to content

fix(xlsx): preserve rich text in streaming writers - #638

Open
MathiasWP wants to merge 1 commit into
productdevbook:mainfrom
MathiasWP:ws/reisadalen-9d6cd318f424463893337d45e5971715
Open

MathiasWP wants to merge 1 commit into
productdevbook:mainfrom
MathiasWP:ws/reisadalen-9d6cd318f424463893337d45e5971715

Conversation

@MathiasWP

@MathiasWP MathiasWP commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Streaming XLSX writers drop rich-text runs: a cell containing only richText disappears, while a cell with a fallback value loses its run formatting. The buffered writer already supports these runs, but StreamStyledCell and the streaming serializer did not pass them through. Existing streaming tests covered styles and formulas, not rich-text runs.

Change

  • Add richText?: RichTextRun[] to StreamStyledCell and recognize rich-text-only wrappers.
  • Pass runs to the existing shared cell serializer for inline and shared-string output.
  • Deep-copy captured header runs and nested fonts so caller mutations cannot change headers repeated after sheet rollover.
  • Add 15 regression cases covering both streaming entry points and the incremental writer, fallback values, literal formula-like text, formatting, empty runs, and rollover.

Fixes #637.

Validation

  • With the final regression tests against unchanged main: 10 fail and 5 pass. With the fix: all 15 pass.
  • Seven affected suites: 94 tests pass with --maxWorkers=1.
  • Lint/format and both TypeScript projects pass; lint reports two existing warnings in unrelated files.
  • Build and packaged-artifact verification pass using Bun 1.4.2.
  • git diff --check passes.

Full-suite attempts did not finish cleanly under heavy concurrent machine load: unrelated stress/property/fuzz tests hit their five-second timeouts, and a reduced-worker run also hit the large-encryption test's 30-second timeout. Those runs were stopped; the full suite still needs CI verification. I did not open the output in Excel.

Summary by CodeRabbit

  • New Features
    • Streaming spreadsheet exports now support rich-text formatting in cells, alongside existing styles and formulas.
  • Bug Fixes
    • Repeated header rows retain their original rich-text formatting when the source content changes later.
    • Cells with empty rich-text content continue to use their values or formulas as expected.
  • Tests
    • Added coverage for rich text across streaming export modes, including single-sheet and multi-sheet workbooks.

Carry rich-text runs through streamed cells and clone repeated headers safely.
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5dcbacd0-50b1-4feb-aa2f-751a68d0b05b
Commits

Reviewing files that changed from the base of the PR and between 3974c7b and fd59a95.

Files selected for processing: 2
  • src/xlsx/stream-writer.ts
  • test/xlsx-stream-rich-text.test.ts

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

Walkthrough

Streaming XLSX writers now accept per-cell rich-text runs and pass them to the shared cell serializer. Captured header rows clone rich-text runs so later mutations do not change repeated headers.

Changes: Streaming rich-text support

Layer / File(s) Summary
Rich-text serialization
src/xlsx/stream-writer.ts, test/xlsx-stream-rich-text.test.ts
StreamStyledCell accepts richText runs, which the streaming serialization paths pass to the shared cell serializer. Tests cover five writer modes, rich-text formatting, formula-like text, and fallback to values or formulas when runs are empty. The addRow documentation lists rich text as supported content.
Header snapshot preservation
src/xlsx/stream-writer.ts, test/xlsx-stream-rich-text.test.ts
Styled-cell detection recognizes richText. Captured rows deep-clone rich-text runs. Rollover tests check that later mutations do not change the captured header.

Priority: Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant XlsxStreamWriter
  participant serializeRow
  participant serializeCell
  participant SharedCellSerializer
  XlsxStreamWriter->>serializeRow: Pass streamed row
  serializeRow->>serializeCell: Pass cell and richText runs
  serializeCell->>SharedCellSerializer: Pass ResolvedCell with richText
Loading

Possibly related PRs

Suggested reviewers: jlucaso1, productdevbook

Merge Risk: Minimal · up to fd59a

No issue requiring a fix before merge was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely identifies the main change: preserving rich text in XLSX streaming writers.
Linked Issues check Passed Issue #637 requires rich-text support for writeXlsxStreamSheets, writeXlsxStream, and XlsxStreamWriter. The diff adds richText?: RichTextRun[], recognizes rich-text-only cells, and passes runs…
Out of Scope Changes check Passed The changes stay within issue #637. The source changes add the requested streaming rich-text plumbing and header snapshot isolation. The new tests validate the requested writer modes and edge cases. T…
Full details: Linked Issues check

Explanation

Issue #637 requires rich-text support for writeXlsxStreamSheets, writeXlsxStream, and XlsxStreamWriter. The diff adds richText?: RichTextRun[], recognizes rich-text-only cells, and passes runs to the shared serializer. The shared path covers inline and shared strings. The added tests cover fallback values, literal = text, formatting, empty runs, all three writer APIs, and header rollover. snapshotRow deep-copies runs and nested fonts before reuse.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #637. The source changes add the requested streaming rich-text plumbing and header snapshot isolation. The new tests validate the requested writer modes and edge cases. The documentation update describes the new addRow capability.

Finishing Touches
🧪 Generate unit tests (beta)
  • 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

Comment @coderabbitai help to get the list of available commands.

@MathiasWP
MathiasWP marked this pull request as ready for review October 26, 2026 14:19

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.

Support richText runs in XLSX streaming writers

1 participant