fix: persist header/footer images on save (fixes #251)#264
Merged
Conversation
Images inserted into headers or footers were silently dropped on save: `collectNewImages` only walked the document body, so the image binary was never written to `word/media/` and no relationship was added to the header/footer's rels file. Word then showed "cannot display image". Refactor image + hyperlink processing to be part-aware: enumerate the body and every header/footer as parts with their own rels file, share the `word/media/` image counter across parts (it's a package-wide namespace), and allocate rIds per rels file. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
- readRelsOrStub: normalize `<Relationships .../>` (Word's empty form) to `<Relationships ...></Relationships>` so `.replace` appends correctly. Without this, footers with no prior relationships silently dropped newly inserted images. - Add symmetric footer image round-trip test. Caught the bug above. - Use headerFooterFilename() helper in collectHeaderFooterUpdates instead of duplicating the prefix/slice logic. - Extract FIXTURE_PATH + loadFixture() to deduplicate test setup. - Remove one narrating comment. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This was referenced Apr 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
collectNewImagesonly walked the document body, so the image binary never landed inword/media/and no relationship was added to the header/footer's rels file — Word then showed "cannot display image".rezip.tsto be part-aware: enumerate the body and every header/footer asParts with their own rels file, share theword/media/image counter (package-wide namespace), and allocate rIds per rels file. Creates a minimal rels file on demand for a header/footer that had no prior relationships.Test plan
packages/core/src/docx/__tests__/header-image-repack.test.ts— inserts an image into a real header (fixture:titlePg-header-footer.docx), repacks, and asserts: binary inword/media/, relationship inword/_rels/header*.xml.rels, no stray entry indocument.xml.rels,r:embedwired up in the header XML,pngregistered in[Content_Types].xml.bun run typecheck— clean.bun test packages/core/src/docx/__tests__/— 39/39 pass, no regressions.word/media/imageN.png+ matching relationship inword/_rels/header*.xml.rels.Follow-up issues surfaced by manual testing
These are pre-existing bugs in the display/edit layers (not the save path this PR fixes). Filed for separate fixes — they need live DOM inspection to root-cause:
PagedEditor.tsx:1842-1844but isn't producing the right result; suspected stale measurement cache or the<img>clipping hack atrenderPage.ts:1149.InlineHeaderFooterEditorbuilds its ownExtensionManagerthat doesn't include the React NodeView the body editor uses for resize handles.Fixes #251.
🤖 Generated with Claude Code