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
"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.",
Copy file name to clipboardExpand all lines: src/act-compat.js
+38-3Lines changed: 38 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -2,8 +2,23 @@ import React from 'react'
2
2
importReactDOMfrom'react-dom'
3
3
4
4
letreactAct
5
+
letactSupported=false
6
+
letasyncActSupported=false
5
7
try{
6
8
reactAct=require('react-dom/test-utils').act
9
+
actSupported=reactAct!==undefined
10
+
11
+
constoriginalError=console.error
12
+
leterrorCalled=false
13
+
console.error=()=>{
14
+
errorCalled=true
15
+
}
16
+
console.error.calls=[]
17
+
reactAct(()=>({then: ()=>{}})).then(/* istanbul ignore next */()=>{})
18
+
if(!errorCalled){
19
+
asyncActSupported=true
20
+
}
21
+
console.error=originalError
7
22
}catch(error){
8
23
// ignore, this is to support old versions of react
9
24
}
@@ -19,8 +34,28 @@ function actPolyfill(cb) {
19
34
20
35
constact=reactAct||actPolyfill
21
36
22
-
functionrtlAct(...args){
23
-
returnact(...args)
37
+
letyouHaveBeenWarned=false
38
+
// this will not avoid warnings that react-dom 16.8.0 logs for triggering
39
+
// state updates asynchronously, but at least we can tell people they need
40
+
// to upgrade to avoid the warnings.
41
+
asyncfunctionasyncActPolyfill(cb){
42
+
if(!youHaveBeenWarned&&actSupported){
43
+
// if act is supported and async act isn't and they're trying to use async
44
+
// act, then they need to upgrade from 16.8 to 16.9.
45
+
// This is a seemless upgrade, so we'll add a warning
46
+
console.error(
47
+
`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.`,
0 commit comments