Skip to content
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

Merged
merged 9 commits into from
Dec 3, 2019

Conversation

sebmarkbage
Copy link
Collaborator

@sebmarkbage sebmarkbage commented Nov 28, 2019

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.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 28, 2019

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:

Sandbox Source
React Configuration

@sizebot
Copy link

sizebot commented Nov 28, 2019

No significant bundle size changes to report.

Size changes (experimental)

Generated by 🚫 dangerJS against 1ea22f8

@sizebot
Copy link

sizebot commented Nov 28, 2019

No significant bundle size changes to report.

Size changes (stable)

Generated by 🚫 dangerJS against 1ea22f8

When accessed, this should always be set. This could enforced by storing
this on the dispatcher for example.
do {
didScheduleRenderPhaseUpdate = false;

invariant(
numberOfReRenders < RE_RENDER_LIMIT,
Copy link
Collaborator

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

Copy link
Collaborator Author

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

@sebmarkbage sebmarkbage merged commit f523b2e into facebook:master Dec 3, 2019
trueadm pushed a commit to trueadm/react that referenced this pull request Dec 4, 2019
* 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
trueadm pushed a commit to trueadm/react that referenced this pull request Dec 4, 2019
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants