Skip to content

Commit 10b0885

Browse files
committed
🐛(frontend) fix svg export
Last upgrade of Blocknote to 0.30.0 broke the SVG export. The previewWidth can be undefined, which causes the export to fail. This commit adds a fallback width in case previewWidth is undefined.
1 parent 62d1bc6 commit 10b0885

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/frontend/apps/e2e/__tests__/app-impress/assets/test.svg

Lines changed: 6 additions & 1 deletion
Loading

src/frontend/apps/impress/src/features/docs/doc-export/blocks-mapping/imageDocx.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ export const blockMappingImageDocx: DocsExporterDocx['mappings']['blockMapping']
2121
const blob = await exporter.resolveFile(block.props.url);
2222
let pngConverted: string | undefined;
2323
let dimensions: { width: number; height: number } | undefined;
24+
let previewWidth = block.props.previewWidth || undefined;
2425

2526
if (!blob.type.includes('image')) {
2627
return [];
2728
}
2829

2930
if (blob.type.includes('svg')) {
3031
const svgText = await blob.text();
31-
pngConverted = await convertSvgToPng(svgText, block.props.previewWidth);
32+
const FALLBACK_SIZE = 536;
33+
previewWidth = previewWidth || blob.size || FALLBACK_SIZE;
34+
pngConverted = await convertSvgToPng(svgText, previewWidth);
3235
const img = new Image();
3336
img.src = pngConverted;
3437
await new Promise((resolve) => {
@@ -47,8 +50,7 @@ export const blockMappingImageDocx: DocsExporterDocx['mappings']['blockMapping']
4750

4851
const { width, height } = dimensions;
4952

50-
let previewWidth = block.props.previewWidth;
51-
if (previewWidth > MAX_WIDTH) {
53+
if (previewWidth && previewWidth > MAX_WIDTH) {
5254
previewWidth = MAX_WIDTH;
5355
}
5456

@@ -69,8 +71,8 @@ export const blockMappingImageDocx: DocsExporterDocx['mappings']['blockMapping']
6971
}
7072
: undefined,
7173
transformation: {
72-
width: previewWidth,
73-
height: (previewWidth / width) * height,
74+
width: previewWidth || width,
75+
height: ((previewWidth || width) / width) * height,
7476
},
7577
}),
7678
],

src/frontend/apps/impress/src/features/docs/doc-export/blocks-mapping/imagePDF.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,25 @@ export const blockMappingImagePDF: DocsExporterPDF['mappings']['blockMapping']['
1212
async (block, exporter) => {
1313
const blob = await exporter.resolveFile(block.props.url);
1414
let pngConverted: string | undefined;
15+
let width = block.props.previewWidth || undefined;
1516

1617
if (!blob.type.includes('image')) {
1718
return <View wrap={false} />;
1819
}
1920

2021
if (blob.type.includes('svg')) {
2122
const svgText = await blob.text();
22-
pngConverted = await convertSvgToPng(svgText, block.props.previewWidth);
23+
const FALLBACK_SIZE = 536;
24+
width = width || blob.size || FALLBACK_SIZE;
25+
pngConverted = await convertSvgToPng(svgText, width);
2326
}
2427

2528
return (
2629
<View wrap={false}>
2730
<Image
2831
src={pngConverted || blob}
2932
style={{
30-
width: block.props.previewWidth * PIXELS_PER_POINT,
33+
width: width ? width * PIXELS_PER_POINT : undefined,
3134
maxWidth: '100%',
3235
}}
3336
/>

0 commit comments

Comments
 (0)