Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upawait act(async () => ...) #14853
Merged
await act(async () => ...) #14853
+1,639
−600
Conversation
This comment has been minimized.
This comment has been minimized.
sizebot
commented
Feb 14, 2019
•
|
ReactDOM: size: 0.0%, gzip: 0.0% Details of bundled changes.Comparing: 9307932...e49e043 react-dom
react-art
react-native-renderer
react-test-renderer
react-noop-renderer
react-reconciler
Generated by |
| act = ReactTestUtils.act; | ||
| }); | ||
|
|
||
| describe('sync', () => { |
This comment has been minimized.
This comment has been minimized.
| ); | ||
| }); | ||
| }); | ||
| describe('async', () => { |
This comment has been minimized.
This comment has been minimized.
| }); | ||
|
|
||
| await sleep(1000); | ||
| expect(console.error).toHaveBeenCalledTimes(1); |
This comment has been minimized.
This comment has been minimized.
threepointone
Feb 14, 2019
Author
Contributor
but nuh uh, we warn anyway (todo - match on actual warning message)
This comment has been minimized.
This comment has been minimized.
|
Assuming there’s no big problem with the approach, I’m going to close this pr later today and continue working on it in my branch. Please feel free to leave comments! |
This comment has been minimized.
This comment has been minimized.
|
(nevermind, I'll leave it open) |
| @@ -517,173 +515,4 @@ describe('ReactTestUtils', () => { | |||
| ReactTestUtils.renderIntoDocument(<Component />); | |||
| expect(mockArgs.length).toEqual(0); | |||
| }); | |||
|
|
|||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
spoke with dan, moving the |
This comment has been minimized.
This comment has been minimized.
|
The failing test is odd, investigating. |
Merged
This was referenced Dec 19, 2019
This was referenced Jan 2, 2020
This was referenced Jan 9, 2020
This was referenced Jan 16, 2020
This was referenced Jan 27, 2020
NMinhNguyen
referenced
this pull request
in NMinhNguyen/react-shallow-renderer
Jan 29, 2020
This took a while, but I'm happy I went through it. Some key moments - recursively flushing effects, flushing microtasks on each async turn, and my team's uncompromising philosophy on code reuse. Really happy with this. I still want to expand test coverage, and I have some more small related todos, but this is good to land. On to the next one. Soundtrack to landing this - https://open.spotify.com/track/0MF8I8OUo8kytiOo8aSHYq?si=gSWqUheKQbiQDXzptCXHTg * hacked up act(async () => {...}) * move stuff around * merge changes * abstract .act warnings and stuff. all renderers. pass all tests. * move testutils.act back into testutils * move into scheduler, rename some bits * smaller bundle * a comment for why we don't do typeof === 'function' * fix test * pass tests - fire, prod * lose actContainerElement * tighter * write a test for TestRenderer it's an odd one, because not only does sync act not flush effects correctly, but the async one does (wut). verified it's fine with the dom version. * lint * rewrote to move flushing logic closer to the renderer the scheduler's `flushPassiveEffects` didn't work as expected for the test renderer, so I decided to go back to the hack (rendering a dumb container) This also makes reactdom not as heavy (by a few bytes, but still). * move it around so the delta isn't too bad * cleanups fix promise chaining propagate errors correctly test for thenable the 'right' way more tests! tidier! ponies! * Stray comment * recursively flush effects * fixed tests * lint, move noop.act into react-reconciler * microtasks when checking if called, s/called/calledLog, cleanup * pass fb lint we could have globally changed our eslint config to assume Promise is available, but that means we expect a promise polyfill on the page, and we don't yet. this code is triggered only in jest anyway, and we're fairly certain Promise will be available there. hence, the once-off disable for the check * shorter timers, fix a test, test for Promise * use global.Promise for existence check * flush microtasks * a version that works in browsers (that support postMessage) I also added a sanity fixture inside fixtures/dom/ mostly for me. * hoist flushEffectsAndMicroTasks * pull out tick logic from ReactFiberScheduler * fix await act (...sync) hanging - fix a hang when awaiting sync logic - a better async/await test for test renderer * feedback changes - use node's setImmediate if available - a warning if MessageChannel isn't available - rename some functions * pass lint/flow checks (without requiring a Promise polyfill/exclusion) * prettier the prettiest, even. * use globalPromise for the missed await warning * __DEV__ check for didWarnAboutMessageChannel * thenables and callbacks instead of promises, pass flow/lint * tinier. better. - pulled most bits out of FiberScheduler - actedUpdates uses callbacks now * pass build validation * augh prettier * golfing 7 more chars * Test that effects are not flushed without also flushing microtasks * export doesHavePendingPassiveEffects, nits * createAct() * dead code * missed in merge? * lose the preflushing bits * ugh prettier * removed `actedUpdates()`, created shared/actingUpdatesScopeDepth * rearrange imports so builds work, remove the hack versions of flushPassiveEffects * represent actingUpdatesScopeDepth as a tuple [number] * use a shared flag on React.__SECRET... * remove createAct, setup act for all relevant renderers * review feedback shared/enqueueTask import ReactSharedInternals from 'shared/ReactSharedInternals'; simpler act() internals ReactSharedInternals.ReactShouldWarnActingUpdates * move act() implementation into createReactNoop * warnIfNotCurrentlyActingUpdatesInDev condition check order
This was referenced Jan 31, 2020
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.
threepointone commentedFeb 14, 2019
•
edited
TODO -
(repasting from the group)
I hacked together an asynchronous version of
act(...), and it's kinda nice.You've seen the synchronous version -
This still works, and gives the same warnings. But if you pass an
asyncfunction -Neat! I set it up so if you don't
awaitthe result fromact, a warning gets triggered (withsetImmediate) to do so. That makes it a bit harder to have rogue asyncact()calls in the ether.You can nest
act()calls -I implemented a cheap form of unrolling safety, so if a previous
act()gets closed before any subsequentact()calls, a warning gets triggered. This should prevent most interleaving attempts, and maintain a tree-like shape ofact()blocks.pros -
cons -
act()call... which might be fine?)