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

await act(async () => ...) #14853

Merged
merged 71 commits into from Apr 2, 2019
Merged
Changes from 1 commit
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
9791a6b
hacked up act(async () => {...})
threepointone Feb 12, 2019
49876c3
move stuff around
threepointone Feb 14, 2019
d16525a
Merge remote-tracking branch 'upstream/master' into async-act
threepointone Feb 14, 2019
0a1b308
Merge remote-tracking branch 'upstream/master' into async-act
threepointone Feb 14, 2019
5cf26ba
merge changes
threepointone Feb 14, 2019
d2ea31e
abstract .act warnings and stuff. all renderers. pass all tests.
threepointone Feb 15, 2019
c7e07c7
Merge remote-tracking branch 'upstream/master' into async-act
threepointone Feb 15, 2019
3c4142b
move testutils.act back into testutils
threepointone Feb 15, 2019
331d9eb
move into scheduler, rename some bits
threepointone Feb 15, 2019
d0daebf
smaller bundle
threepointone Feb 15, 2019
00c2fd6
a comment for why we don't do typeof === 'function'
threepointone Feb 15, 2019
788fd73
fix test
threepointone Feb 15, 2019
cd2f191
pass tests - fire, prod
threepointone Feb 15, 2019
6af7e80
lose actContainerElement
threepointone Feb 15, 2019
a8fb80b
tighter
threepointone Feb 15, 2019
955d590
write a test for TestRenderer
threepointone Feb 16, 2019
ee8086a
lint
threepointone Feb 16, 2019
441e597
rewrote to move flushing logic closer to the renderer
threepointone Feb 16, 2019
c07174b
move it around so the delta isn't too bad
threepointone Feb 16, 2019
95bffdf
Merge remote-tracking branch 'upstream/master' into async-act
threepointone Feb 25, 2019
0fe5318
cleanups
threepointone Feb 25, 2019
c0a4573
Stray comment
threepointone Feb 25, 2019
1b1a896
recursively flush effects
threepointone Feb 28, 2019
06d8391
Merge branch 'async-act' of github.com:threepointone/react into async…
threepointone Feb 28, 2019
6c2bcc5
Merge remote-tracking branch 'upstream/master' into async-act
threepointone Mar 1, 2019
3028209
fixed tests
threepointone Mar 1, 2019
7da103b
lint, move noop.act into react-reconciler
threepointone Mar 1, 2019
cc51fca
microtasks when checking if called, s/called/calledLog, cleanup
threepointone Mar 4, 2019
91a3ff4
pass fb lint
threepointone Mar 4, 2019
a5e84e2
Merge remote-tracking branch 'upstream/master' into async-act
threepointone Mar 6, 2019
8688517
shorter timers, fix a test, test for Promise
threepointone Mar 6, 2019
308d14f
use global.Promise for existence check
threepointone Mar 8, 2019
edfafa5
Merge remote-tracking branch 'upstream/master' into async-act
threepointone Mar 8, 2019
13f43fd
Merge remote-tracking branch 'upstream/master' into async-act
threepointone Mar 11, 2019
6283cf4
flush microtasks
threepointone Mar 13, 2019
38bf178
a version that works in browsers (that support postMessage)
threepointone Mar 13, 2019
ab521ce
hoist flushEffectsAndMicroTasks
threepointone Mar 13, 2019
ae46998
pull out tick logic from ReactFiberScheduler
threepointone Mar 14, 2019
2779bae
fix await act (...sync) hanging
threepointone Mar 15, 2019
d36b8d5
feedback changes
threepointone Mar 15, 2019
3766812
pass lint/flow checks (without requiring a Promise polyfill/exclusion)
threepointone Mar 15, 2019
f66ed55
Merge remote-tracking branch 'upstream/master' into async-act
threepointone Mar 15, 2019
ad55c26
prettier
threepointone Mar 15, 2019
a29f008
use globalPromise for the missed await warning
threepointone Mar 15, 2019
a777344
__DEV__ check for didWarnAboutMessageChannel
threepointone Mar 15, 2019
aa37d51
thenables and callbacks instead of promises, pass flow/lint
threepointone Mar 15, 2019
c4afc5f
tinier. better.
threepointone Mar 16, 2019
7998527
pass build validation
threepointone Mar 16, 2019
e37602b
augh prettier
threepointone Mar 16, 2019
58ecb21
golfing 7 more chars
threepointone Mar 16, 2019
04a4e91
Test that effects are not flushed without also flushing microtasks
acdlite Mar 16, 2019
cdcbc7c
Merge remote-tracking branch 'upstream/master' into async-act
threepointone Mar 16, 2019
6a8cc02
Merge branch 'async-act' of github.com:threepointone/react into async…
threepointone Mar 16, 2019
429bda2
export doesHavePendingPassiveEffects, nits
threepointone Mar 16, 2019
adc92b4
createAct()
threepointone Mar 24, 2019
c1ee84e
dead code
threepointone Mar 24, 2019
53d3fbf
Merge remote-tracking branch 'upstream/master' into async-act
threepointone Mar 25, 2019
ad548b5
missed in merge?
threepointone Mar 25, 2019
8e4ea16
Merge remote-tracking branch 'upstream/master' into async-act
threepointone Mar 27, 2019
573a991
lose the preflushing bits
threepointone Mar 27, 2019
91d40cd
ugh prettier
threepointone Mar 27, 2019
c97cee4
removed `actedUpdates()`, created shared/actingUpdatesScopeDepth
threepointone Mar 31, 2019
65d9d0c
Merge remote-tracking branch 'upstream/master' into async-act
threepointone Mar 31, 2019
efffcb4
rearrange imports so builds work, remove the hack versions of flushPa…
threepointone Apr 1, 2019
d01d0c9
represent actingUpdatesScopeDepth as a tuple [number]
threepointone Apr 1, 2019
8737f7d
use a shared flag on React.__SECRET...
threepointone Apr 2, 2019
5a9081a
remove createAct, setup act for all relevant renderers
threepointone Apr 2, 2019
44236c9
review feedback
threepointone Apr 2, 2019
068561a
move act() implementation into createReactNoop
threepointone Apr 2, 2019
abf1e3a
Merge remote-tracking branch 'upstream/master' into async-act
threepointone Apr 2, 2019
e49e043
warnIfNotCurrentlyActingUpdatesInDev condition check order
threepointone Apr 2, 2019
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

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.
  • Loading branch information...
