Skip to content

Commit 6aa70b5

Browse files
SD-3116 - bug: SVG image doesn't render on imported files (#3268)
* fix: use correct mime type for SVG images * test: added behavior tests for imported SVG images * fix: added missing test file * refactor: use diff image on svg-image.docx --------- Co-authored-by: Gabriel Chittolina <gabrielchittolina1@gmail.com>
1 parent a6a6654 commit 6aa70b5

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

packages/super-editor/src/editors/v1/core/DocxZipper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { reconcileDocumentRelationships, MANAGED_DOCUMENT_PARTS } from './opc/re
1111
const IMAGE_EXTS = new Set(['png', 'jpg', 'jpeg', 'gif', 'bmp', 'tiff', 'tif', 'emf', 'wmf', 'svg', 'webp']);
1212

1313
/** Map file extensions to correct MIME sub-types where they differ. */
14-
const MIME_TYPE_FOR_EXT = { tif: 'tiff', jpg: 'jpeg' };
14+
const MIME_TYPE_FOR_EXT = { tif: 'tiff', jpg: 'jpeg', svg: 'svg+xml' };
1515
const CUSTOM_XML_ITEM_PROPS_CONTENT_TYPE = 'application/vnd.openxmlformats-officedocument.customXmlProperties+xml';
1616

1717
/** OOXML content types for embedded font file extensions. */
244 KB
Binary file not shown.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import path from 'node:path';
2+
import { fileURLToPath } from 'node:url';
3+
import { test, expect } from '../../fixtures/superdoc.js';
4+
import { assertDocumentApiReady } from '../../helpers/document-api.js';
5+
6+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
7+
const DOC_PATH = path.resolve(__dirname, 'fixtures/svg-image.docx');
8+
9+
test.use({ config: { toolbar: 'full', comments: 'off' } });
10+
11+
test('loads DOCX with SVG image and renders it with the correct MIME type', async ({ superdoc }) => {
12+
await superdoc.loadDocument(DOC_PATH);
13+
await superdoc.waitForStable();
14+
await assertDocumentApiReady(superdoc.page);
15+
16+
await expect(superdoc.page.locator('.superdoc-page').first()).toBeVisible();
17+
18+
const mediaEntry = await superdoc.page.evaluate(() => {
19+
const editor = (window as any).editor;
20+
const media = editor?.storage?.image?.media ?? {};
21+
const svgKey = Object.keys(media).find((k) => k.toLowerCase().endsWith('.svg'));
22+
return svgKey ? { key: svgKey, value: media[svgKey] } : null;
23+
});
24+
25+
expect(mediaEntry, 'imported SVG should be registered in editor.storage.image.media').not.toBeNull();
26+
expect(mediaEntry!.value, 'SVG data URI must use the image/svg+xml MIME type').toMatch(
27+
/^data:image\/svg\+xml;base64,/,
28+
);
29+
30+
const imgSrc = await superdoc.page.locator('img').first().getAttribute('src');
31+
expect(imgSrc, 'rendered <img> should resolve to the SVG data URI').toMatch(/^data:image\/svg\+xml;base64,/);
32+
});

0 commit comments

Comments
 (0)