Skip to content

Commit be8ea2b

Browse files
authored
fix: add keys to pdf exporter (#1739)
1 parent 5adf609 commit be8ea2b

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

packages/xl-pdf-exporter/src/pdf/defaultSchema/blocks.tsx

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
2727
> = {
2828
paragraph: (block, exporter) => {
2929
// const style = blocknoteDefaultPropsToReactPDFStyle(block.props);
30-
return <Text>{exporter.transformInlineContent(block.content)}</Text>;
30+
return (
31+
<Text key={"paragraph" + block.id}>
32+
{exporter.transformInlineContent(block.content)}
33+
</Text>
34+
);
3135
},
3236
toggleListItem: (block, exporter) => {
3337
return (
@@ -39,7 +43,7 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
3943
bulletListItem: (block, exporter) => {
4044
// const style = t(block.props);
4145
return (
42-
<ListItem listMarker={BULLET_MARKER}>
46+
<ListItem listMarker={BULLET_MARKER} key={"bulletListItem" + block.id}>
4347
<Text>{exporter.transformInlineContent(block.content)}</Text>
4448
</ListItem>
4549
);
@@ -48,7 +52,10 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
4852
// const style = blocknoteDefaultPropsToReactPDFStyle(block.props);
4953
// console.log("NUMBERED LIST ITEM", block.props.textAlignment, style);
5054
return (
51-
<ListItem listMarker={`${numberedListIndex}.`}>
55+
<ListItem
56+
listMarker={`${numberedListIndex}.`}
57+
key={"numberedListItem" + block.id}
58+
>
5259
<Text>{exporter.transformInlineContent(block.content)}</Text>
5360
</ListItem>
5461
);
@@ -61,6 +68,7 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
6168
listMarker={
6269
block.props.checked ? CHECK_MARKER_CHECKED : CHECK_MARKER_UNCHECKED
6370
}
71+
key={"checkListItem" + block.id}
6472
>
6573
<Text>{exporter.transformInlineContent(block.content)}</Text>
6674
</ListItem>
@@ -77,6 +85,7 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
7785
}[block.props.level];
7886
return (
7987
<Text
88+
key={"heading" + block.id}
8089
style={{
8190
fontSize: levelFontSizeEM * FONT_SIZE * PIXELS_PER_POINT,
8291
fontWeight: 700,
@@ -89,6 +98,7 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
8998
quote: (block, exporter) => {
9099
return (
91100
<Text
101+
key={"quote" + block.id}
92102
style={{
93103
borderLeft: "#7D797A",
94104
color: "#7D797A",
@@ -106,7 +116,7 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
106116

107117
return (
108118
<Text
109-
key={`line_${index}`}
119+
key={`line_${index}` + block.id}
110120
style={{
111121
marginLeft: indent * 9.5 * PIXELS_PER_POINT,
112122
}}
@@ -127,17 +137,18 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
127137
fontSize: FONT_SIZE * PIXELS_PER_POINT,
128138
fontFamily: "GeistMono",
129139
}}
140+
key={"codeBlock" + block.id}
130141
>
131142
{lines}
132143
</View>
133144
);
134145
},
135146
pageBreak: () => {
136-
return <View break />;
147+
return <View break key={"pageBreak"} />;
137148
},
138149
audio: (block, exporter) => {
139150
return (
140-
<View wrap={false}>
151+
<View wrap={false} key={"audio" + block.id}>
141152
{file(
142153
block.props,
143154
"Open audio file",
@@ -152,7 +163,7 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
152163
},
153164
video: (block, exporter) => {
154165
return (
155-
<View wrap={false}>
166+
<View wrap={false} key={"video" + block.id}>
156167
{file(
157168
block.props,
158169
"Open video file",
@@ -167,7 +178,7 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
167178
},
168179
file: (block, exporter) => {
169180
return (
170-
<View wrap={false}>
181+
<View wrap={false} key={"file" + block.id}>
171182
{file(
172183
block.props,
173184
"Open file",
@@ -182,7 +193,7 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
182193
},
183194
image: async (block, t) => {
184195
return (
185-
<View wrap={false}>
196+
<View wrap={false} key={"image" + block.id}>
186197
<Image
187198
src={await t.resolveFile(block.props.url)}
188199
style={{
@@ -196,7 +207,9 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
196207
);
197208
},
198209
table: (block, t) => {
199-
return <Table data={block.content} transformer={t} />;
210+
return (
211+
<Table data={block.content} transformer={t} key={"table" + block.id} />
212+
);
200213
},
201214
};
202215

@@ -208,7 +221,7 @@ function file(
208221
) {
209222
const PIXELS_PER_POINT = 0.75;
210223
return (
211-
<Link src={props.url}>
224+
<Link src={props.url} key={"file" + props.url}>
212225
<View
213226
style={{
214227
display: "flex",
@@ -232,6 +245,7 @@ function caption(
232245
}
233246
return (
234247
<Text
248+
key={"caption" + props.caption}
235249
style={{
236250
width: props.previewWidth
237251
? props.previewWidth * PIXELS_PER_POINT

packages/xl-pdf-exporter/src/pdf/defaultSchema/inlinecontent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const pdfInlineContentMappingForDefaultSchema: InlineContentMapping<
1212
> = {
1313
link: (ic, exporter) => {
1414
return (
15-
<Link href={ic.href}>
15+
<Link href={ic.href} key={"link" + ic.href}>
1616
{ic.content.map((content) => exporter.transformStyledText(content))}
1717
</Link>
1818
);

packages/xl-pdf-exporter/src/pdf/pdfExporter.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@ export class PDFExporter<
117117
public transformStyledText(styledText: StyledText<S>) {
118118
const stylesArray = this.mapStyles(styledText.styles);
119119
const styles = Object.assign({}, ...stylesArray);
120-
return <Text style={styles}>{styledText.text}</Text>;
120+
return (
121+
<Text style={styles} key={styledText.text}>
122+
{styledText.text}
123+
</Text>
124+
);
121125
}
122126

123127
/**
@@ -150,7 +154,7 @@ export class PDFExporter<
150154

151155
const style = this.blocknoteDefaultPropsToReactPDFStyle(b.props as any);
152156
ret.push(
153-
<>
157+
<View key={b.id}>
154158
<View
155159
style={{
156160
paddingVertical: 3 * PIXELS_PER_POINT,
@@ -166,11 +170,12 @@ export class PDFExporter<
166170
marginLeft: FONT_SIZE * 1.5 * PIXELS_PER_POINT,
167171
...this.styles.blockChildren,
168172
}}
173+
key={b.id + nestingLevel + "children"}
169174
>
170175
{children}
171176
</View>
172177
)}
173-
</>,
178+
</View>,
174179
);
175180
}
176181

0 commit comments

Comments
 (0)