Skip to content

fix: handle null declaration in DocxExporter to prevent export crash#2378

Open
aldrinjenson wants to merge 1 commit intosuperdoc-dev:mainfrom
aldrinjenson:fix/null-declaration-docx-export
Open

fix: handle null declaration in DocxExporter to prevent export crash#2378
aldrinjenson wants to merge 1 commit intosuperdoc-dev:mainfrom
aldrinjenson:fix/null-declaration-docx-export

Conversation

@aldrinjenson
Copy link

@aldrinjenson aldrinjenson commented Mar 12, 2026

Summary

  • Fixes TypeError: Cannot read properties of null (reading 'attributes') crash when exporting a SuperDoc to DOCX
  • The crash occurs in DocxExporter.#generate_xml_as_list when converter.declaration is null — which happens for documents created/edited via Yjs collaboration that were never initialized from raw XML
  • Adds optional chaining and a standard XML declaration fallback (version="1.0" encoding="UTF-8" standalone="yes")

Root Cause

exporter.js line 580 accessed this.converter.declaration.attributes without a null check. SuperConverter.declaration is initialized as null in the constructor and only populated in parseFromXml(), which isn't called for Yjs-only documents.

Test plan

  • Added unit tests for null and undefined declaration cases
  • Verify exporting the specific failing superdoc to DOCX produces a valid file that opens in Word
  • Confirm the fallback encoding (UTF-8 uppercase) is compatible with downstream consumers

🤖 Generated with Claude Code

When exporting a SuperDoc to DOCX, if the converter's declaration is null
(e.g., for documents created/edited via Yjs collaboration without raw XML
import), the export crashes with: TypeError: Cannot read properties of null
(reading 'attributes').

Add optional chaining and a standard XML declaration fallback
(version="1.0" encoding="UTF-8" standalone="yes") so export succeeds when
converter.declaration is null or undefined.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant