I will occasionally see this error thrown from componentWillUnmount -- it's hard to reproduce, and acts like a race condition.
https://github.com/wojtekmaj/react-pdf/blob/master/src/Page.jsx#L50
This occurs in 2.5.2, but not 2.1.7. I haven't tested all the versions in between to figure out exactly when it breaks.
Hey @tjwebb,
do you perhaps managed to catch the error along with stack trace? Stack trace would be an amazing help.
I have the same problem. It occurs when Page's componentWillUnmount() calls
callIfDefined(this.props.unregisterPage, this.state.page.pageIndex); while this.state.page is null. For me, this situation occurs usually when changing pages too fast. I can confirm the error is gone if we check for this.state.page:
componentWillUnmount() {
if (this.state.page) {
callIfDefined(this.props.unregisterPage, this.state.page.pageIndex);
}
if (this.runningTask && this.runningTask.cancel) {
this.runningTask.cancel();
}
}
Not sure if this is the right solution though... this.state.page shouldn't be null in the first place.
Uncaught TypeError: Cannot read property 'pageIndex' of null
at Page.componentWillUnmount (Page.js:123)
at callComponentWillUnmountWithTimer (react-dom.development.js:8732)
at HTMLUnknownElement.callCallback (react-dom.development.js:542)
at HTMLUnknownElement.nrWrapper (0100029862017:506)
at Object.invokeGuardedCallbackDev (react-dom.development.js:581)
at invokeGuardedCallback (react-dom.development.js:438)
at safelyCallComponentWillUnmount (react-dom.development.js:8739)
at commitUnmount (react-dom.development.js:8865)
at commitNestedUnmounts (react-dom.development.js:8901)
at unmountHostComponents (react-dom.development.js:9184)
at commitDeletion (react-dom.development.js:9234)
at commitAllHostEffects (react-dom.development.js:9926)
at HTMLUnknownElement.callCallback (react-dom.development.js:542)
at HTMLUnknownElement.nrWrapper (0100029862017:506)
at Object.invokeGuardedCallbackDev (react-dom.development.js:581)
at invokeGuardedCallback (react-dom.development.js:438)
at commitRoot (react-dom.development.js:10015)
at performWorkOnRoot (react-dom.development.js:11017)
at performWork (react-dom.development.js:10967)
at batchedUpdates (react-dom.development.js:11086)
at batchedUpdates (react-dom.development.js:2330)
at dispatchEvent (react-dom.development.js:3421)
at HTMLDocument.nrWrapper (0100029862017:506)
index.js:2177 The above error occurred in the <Page> component:
in Page (at pdfViewer.js:99)
in div (created by Document)
in Document (at pdfViewer.js:88)
in div (at pdfViewer.js:68)
in PdfViewer (at documentoViewer.js:14)
in DocumentoViewer (at documentoViewerContainer.js:39)
in DocumentoViewerContainer (created by Connect(DocumentoViewerContainer))
in Connect(DocumentoViewerContainer) (at index.js:196)
in div (at index.js:193)
in div (at index.js:163)
in Viewer (created by Connect(Viewer))
in Connect(Viewer) (at index.js:93)
in div (at index.js:92)
in div (at index.js:87)
in div (at index.js:83)
in IntlProvider (at index.js:82)
in Route (at index.js:81)
in Switch (at index.js:80)
in Router (created by BrowserRouter)
in BrowserRouter (at index.js:79)
in App (created by Connect(App))
in Connect(App) (at index.js:31)
in Provider (at index.js:30)
Hi, just to say we get this error too.
It occurs for us only specifically when we load a new PDF into a container where was one already loaded (e.g. switching which PDF document is loaded).
@iaincollins this is also our scenario.
Hey all,
this issue should have been fixed in the newest v3.0.0, which just got out of alpha stage, which means there is not going to be breaking changes.
Please try it out by executing npm install react-pdf@next or yarn add react-pdf@next!
Updating your code is easy, and if you face any issues please let me know at #143 :)
@wojtekmaj no plans on fixing it before v3.0.0? Is the fix I mentioned above acceptable? If so, I can issue a PR.
Top priority for now is to get 3.0.0 released. It's a big, big improvement in architecture which generally makes it easier for me to keep the code in well condition. At the same time, impact for developers is minimal with practically only CSS classes to rename. On 2.x, I'm lacking even basic tests which, frankly, makes it a little scary. So if not highly requested I'd rather not touch it. I'll see what I can do.
I have the fix and I'm 99% sure it will fix it. I have trouble testing it though. If anyone have a scenario which gives them a high possibility of getting the error we're discussing, I'd appreciate if you installed react-pdf from branch bugfix/Page-component-crash-on-unmount-when-page-not-loaded and see if this fixes the error. If so, I'll be happy to merge it and release v2.5.4.
@wojtekmaj I'll try it tomorrow. Thanks for all the effort!
@wojtekmaj Thanks so much for this!
We are using React 16.2 and Webpack 3.8 and we were using react-pdf 2.4.2. I tried both the bugfix release and grabbing the 3.0.0 from next tag.
I wasn't able to get the bugfix release to work for us. I think maybe it's missing a build dir with a consumable version of the webpack entry point? (We need the webpack entry point and I futzed around aimlessly a bit but couldn't get it to work.)
Upgrading to 3.0.0-beta in @next tag completely fixed the problem for us and worked magically!
All we had to do was change the import path to 'react-pdf/dist/entry.webpack' and it just worked.
The issue we were having was easy to replicate for us and I can no longer replicate it with 3.0.0 so this is completely resolved here. Thank you for you assistance and for maintaining this package.
@wojtekmaj I couldn't reproduce the error with the changes you made. Thanks!
I'll try 3.0.0 soon.
Fixed in v3.0.0. Regarding v2.5.4, I'm still ready to do it if necessary, but highly recommend updating - it took me lot of hard work to make it painless. :)
Most helpful comment
I have the fix and I'm 99% sure it will fix it. I have trouble testing it though. If anyone have a scenario which gives them a high possibility of getting the error we're discussing, I'd appreciate if you installed react-pdf from branch
bugfix/Page-component-crash-on-unmount-when-page-not-loadedand see if this fixes the error. If so, I'll be happy to merge it and release v2.5.4.