Skip to content

Commit dc6801c

Browse files
author
Kent C. Dodds
committed
fix(act): wait until react-dom-16.9.0 is released
1 parent 5a88da2 commit dc6801c

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
"jest-dom": "3.1.3",
5656
"jest-in-case": "^1.0.2",
5757
"kcd-scripts": "1.1.2",
58-
"react": "16.9.0-alpha.0",
59-
"react-dom": "16.9.0-alpha.0",
58+
"react": "^16.8.6",
59+
"react-dom": "^16.8.6",
6060
"react-intl": "^2.8.0",
6161
"react-redux": "6.0.1",
6262
"react-router": "^5.0.0",

src/__tests__/old-act.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import {asyncAct} from '../act-compat'
22

3+
jest.mock('../react-dom-16.9.0-is-released', () => ({
4+
reactDomSixteenPointNineIsReleased: true,
5+
}))
6+
37
jest.mock('react-dom/test-utils', () => ({
48
act: cb => {
59
const promise = cb()

src/act-compat.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
22
import ReactDOM from 'react-dom'
3+
import {reactDomSixteenPointNineIsReleased} from './react-dom-16.9.0-is-released'
34

45
let reactAct
56
let actSupported = false
@@ -14,7 +15,9 @@ try {
1415
errorCalled = true
1516
}
1617
console.error.calls = []
17-
reactAct(() => ({then: () => {}})).then(/* istanbul ignore next */ () => {})
18+
/* istanbul ignore next */
19+
reactAct(() => ({then: () => {}})).then(() => {})
20+
/* istanbul ignore next */
1821
if (!errorCalled) {
1922
asyncActSupported = true
2023
}
@@ -39,7 +42,12 @@ let youHaveBeenWarned = false
3942
// state updates asynchronously, but at least we can tell people they need
4043
// to upgrade to avoid the warnings.
4144
async function asyncActPolyfill(cb) {
42-
if (!youHaveBeenWarned && actSupported) {
45+
// istanbul-ignore-next
46+
if (
47+
!youHaveBeenWarned &&
48+
actSupported &&
49+
reactDomSixteenPointNineIsReleased
50+
) {
4351
// if act is supported and async act isn't and they're trying to use async
4452
// act, then they need to upgrade from 16.8 to 16.9.
4553
// This is a seemless upgrade, so we'll add a warning
@@ -53,6 +61,7 @@ async function asyncActPolyfill(cb) {
5361
act(() => {})
5462
}
5563

64+
// istanbul ignore next
5665
const asyncAct = asyncActSupported ? reactAct : asyncActPolyfill
5766

5867
export default act

src/react-dom-16.9.0-is-released.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// we don't want to warn until [email protected] is actually released
2+
export const reactDomSixteenPointNineIsReleased = false

0 commit comments

Comments
 (0)