-
Notifications
You must be signed in to change notification settings - Fork 86
Description
What happened?
When loading a DOCX file generated by docx-templates (v4.15.0) that contains multiple inline images, SuperDoc renders only the last image in every image slot. All other image slots show the same last image repeated. The DOCX opens correctly in Microsoft Word, Google Docs, and LibreOffice — the issue is specific to the SuperDoc editor.
Steps to reproduce
Generate a DOCX using docx-templates with multiple images inserted via an image loop (e.g. 3 property photos)
Load the resulting DOCX into SuperDoc via docxUrl
Observe all image slots render the same last image
SuperDoc version
1.16.0
Additional context
Expected behavior
Each image slot should display its own distinct image, matching the output in Word/Google Docs/LibreOffice.
Actual behavior
Only the last image renders — it appears in every slot.
Root cause identified
After inspecting the raw DOCX XML we found two issues introduced by the docx npm package (used internally by docx-templates):
Duplicate pic:cNvPr id="0" on all images — every inserted image has id="0" on the pic:cNvPr element. Per the OOXML spec (§20.2.2.3) this ID must be unique within the document. ProseMirror likely uses this ID as a node key and deduplicates — rendering only the last image for all slots.
<pic:cNvPr id="0" name="image1.jpg"/>
<pic:cNvPr id="0" name="image2.jpg"/>
<pic:cNvPr id="0" name="image3.jpg"/>
Non-standard relationship IDs — docx-templates generates relationship IDs in img{hash} format instead of the standard rId{n} convention:
Environment
Version
@harbour-enterprises/superdoc 1.16.0
docx-templates 4.15.0
Browser Chrome 122
Node.js 20.x
Possible fix
SuperDoc could defensively reassign unique IDs to any pic:cNvPr elements that share id="0" during DOCX load, similar to how Word handles this gracefully. Alternatively, documenting that SuperDoc requires standard rId{n} relationship IDs would help integrators know to pre-process their DOCX files.
Additional context
Confirmed images ARE present in the DOCX zip (correct EMU dimensions found in XML)
Images are NOT inside a table — they are in standalone <w:p> paragraphs
The bug is not related to file size — tested with files ranging from 1MB to 12MB with identical results
Downloads (PDF, Word) correctly show all distinct images — the issue is editor rendering only