threepointone committed Feb 16, 2019
commit 955d590b28708371d524d8111da1516a040b04ad
@@ -234,6 +234,29 @@ describe('act', () => {
});
});

it('can handle async await', async () => {
function App() {
let [ctr, setCtr] = React.useState(0);
async function someAsyncFunction() {
await sleep(0);
setCtr(1);
}
React.useEffect(() => {
someAsyncFunction();
}, []);
return ctr;
}
const el = document.createElement('div');

await act(async () => {
act(() => {
ReactDOM.render(<App />, el);
});
await sleep(100);
});
expect(el.innerHTML).toEqual('1');
});

it('warns if you do not await an act call', async () => {
spyOnDevAndProd(console, 'error');
act(async () => {});
@@ -17,6 +17,14 @@ const React = require('react');
const ReactCache = require('react-cache');
const ReactTestRenderer = require('react-test-renderer');

function sleep(period) {
return new Promise(resolve => {
setTimeout(() => {
resolve(true);
}, period);
});
}

describe('ReactTestRenderer', () => {
it('should warn if used to render a ReactDOM portal', () => {
const container = document.createElement('div');
@@ -44,6 +52,37 @@ describe('ReactTestRenderer', () => {
});
expect(root.toJSON()).toEqual('1');
});
describe('async', () => {
beforeEach(() => {
jest.useRealTimers()
})
afterEach(() => {
jest.useFakeTimers()
})
it('should work async too', async () => {
function App() {
let [ctr, setCtr] = React.useState(0);
async function someAsyncFunction() {
await sleep(100);
setCtr(1);
}
React.useEffect(() => {
someAsyncFunction();
}, []);
return ctr;
}
let root;
await ReactTestRenderer.act(async () => {
// todo - I don't understand why a nested async act call
// flushes the effect correctly
await ReactTestRenderer.act(async () => {
root = ReactTestRenderer.create(<App />);
});
await sleep(200);
});
expect(root.toJSON()).toEqual('1');
});
});
});

describe('timed out Suspense hidden subtrees should not be observable via toJSON', () => {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.