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
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(()=>{})
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
+
// this will not avoid warnings that react-dom 16.8.0 logs for triggering
38
+
// state updates asynchronously, but at least we can tell people they need
39
+
// to upgrade to avoid the warnings.
40
+
asyncfunctionasyncActPolyfill(cb){
41
+
if(actSupported){
42
+
// if act is supported and async act isn't and they're trying to use async
43
+
// act, then they need to upgrade from 16.8 to 16.9.
44
+
// This is a seemless upgrade, so we'll add a warning
45
+
console.error(
46
+
`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 react-dom@16.9.0 to remove this warning.`,
0 commit comments