You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The previous version of async act detection left an open hanging act scope, which broke tests and expectations. This PR delays the detection until it's been called at least once.
"It looks like you're using a version of react-dom that supports the \\"act\\" function, but not an awaitable version of \\"act\\" which you will need. Please upgrade to at least [email protected] to remove this warning.",
30
-
],
31
-
]
32
-
`)
30
+
Array [
31
+
Array [
32
+
Array [
33
+
"sigil",
34
+
],
35
+
],
36
+
Array [
37
+
"It looks like you're using a version of react-dom that supports the \\"act\\" function, but not an awaitable version of \\"act\\" which you will need. Please upgrade to at least [email protected] to remove this warning.",
// so for versions that don't have act from test utils
@@ -38,32 +17,101 @@ function actPolyfill(cb) {
38
17
constact=reactAct||actPolyfill
39
18
40
19
letyouHaveBeenWarned=false
41
-
// this will not avoid warnings that react-dom 16.8.0 logs for triggering
42
-
// state updates asynchronously, but at least we can tell people they need
43
-
// to upgrade to avoid the warnings.
44
-
asyncfunctionasyncActPolyfill(cb){
45
-
// istanbul-ignore-next
46
-
if(
47
-
!youHaveBeenWarned&&
48
-
actSupported&&
49
-
reactDomSixteenPointNineIsReleased
50
-
){
51
-
// if act is supported and async act isn't and they're trying to use async
52
-
// act, then they need to upgrade from 16.8 to 16.9.
53
-
// This is a seemless upgrade, so we'll add a warning
54
-
console.error(
55
-
`It looks like you're using a version of react-dom that supports the "act" function, but not an awaitable version of "act" which you will need. Please upgrade to at least [email protected] to remove this warning.`,
56
-
)
57
-
youHaveBeenWarned=true
20
+
letisAsyncActSupported=null
21
+
22
+
functionasyncAct(cb){
23
+
if(actSupported===true){
24
+
if(isAsyncActSupported===null){
25
+
returnnewPromise((resolve,reject)=>{
26
+
// patch console.error here
27
+
constoriginalConsoleError=console.error
28
+
console.error=functionerror(...args){
29
+
/* if console.error fired *with that specific message* */
30
+
if(
31
+
args[0].indexOf(
32
+
'Warning: Do not await the result of calling ReactTestUtils.act',
33
+
)===0
34
+
){
35
+
// v16.8.6
36
+
isAsyncActSupported=false
37
+
}elseif(
38
+
args[0].indexOf(
39
+
'Warning: The callback passed to ReactTestUtils.act(...) function must not return anything',
40
+
)===0
41
+
){
42
+
// no-op
43
+
}else{
44
+
originalConsoleError.call(console,args)
45
+
}
46
+
}
47
+
letcbReturn
48
+
constresult=reactAct(()=>{
49
+
cbReturn=cb()
50
+
returncbReturn
51
+
})
52
+
53
+
result.then(()=>{
54
+
console.error=originalConsoleError
55
+
// if it got here, it means async act is supported
56
+
isAsyncActSupported=true
57
+
resolve()
58
+
},reject)
59
+
60
+
// 16.8.6's act().then() doesn't call a resolve handler, so we need to manually flush here, sigh
// if act is supported and async act isn't and they're trying to use async
67
+
// act, then they need to upgrade from 16.8 to 16.9.
68
+
// This is a seemless upgrade, so we'll add a warning
69
+
console.error(
70
+
`It looks like you're using a version of react-dom that supports the "act" function, but not an awaitable version of "act" which you will need. Please upgrade to at least [email protected] to remove this warning.`,
71
+
)
72
+
youHaveBeenWarned=true
73
+
}
74
+
75
+
cbReturn.then(()=>{
76
+
// a faux-version.
77
+
// todo - copy https://github.com/facebook/react/blob/master/packages/shared/enqueueTask.js
0 commit comments