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
Don't use closures in DevTools injection #18278
Conversation
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 0c43f3e:
|
Details of bundled changes.Comparing: 5474a83...0c43f3e react-art
react-test-renderer
react-dom
react-native-renderer
react-reconciler
ReactDOM: size: 0.0%, gzip: -0.0% Size changes (experimental) |
Details of bundled changes.Comparing: 5474a83...0c43f3e react-art
react-test-renderer
react-native-renderer
react-dom
react-reconciler
Size changes (stable) |
Looks like fast-refresh is mutating the hook object. :( |
if ( | ||
injectedHook && | ||
typeof injectedHook.onScheduleFiberRoot === 'function' | ||
) { |
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.
Could sent pointers to e.g. onScheduleFiberRoot
directly so we wouldn't have to do the property access
if (typeof onScheduleFiberRoot === 'function') {
onScheduleFiberRoot(rendererID, root, chilren);
}
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 think Seb is saying that property gets mutated by Fast Refresh. (I don't actually remember if it does but I guess?)
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.
sure
So, landing this? |
Nested closures are tricky. They're not super efficient and when they share scope between multiple closures they're hard for a compiler to optimize. It's also unclear how many versions will be created. By hoisting things out an just make it simple calls the compiler can do a much better job.
Thanks for this change. FYI - It is also fixing a bug with React Fast refresh which happen when In our setup, we have 2 bundles - one contains React (loaded first) and a second one containing the Fast Refresh runtime (+ app code). Since Fast refresh runtime is executed after React it wasn't working fully. Beside this little quirk Fast Refresh is really great and reliable:+1: |
Nested closures are tricky. They're not super efficient and when they share scope between multiple closures they're hard for a compiler to optimize. It's also unclear how many versions will be created.
By hoisting things out an just make it simple calls the compiler can do a much better job.
Before
After
Note that it's still sub-optimal because the config object gets created even though it should be able to be inlined by Closure Compiler. We should really switch this per-renderer config object to be a HostConfig the whole thing instead to avoid that.
The injected object is also created outside the condition so it's always created even if no devtools is present.