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
Member

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.

sebmarkbage added 7 commits Nov 27, 2019
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.
@codesandbox

This comment has been minimized.

Copy link

codesandbox 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

This comment has been minimized.

Copy link

sizebot commented Nov 28, 2019

No significant bundle size changes to report.

Size changes (experimental)

Generated by 🚫 dangerJS against 1ea22f8

@sizebot

This comment has been minimized.

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.
@sebmarkbage sebmarkbage force-pushed the sebmarkbage:hooks-less-global-state branch from e73d0f2 to 25aa2e5 Nov 28, 2019
do {
didScheduleRenderPhaseUpdate = false;

invariant(
numberOfReRenders < RE_RENDER_LIMIT,

This comment has been minimized.

Copy link
@acdlite

acdlite Dec 2, 2019

Member

The stack on this error is less useful now

This comment has been minimized.

Copy link
@sebmarkbage

sebmarkbage Dec 3, 2019

Author Member

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
21 checks passed
21 checks passed
ci/circleci: build Your tests passed on CircleCI!
Details
ci/circleci: build_experimental Your tests passed on CircleCI!
Details
ci/circleci: flow Your tests passed on CircleCI!
Details
ci/circleci: lint Your tests passed on CircleCI!
Details
ci/circleci: lint_build Your tests passed on CircleCI!
Details
ci/circleci: process_artifacts Your tests passed on CircleCI!
Details
ci/circleci: process_artifacts_experimental Your tests passed on CircleCI!
Details
ci/circleci: setup Your tests passed on CircleCI!
Details
ci/circleci: sizebot Your tests passed on CircleCI!
Details
ci/circleci: sizebot_experimental Your tests passed on CircleCI!
Details
ci/circleci: test_build Your tests passed on CircleCI!
Details
ci/circleci: test_build_devtools Your tests passed on CircleCI!
Details
ci/circleci: test_build_experimental Your tests passed on CircleCI!
Details
ci/circleci: test_build_prod Your tests passed on CircleCI!
Details
ci/circleci: test_build_prod_experimental Your tests passed on CircleCI!
Details
ci/circleci: test_dom_fixtures Your tests passed on CircleCI!
Details
ci/circleci: test_source Your tests passed on CircleCI!
Details
ci/circleci: test_source_experimental Your tests passed on CircleCI!
Details
ci/circleci: test_source_persistent Your tests passed on CircleCI!
Details
ci/circleci: test_source_prod Your tests passed on CircleCI!
Details
ci/codesandbox Building packages succeeded.
Details
trueadm added 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 added 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
4 participants
You can’t perform that action at this time.