-
Notifications
You must be signed in to change notification settings - Fork 47k
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
[React Native] Inline calls to FabricUIManager in shared code #15490
Conversation
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 think we want any inline requires in React code as this will mess with future builds. Is there another way we can solve this?
We already have a few inline requires for our www/fbsource forks. I didn't think there was harm adding another one temporarily. |
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.
Yea, no this is not the right fix. It's effectively a side-effect in the module init which is problematic for many reasons. Like if we eagerly initialize more for better start up perf.
A better fix would be to inline global.nativeFabricUIManager
directly instead of relying on the module system working like if it's a function call.
Previous bad ideas are never good precedence for future bad ideas. That's how small bad ideas leak and become large bad ideas. |
Uh, ok. I was not aware that we had established this particular thing as a "bad idea" 😄 |
Details of bundled changes.Comparing: 3f058de...9242802 react-native-renderer
Generated by 🚫 dangerJS |
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'm surprised lint and Flow lets you do this.
Would be nice to declare it as a top level global property here:
https://github.com/facebook/react/blob/master/scripts/flow/react-native-host-hooks.js#L100
Apparently accessing something with Also, apparently |
My previous commit (1b2159a) caused crashes when running in Fabric when navigating from a paper screen to a fabric screen.
The NativeMethodsMixin and ReactNativeComponent code is shared in both the Paper renderer and Fabric renderer. The previous commit caused the top of the paper renderer to include
require('FabricUIManager')
.FabricUIManager.js
is essentially just:Because this code was getting called at the top of the paper renderer,
FabricUIManager
was exportingundefined
.When transitioning to a Fabric screen, c++ installs that global, and then the FabricRenderer has this check:
This manifested as a crash
cannot access registerEventHandle of undefined
. This is because FabricUIManager was cached from being accessed too early.The "right" fix
We will fix this correctly by having native always, on startup, define and set the object:
When starting with the paper renderer, these functions will just throw.
Then, when Fabric is loaded, it will replace the implementation of those functions with the actual correct implementation.
This will ensure there is no timing issues with when JavaScript reads and caches the value of the global or any of the functions.
We will need to ensure we replace the implementations of the functions and not redefine them because we will need to support JS reading the functions early like this:
Reading them early, and then calling them after Fabric has loaded will need to work.
The "short term" fix
This PR includes the short term fix which is to inline these requires so that it isn't called early. Normally this would happen by default as we run everything inline requires however this file is blacklisted from inline requires in React Native as it is faster this way.
Test Plan:
Opened Marketplace (this worked before this change)
Navigating from Catalyst (paper) to Fabric RNTester (fabric). This crashed before with the error above and no longer crashes.