-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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
warn if passive effects get queued outside of an act() call. #15631
warn if passive effects get queued outside of an act() call. #15631
Conversation
a first crack at flushing the scheduler manually from inside act(). uses unstable_flushWithoutYielding(). The tests that changes, mostly replaced toFlushAndYield(...) with toHaveYielded(). For some tests that tested the state of the tree before flushing effects (but still after updates), I replaced act() with bacthedUpdates().
of note, unstable_flushWithoutYielding now returns a boolean much like flushPassiveEffects
…shWithoutYielding
I also tried writing a test for it, but couldn't get the scheduler to unmock. included the failing test.
based on facebook#15591. of note, we don't modify our own tests to satisfy this warning, instead using a feature flag to disable the warning for some tests. this is because we're testing the actual sequencing of work in these tests, and don't want to flush everything with act().
React: size: 0.0%, gzip: -0.0% Details of bundled changes.Comparing: c7398f3...9f7a346 react
react-dom
react-art
react-native-renderer
react-test-renderer
react-noop-renderer
react-reconciler
scheduler
Generated by 🚫 dangerJS |
if (ReactShouldWarnActingUpdates.current === false) { | ||
warningWithoutStack( | ||
false, | ||
'An effect from %s inside a test was not wrapped in act(...).\n\n' + |
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.
Nit: This makes it sound like useEffect
is supposed to be wrapped in act
.
^ approved once base PR is merged |
I'm rewriting this to (hopefully) not need the feature flag. it'll mean rewriting a lot of the tests. |
@threepointone Let's land the change before updating a bunch of tests? I would prefer not to couple those. |
made an attempt at doing this without the feature flag here - #15763 |
abandoning this for #15763 |
This version uses a feature flag to disable the warning in tests. It isn't a viable options since we'd have to disable a whole lot of tests that run in yarn test-build See #15763 instead
based on #15591. this might be a bit controversial, but I agree with the reasoning. of note, we don't modify our own tests to satisfy this warning, instead using a feature flag to disable the warning for some tests. this is because we're testing the actual sequencing of work in these tests, and don't want to flush everything with act().
you probably want to see just this commit - 9f7a346