-
Notifications
You must be signed in to change notification settings - Fork 47.4k
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
Remove canonical check in fiber host component #16914
Conversation
What if someone passes a Fabric instance to Paper's |
Is that possible? I know there is some cross calling that can happen as demonstrated in All the cases in those tests are from calling the public exports of the renderer with a Fabric instance which happens all the time today, in fact, nothing is calling the public exports of the Fabric renderer in JS.
This has to continue working, but I'm not sure how in practice you'd call a method on a paper instance with a fabric instance. Are you able to have two subtrees (or roots? 😮) one in paper and one in Fabric? Like, I'm sure a test like this would trigger the problem, but is this a case that could actually happen / we should think about?
|
I haven't thought about it much and it's pretty late. :-) I'd double check with Seb but you have more context on this. |
Something I realized this morning is that this test wouldn't actually trigger that code:
because the instance you get back from a fabric ref doesn't have a I added
So passing a fabric ref to the paper function wouldn't enter the canonical branch. The only time you need the canonical check is when explicitly using Also, I tried really hard to validate this with an actual test and couldn't write one. I tried adding something to the
It seems like having multiple renderers running like this is not an explicitly supported approach. @gaearon, thanks for pushing me to deeply understand this even more. I feel even more confident in this change now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel like I have as much context as you do on this, Eli. Stamping to unblock for now. We can always roll this change back if it causes problems after a sync.
I believe this is a dead branch.
I added this code in #15126 and I think it has always been wrong. At least, I'm not sure what could trigger it.
I think I was pattern matching from this code in NativeMethodsMixin https://github.com/facebook/react/blob/master/packages/react-native-renderer/src/NativeMethodsMixin.js#L166-L182
Simplified:
The only thing in the codebase that creates an object with a canonical key is createInstance in ReactFabricHostConfig.
canonical
is only set on Fabric host components, not paper ones.In order to get that instance, you must call
findHostInstance
. NativeMethodsMixin and ReactNativeComponent both usefindHostInstance
in order to detect whether an instance is created with the paper renderer or the fabric renderer to know which API to call.FiberHostComponent only needs to deal with paper components and the FabricHostComponent only needs to deal with the fabric components, so this check for canonical in paper is unnecessary.
When I wrote this code I also added tests for calling this function passing an argument created with all three
NativeMethodsMixin
,ReactNativeComponent
, and a host component. If I add athrow
to this if statement, none of the tests fail.