[Fresh] Track mounted roots via DevTools Hook#15928
Merged
Merged
Conversation
Details of bundled changes.Comparing: 9845437...d20de50 react-refresh
Generated by 🚫 dangerJS |
Collaborator
Author
|
Pushed a second commit. This just adds some helpers that are currently inlined in Metro in my draft. It doesn't make sense to inline them in Metro because they're more React-specific. And other integrations will need the same helpers. So I put them in the runtime too. |
These utilities will likely be needed by all module systems, so let's just put them here.
Collaborator
Author
|
Verified this works in RN. |
bvaughn
reviewed
Jun 19, 2019
| // Note that in this case it's important that renderer code runs *after* this method call. | ||
| // Otherwise, the renderer will think that there is no global hook, and won't do the injection. | ||
| globalObject.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook = { | ||
| supportsFiber: true, |
Contributor
There was a problem hiding this comment.
We should eventually remove this check in React 😆
bvaughn
approved these changes
Jun 19, 2019
Contributor
|
Changes seem good. Your recent prod-only errors are causing test-prod tests to fail though 😁 |
facebook-github-bot
pushed a commit
to facebook/react-native
that referenced
this pull request
Jun 21, 2019
Summary: This pulls in the latest package updates for Fresh. It doesn't have any user-observable behavior. The renderer is rebuilt on top of the last cherry-picked sync. I cherry-picked facebook/react#15928 on top of it. Reviewed By: rickhanlonii Differential Revision: D15901887 fbshipit-source-id: ccd974f79e4c0a2a8a8cab0d472deeaedf1e3ddd
gaearon
added a commit
to gaearon/react
that referenced
this pull request
Jun 24, 2019
* Track mounted roots via DevTools Hook * Add helper utilities to the runtime These utilities will likely be needed by all module systems, so let's just put them here. * Wrap more things in __DEV__ * Fix tests to also be DEV-only
rickhanlonii
pushed a commit
to rickhanlonii/react
that referenced
this pull request
Jun 25, 2019
* Track mounted roots via DevTools Hook * Add helper utilities to the runtime These utilities will likely be needed by all module systems, so let's just put them here. * Wrap more things in __DEV__ * Fix tests to also be DEV-only
M-i-k-e-l
pushed a commit
to M-i-k-e-l/react-native
that referenced
this pull request
Mar 10, 2020
Summary: This pulls in the latest package updates for Fresh. It doesn't have any user-observable behavior. The renderer is rebuilt on top of the last cherry-picked sync. I cherry-picked facebook/react#15928 on top of it. Reviewed By: rickhanlonii Differential Revision: D15901887 fbshipit-source-id: ccd974f79e4c0a2a8a8cab0d472deeaedf1e3ddd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The previous Fresh runtime API forced you to pass a root handle. However, that presumes that the module runtime (such as Metro) somehow is aware of all roots on the page. This isn't the case.
We could have React keep track of mounted roots. However, that might not be necessary. Here's why.
We still need some way to let the module runtime schedule refreshes. Currently this is done via DevTools Global Hook injection. DevTools (or module runtime) can set up the Global Hook. The renderer injects
scheduleHotUpdatein it. As a result, the module runtime can schedule refreshes.Since we already rely on the DevTools Hook for communication, we might as well use the fact that this Hook gives us information about all roots. Indeed, that's how DevTools itself works.
The Goal
This PR lets the module runtime do
and then
without worrying about how to track mounted roots.
Implementation
Adding
injectIntoGlobalHookto Refresh RuntimeThe goal in both cases is to grab the scheduling functionality and to track roots in the Runtime. This lets the module system (e.g. Metro) simply call
ReactRefreshRuntime.performReactRefresh()and not worry about how this connects to React.The only constraint is that
ReactRefreshRuntime.injectIntoGlobalHook()needs to run before the renderer code. The module system can guarantee it because it owns the execution order.I have added regression tests for tracking roots.
Tweaking the API exposed to DevTools
Previously, we had
scheduleHotUpdate(root, update)which included the resolution function. However, I realized this doesn't really work if you don't have aroot. For example, if you hot update a component, but no roots are mounted yet, you still want its next render to use the updated version. So you need to inject the resolution function anyway.I changed the API to:
setRefreshHandler(handler)— This sets up the family resolution function. It is called on first edit even if there are no roots.scheduleRefresh(root, update)— renamed fromscheduleHotReloadfindHostInstancesForRefresh— renamed fromfindHostInstancesForHotReloadFollow-ups
There's a few things I plan to change here later. One is to use host config for getting client rect. But this isn't critical to get in now, since I don't plan to implement this in the first Metro integration. The second one is to add a few convenience helpers to move more React-related logic out of the module runtime (e.g. Metro). I might push that a bit later but it doesn't block this PR.