-
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
Use fewer global variables in Hooks #17480
Use fewer global variables in Hooks #17480
Conversation
This means that it's harder to find it since it's not in the dispatch function's stack but we can add a DEV only one for that if we really need it. Alternatively, we can check it in against the renderUpdates queue.
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 1ea22f8:
|
When accessed, this should always be set. This could enforced by storing this on the dispatcher for example.
e73d0f2
to
25aa2e5
Compare
do { | ||
didScheduleRenderPhaseUpdate = false; | ||
|
||
invariant( | ||
numberOfReRenders < RE_RENDER_LIMIT, |
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.
The stack on this error is less useful 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.
In the commit I mentioned that we could add a DEV warning to help this. However, I think I could do a follow up of this that uses the dispatcher to error instead in this: #17484
* We don't need the global state for this * Move componentUpdateQueue and sideEffectTag out of global state * Move firstWorkInProgressHook off global state * Move remainingExpirationTime off global state * Reset fiber to its current state if it throws * Move rerender error check to avoid global state This means that it's harder to find it since it's not in the dispatch function's stack but we can add a DEV only one for that if we really need it. Alternatively, we can check it in against the renderUpdates queue. * Move next___Hook out of global state * Assert that currentlyRenderingFiber is always set When accessed, this should always be set. This could enforced by storing this on the dispatcher for example. * Add another test just to be safe
* We don't need the global state for this * Move componentUpdateQueue and sideEffectTag out of global state * Move firstWorkInProgressHook off global state * Move remainingExpirationTime off global state * Reset fiber to its current state if it throws * Move rerender error check to avoid global state This means that it's harder to find it since it's not in the dispatch function's stack but we can add a DEV only one for that if we really need it. Alternatively, we can check it in against the renderUpdates queue. * Move next___Hook out of global state * Assert that currentlyRenderingFiber is always set When accessed, this should always be set. This could enforced by storing this on the dispatcher for example. * Add another test just to be safe
Module level variables is an exception that we should use sparingly. It will make using multiple threads in a threaded implementation infeasible, harder to port to stricter languages, it's harder to reason about the performance and it is kind of hard to reason about whether these are allowed to diverge from the main state.