diegomura / diegomura/react-pdf

Uncaught TypeError: parentInstance.children.push is not a function error in react-pdf/renderer in Next.js

Open
#1,470 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
16.8k
Forks
1.3k
Avg merge
5h 6m
Merged PRs (30d)
52

Description

I'm trying to print pdf on screen in the Next.js app. And I'm using the custom document from the Next.js docs, to manipulate the DOM.
Link to the custom document:
https://nextjs.org/docs/advanced-features/custom-document
My document is same as this custom document except that I have included my DOM id like this, it is written next to the `````` line:
```

```
Below is the file where I'm using the createPortal to write my pdf:
```
import React, { useEffect, useState } from "react";
import ReactDOM from "react-dom";

// Create Document Component
export default function TestDoc({ show, children }) {
const [isBrowser, setIsBrowser] = useState(false);
useEffect(() => setIsBrowser(true), []);
const paperContent = show ?

{children}
: null;

if (isBrowser) {
return ReactDOM.createPortal(
paperContent,
document.getElementById("my-pdf")
);
} else {
return null;
}
}
```
And below is the code of the children prop that I want to render:
```
import TestDoc from "@/components/TestDoc";
import {
Document,
Page,
Text,
View,
StyleSheet,
PDFViewer,
} from "@react-pdf/renderer";
export default function Component(){

...code...

return(
{showPaper && (





Section #1


Section #2





)}
);
}
```

But when I run this code, its creating these errors:

1)

Uncaught TypeError: parentInstance.children.push is not a function
at appendChildToContainer...

2)

Uncaught TypeError: _parentInstance$child3.indexOf is not a function
at removeChildFromContainer...

3)

The above error occurred in the

component:
in div (at TestDoc.js:9)
in TestDoc (at contact.js:74)
Consider adding an error boundary to your tree to customize error handling behavior.

4)

Uncaught TypeError: parentInstance.children.push is not a function
at appendChildToContainer

5) `The above error occurred in the component: at PDFViewer...`
6)

The above error occurred in the component:
in TestDoc (at contact.js:74) Consider adding an error boundary to your tree to customize error handling behavior.

I have spent hours and hours to fix it but couldn't solve it. Please help me with this issue I need to get react-pdf/renderer working in my Next.JS app.

I would really appreciate your help.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.