Skip to content
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

Warning: setState(...): Can only update a mounted or mounting component. #43

Closed
ramusus opened this issue Jul 31, 2017 · 2 comments
Closed
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed
Milestone

Comments

@ramusus
Copy link

ramusus commented Jul 31, 2017

Using versions 1.8.3 and 2.0.0beta I got this error. It happens every time, when I unmount my component before onDocumentLoad is called. I don't want to use this.isMounted() because it's considered anti-pattern. So is there any way to unsubscribe from async actions in componentWillUnmount? I think it should be somewhere inside Document component

warning.js:36 Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the PageTextContent component.

printWarning @ warning.js:36
warning @ warning.js:60
getInternalInstanceReadyForUpdate @ ReactUpdateQueue.js:48
enqueueSetState @ ReactUpdateQueue.js:200
ReactComponent.setState @ ReactBaseClasses.js:64
PageTextContent._this.onGetTextSuccess @ PageTextContent.js:64
Promise resolved (async)
getTextContent @ PageTextContent.js:135
componentDidMount @ PageTextContent.js:111
(anonymous) @ ReactCompositeComponent.js:265
measureLifeCyclePerf @ ReactCompositeComponent.js:75
(anonymous) @ ReactCompositeComponent.js:264
notifyAll @ CallbackQueue.js:76
close @ ReactReconcileTransaction.js:80
closeAll @ Transaction.js:206
perform @ Transaction.js:153
perform @ Transaction.js:140
perform @ ReactUpdates.js:89
flushBatchedUpdates @ ReactUpdates.js:172
closeAll @ Transaction.js:206
perform @ Transaction.js:153
batchedUpdates @ ReactDefaultBatchingStrategy.js:62
enqueueUpdate @ ReactUpdates.js:200
enqueueUpdate @ ReactUpdateQueue.js:24
enqueueSetState @ ReactUpdateQueue.js:209
ReactComponent.setState @ ReactBaseClasses.js:64
Page._this.onLoadSuccess @ Page.js:54
Promise resolved (async)
loadPage @ Page.js:151
componentDidMount @ Page.js:86
(anonymous) @ ReactCompositeComponent.js:265
measureLifeCyclePerf @ ReactCompositeComponent.js:75
(anonymous) @ ReactCompositeComponent.js:264
notifyAll @ CallbackQueue.js:76
close @ ReactReconcileTransaction.js:80
closeAll @ Transaction.js:206
perform @ Transaction.js:153
perform @ Transaction.js:140
perform @ ReactUpdates.js:89
flushBatchedUpdates @ ReactUpdates.js:172
closeAll @ Transaction.js:206
perform @ Transaction.js:153
batchedUpdates @ ReactDefaultBatchingStrategy.js:62
enqueueUpdate @ ReactUpdates.js:200
enqueueUpdate @ ReactUpdateQueue.js:24
enqueueSetState @ ReactUpdateQueue.js:209
ReactComponent.setState @ ReactBaseClasses.js:64
Document._this.onLoadSuccess @ Document.js:69
Promise resolved (async)
PDFDocumentLoadingTask_then @ pdf.js:2007
Document._this.onSourceSuccess @ Document.js:61
Promise resolved (async)
loadDocument @ Document.js:206
componentDidMount @ Document.js:149
(anonymous) @ ReactCompositeComponent.js:265
measureLifeCyclePerf @ ReactCompositeComponent.js:75
(anonymous) @ ReactCompositeComponent.js:264
notifyAll @ CallbackQueue.js:76
close @ ReactReconcileTransaction.js:80
closeAll @ Transaction.js:206
perform @ Transaction.js:153
perform @ Transaction.js:140
perform @ ReactUpdates.js:89
flushBatchedUpdates @ ReactUpdates.js:172
close @ ReactUpdates.js:47
closeAll @ Transaction.js:206
perform @ Transaction.js:153
perform @ ReactUpdates.js:89
flushBatchedUpdates @ ReactUpdates.js:172
closeAll @ Transaction.js:206
perform @ Transaction.js:153
batchedUpdates @ ReactDefaultBatchingStrategy.js:62
batchedUpdates @ ReactUpdates.js:97
dispatchEvent @ ReactEventListener.js:147
@wojtekmaj wojtekmaj self-assigned this Aug 11, 2017
@wojtekmaj wojtekmaj added bug Something isn't working help wanted Extra attention is needed labels Aug 11, 2017
@wojtekmaj
Copy link
Owner

Hey, thanks for the report. I can confirm that this indeed is happening.

I could just set up flags which simulate isMounted on my own, but I'm not sure if we want that. I'd rather cancel a running task instead.

Sadly, it seems like the only way I can cancel a PDF.js task is to destroy it, which for some reason also happens to destroy worker altogether, which makes ReactPDF to fail to re-initialize when necessary. I don't know if I succeed at it alone, but any help is appreciated!

@wojtekmaj wojtekmaj added this to the 2.0.0 milestone Aug 11, 2017
@wojtekmaj
Copy link
Owner

wojtekmaj commented Aug 11, 2017

Decided to implement cancellable promises. Coming in the 2.0.0 release (and it's in freshly released beta too)!

I'm still looking for feedback whether we could do it better, but this should work just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants