Skip to content

fix: add keys to pdf exporter #1739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions packages/xl-pdf-exporter/src/pdf/defaultSchema/blocks.tsx
Original file line number Diff line number Diff line change
@@ -26,12 +26,16 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
> = {
paragraph: (block, exporter) => {
// const style = blocknoteDefaultPropsToReactPDFStyle(block.props);
return <Text>{exporter.transformInlineContent(block.content)}</Text>;
return (
<Text key={"paragraph" + block.id}>
{exporter.transformInlineContent(block.content)}
</Text>
);
},
bulletListItem: (block, exporter) => {
// const style = t(block.props);
return (
<ListItem listMarker={BULLET_MARKER}>
<ListItem listMarker={BULLET_MARKER} key={"bulletListItem" + block.id}>
<Text>{exporter.transformInlineContent(block.content)}</Text>
</ListItem>
);
@@ -40,7 +44,10 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
// const style = blocknoteDefaultPropsToReactPDFStyle(block.props);
// console.log("NUMBERED LIST ITEM", block.props.textAlignment, style);
return (
<ListItem listMarker={`${numberedListIndex}.`}>
<ListItem
listMarker={`${numberedListIndex}.`}
key={"numberedListItem" + block.id}
>
<Text>{exporter.transformInlineContent(block.content)}</Text>
</ListItem>
);
@@ -53,6 +60,7 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
listMarker={
block.props.checked ? CHECK_MARKER_CHECKED : CHECK_MARKER_UNCHECKED
}
key={"checkListItem" + block.id}
>
<Text>{exporter.transformInlineContent(block.content)}</Text>
</ListItem>
@@ -63,6 +71,7 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
block.props.level === 1 ? 2 : block.props.level === 2 ? 1.5 : 1.17;
return (
<Text
key={"heading" + block.id}
style={{
fontSize: fontSizeEM * FONT_SIZE * PIXELS_PER_POINT,
fontWeight: 700,
@@ -75,6 +84,7 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
quote: (block, exporter) => {
return (
<Text
key={"quote" + block.id}
style={{
borderLeft: "#7D797A",
color: "#7D797A",
@@ -92,7 +102,7 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<

return (
<Text
key={`line_${index}`}
key={`line_${index}` + block.id}
style={{
marginLeft: indent * 9.5 * PIXELS_PER_POINT,
}}
@@ -113,17 +123,18 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
fontSize: FONT_SIZE * PIXELS_PER_POINT,
fontFamily: "GeistMono",
}}
key={"codeBlock" + block.id}
>
{lines}
</View>
);
},
pageBreak: () => {
return <View break />;
return <View break key={"pageBreak"} />;
},
audio: (block, exporter) => {
return (
<View wrap={false}>
<View wrap={false} key={"audio" + block.id}>
{file(
block.props,
"Open audio file",
@@ -138,7 +149,7 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
},
video: (block, exporter) => {
return (
<View wrap={false}>
<View wrap={false} key={"video" + block.id}>
{file(
block.props,
"Open video file",
@@ -153,7 +164,7 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
},
file: (block, exporter) => {
return (
<View wrap={false}>
<View wrap={false} key={"file" + block.id}>
{file(
block.props,
"Open file",
@@ -168,7 +179,7 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
},
image: async (block, t) => {
return (
<View wrap={false}>
<View wrap={false} key={"image" + block.id}>
<Image
src={await t.resolveFile(block.props.url)}
style={{
@@ -182,7 +193,9 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
);
},
table: (block, t) => {
return <Table data={block.content} transformer={t} />;
return (
<Table data={block.content} transformer={t} key={"table" + block.id} />
);
},
};

@@ -194,7 +207,7 @@ function file(
) {
const PIXELS_PER_POINT = 0.75;
return (
<Link src={props.url}>
<Link src={props.url} key={"file" + props.url}>
<View
style={{
display: "flex",
@@ -218,6 +231,7 @@ function caption(
}
return (
<Text
key={"caption" + props.caption}
style={{
width: props.previewWidth
? props.previewWidth * PIXELS_PER_POINT
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ export const pdfInlineContentMappingForDefaultSchema: InlineContentMapping<
> = {
link: (ic, exporter) => {
return (
<Link href={ic.href}>
<Link href={ic.href} key={"link" + ic.href}>
{ic.content.map((content) => exporter.transformStyledText(content))}
</Link>
);
11 changes: 8 additions & 3 deletions packages/xl-pdf-exporter/src/pdf/pdfExporter.tsx
Original file line number Diff line number Diff line change
@@ -117,7 +117,11 @@ export class PDFExporter<
public transformStyledText(styledText: StyledText<S>) {
const stylesArray = this.mapStyles(styledText.styles);
const styles = Object.assign({}, ...stylesArray);
return <Text style={styles}>{styledText.text}</Text>;
return (
<Text style={styles} key={styledText.text}>
{styledText.text}
</Text>
);
}

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

const style = this.blocknoteDefaultPropsToReactPDFStyle(b.props as any);
ret.push(
<>
<View key={b.id}>
<View
style={{
paddingVertical: 3 * PIXELS_PER_POINT,
@@ -166,11 +170,12 @@ export class PDFExporter<
marginLeft: FONT_SIZE * 1.5 * PIXELS_PER_POINT,
...this.styles.blockChildren,
}}
key={b.id + nestingLevel + "children"}
>
{children}
</View>
)}
</>,
</View>,
);
}

Loading
Oops, something went wrong.