Reimplement act without mock Scheduler
#21714
Merged
+423
−1,004
Conversation
| }); | ||
| expect(container.innerHTML).toBe('0'); | ||
| // Flush the pending timers | ||
| await act(async () => { |
| } | ||
|
|
||
| await act(() => { | ||
| render(<App />, container); |
acdlite
Jun 22, 2021
Author
Member
This is actually a new feature. There was no inherent reason this wasn't already supported. This is nice because usually an act scope doesn't need to be async, but if the effects trigger microtasks you might still want to await that.
|
Comparing: 422e0bb...7641eec Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: Expand to show
|
c38eabe
to
3400ee6
|
Think I might need to add the isomorphic module in this PR to fix the dev tools tests. I forgot they involve multiple renderers. |
e83ad98
to
6c91e94
act should work without mock Scheduleract without mock Scheduler
|
LGTM, pair reviewed offline online |
Currently, in a React 18 root, `act` only works if you mock the Scheduler package. This was because we didn't want to add additional checks at runtime. But now that the `act` testing API is dev-only, we can simplify its implementation. Now when an update is wrapped with `act`, React will bypass Scheduler entirely and push its tasks onto a special internal queue. Then, when the outermost `act` scope exists, we'll flush that queue. I also removed the "wrong act" warning, because the plan is to move `act` to an isomorphic entry point, simlar to `startTransition`. That's not directly related to this PR, but I didn't want to bother re-implementing that warning only to immediately remove it. I'll add the isomorphic API in a follow up. Note that the internal version of `act` that we use in our own tests still depends on mocking the Scheduler package, because it needs to work in production. I'm planning to move that implementation to a shared (internal) module, too.
06f7b4f
into
facebook:master
2 of 22 checks passed
2 of 22 checks passed
ci/circleci: RELEASE_CHANNEL_stable_yarn_build
Your tests are queued behind your running builds
Details
ci/circleci: yarn_test--r=experimental --env=production
Your tests are queued behind your running builds
Details
ci/circleci: yarn_test--r=stable --env=development
Your tests are queued behind your running builds
Details
ci/circleci: yarn_test--r=stable --env=development --persistent
Your tests are queued behind your running builds
Details
ci/circleci: yarn_test--r=www-classic --env=development --variant=false
Your tests are queued behind your running builds
Details
ci/circleci: yarn_test--r=www-classic --env=development --variant=true
CircleCI is running your tests
Details
ci/circleci: yarn_test--r=www-classic --env=production --variant=false
Your tests are queued behind your running builds
Details
ci/circleci: yarn_test--r=www-classic --env=production --variant=true
Your tests are queued behind your running builds
Details
ci/circleci: yarn_test--r=www-modern --env=development --variant=false
Your tests are queued behind your running builds
Details
ci/circleci: yarn_test--r=www-modern --env=development --variant=true
CircleCI is running your tests
Details
ci/circleci: yarn_test--r=www-modern --env=production --variant=false
Your tests are queued behind your running builds
Details
ci/circleci: yarn_test--r=www-modern --env=production --variant=true
Your tests are queued behind your running builds
Details
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.
Based on #21703
Currently, in a React 18 root,
actonly works if you mock the Scheduler package. This was because we didn't want to add additional checks at runtime.But now that the
acttesting API is dev-only, we can simplify its implementation.Now when an update is wrapped with
act, React will bypass Scheduler entirely and push its tasks onto a special internal queue. Then, when the outermostactscope exists, we'll flush that queue.I also removed the "wrong act" warning, because the plan is to move
actto an isomorphic entry point, similar tostartTransition. That's not directly related to this PR, but I didn't want to bother re-implementing that warning only to immediately remove it.I'll add the isomorphic API in a follow up.
Note that the internal version of
actthat we use in our own tests still depends on mocking the Scheduler package, because it needs to work in production. I'm planning to move that implementation to a shared (internal) module, too.