Skip to content

[Fabric] Fix targetAsInstance dispatchEvent "cannot read property of null" #18156

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

Conversation

JoshuaGross
Copy link
Contributor

Summary

In some cases in prod testing, the targetFiber here in dispatchEvent does not have a stateNode. If we try to get canonical directly from stateNode, it will crash. We already check that targetFiber is non-null before continuing, I think it makes sense to check stateNode as well.

It's unclear to me why this is happening in the first place, though (why we'd have a targetFiber but not a stateNode). We may want to investigate and fix that in addition to/instead of this.

Test Plan

yarn test
yarn test-prod
yarn flow fabric

I have an FB-internal prod test as well.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 27, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 69c4f24:

Sandbox Source
old-cache-71r3i Configuration

@gaearon
Copy link
Collaborator

gaearon commented Feb 27, 2020

Do you need this in the next sync?

@sizebot
Copy link

sizebot commented Feb 27, 2020

No significant bundle size changes to report.

Size changes (stable)

Generated by 🚫 dangerJS against 69c4f24

@sizebot
Copy link

sizebot commented Feb 27, 2020

No significant bundle size changes to report.

Size changes (experimental)

Generated by 🚫 dangerJS against 69c4f24

@JoshuaGross
Copy link
Contributor Author

Eli thinks it “shouldn’t be possible” for stateNode to be null so I need to do a bit more investigation. I would probably just land the eventual solution as a partial sync if it’s urgent.

@gaearon
Copy link
Collaborator

gaearon commented Feb 27, 2020

fwiw we do null stateNode since recently on unmount.

@JoshuaGross
Copy link
Contributor Author

@gaearon Oh interesting - so the case where it's crashing, it would potentially mean an event has been dispatched to an unmounted component?

@JoshuaGross
Copy link
Contributor Author

@gaearon If it seems to you that this is a reasonable check to make, and that we aren't covering up some earlier data corruption, then I'm fine landing this.

@JoshuaGross JoshuaGross merged commit ae60caa into facebook:master Feb 28, 2020
@gaearon
Copy link
Collaborator

gaearon commented Feb 28, 2020

so the case where it's crashing, it would potentially mean an event has been dispatched to an unmounted component

Possibly.

If it seems to you that this is a reasonable check to make, and that we aren't covering up some earlier data corruption, then I'm fine landing this.

I don't know the event system enough to tell if that's ever supposed to happen. @trueadm might know.

@trueadm
Copy link
Contributor

trueadm commented Feb 28, 2020

It's definitely possible with sync events. An event can cause a sync update that causes an update that unmounts a fiber, then the event can propagate to the unmounted fiber. It's rare, but can happen and should probably be guarded against.

@JoshuaGross
Copy link
Contributor Author

Cool. Thanks for the context (cc @TheSavior)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants