react-pdf-viewer / react-pdf-viewer

A React component to view a PDF document
https://react-pdf-viewer.dev
Other
2.13k stars 230 forks source link

PDF with annotations causing `Type Error: Cannot read properties of null (reading '0')` #1748

Open dvberzon opened 3 months ago

dvberzon commented 3 months ago

Steps to reproduce.

The following pdf was generated from a minimal docx file with a comment in (using gotenberg)

preview_doc with a comment.pdf

(original doc x file) doc with a comment.docx

We are attempting to preview this pdf within react-pdf-viewer

result

When trying to show it in react-pdf-viewer there is an error

TypeError
Cannot read properties of null (reading '0')
    at Annotation (https://dw38pg.csb.app/node_modules/
react-pdf-viewer/core/lib/cjs/core.js:1437:13
renderWithHooks
https://dw38pg.csb.app/node_modules/react-dom/cjs/react-dom.development.js:16305:18
mountIndeterminateComponent
https://dw38pg.csb.app/node_modules/react-dom/cjs/react-dom.development.js:20074:13
beginWork
https://dw38pg.csb.app/node_modules/react-dom/cjs/react-dom.development.js:21587:16
HTMLUnknownElement.callCallback
...

Expected result

No error is thrown and the comment displays in the annotation layer

See code sandbox example here https://codesandbox.io/p/sandbox/react-pdf-viewer-error-dw38pg?file=%2Fsrc%2FApp.tsx%3A11%2C11

The error is being thrown here

https://github.com/react-pdf-viewer/react-pdf-viewer/blob/84804a8a27d481e6abcaeff4cc039b5f1d806e74/packages/core/src/annotations/Annotation.tsx#L48

Where rect[0] falls over because rect is null.

The error does to not happen when uploading the pdf to the example pdf viewer on the homepage https://react-pdf-viewer.dev/. We cannot find the source of the demo on the homepage, but perhaps one of the included plugins fixes the issue.

The error also goes away if I downgrade pdfjs-dist to 3.7.107, so it is something to do with compatibility with the pdfjs after 3.8.162

Any help appreciated.

matheins commented 2 months ago

Why does nobody care? PDF views crashing due to annotations is such an obvious thing that needs to get fixed.

amdixit commented 3 weeks ago

Any update on this issue?