From dc6801c2de3cf040d08e4cfe590d9dbfdc02a4dd Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Fri, 5 Apr 2019 10:41:39 -0600 Subject: [PATCH] fix(act): wait until react-dom-16.9.0 is released --- package.json | 4 ++-- src/__tests__/old-act.js | 4 ++++ src/act-compat.js | 13 +++++++++++-- src/react-dom-16.9.0-is-released.js | 2 ++ 4 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 src/react-dom-16.9.0-is-released.js diff --git a/package.json b/package.json index f226d339..ba558b87 100644 --- a/package.json +++ b/package.json @@ -55,8 +55,8 @@ "jest-dom": "3.1.3", "jest-in-case": "^1.0.2", "kcd-scripts": "1.1.2", - "react": "16.9.0-alpha.0", - "react-dom": "16.9.0-alpha.0", + "react": "^16.8.6", + "react-dom": "^16.8.6", "react-intl": "^2.8.0", "react-redux": "6.0.1", "react-router": "^5.0.0", diff --git a/src/__tests__/old-act.js b/src/__tests__/old-act.js index 5fee7fe7..d21c2bae 100644 --- a/src/__tests__/old-act.js +++ b/src/__tests__/old-act.js @@ -1,5 +1,9 @@ import {asyncAct} from '../act-compat' +jest.mock('../react-dom-16.9.0-is-released', () => ({ + reactDomSixteenPointNineIsReleased: true, +})) + jest.mock('react-dom/test-utils', () => ({ act: cb => { const promise = cb() diff --git a/src/act-compat.js b/src/act-compat.js index 7e4fbb9a..a87ee4d7 100644 --- a/src/act-compat.js +++ b/src/act-compat.js @@ -1,5 +1,6 @@ import React from 'react' import ReactDOM from 'react-dom' +import {reactDomSixteenPointNineIsReleased} from './react-dom-16.9.0-is-released' let reactAct let actSupported = false @@ -14,7 +15,9 @@ try { errorCalled = true } console.error.calls = [] - reactAct(() => ({then: () => {}})).then(/* istanbul ignore next */ () => {}) + /* istanbul ignore next */ + reactAct(() => ({then: () => {}})).then(() => {}) + /* istanbul ignore next */ if (!errorCalled) { asyncActSupported = true } @@ -39,7 +42,12 @@ let youHaveBeenWarned = false // state updates asynchronously, but at least we can tell people they need // to upgrade to avoid the warnings. async function asyncActPolyfill(cb) { - if (!youHaveBeenWarned && actSupported) { + // istanbul-ignore-next + if ( + !youHaveBeenWarned && + actSupported && + reactDomSixteenPointNineIsReleased + ) { // if act is supported and async act isn't and they're trying to use async // act, then they need to upgrade from 16.8 to 16.9. // This is a seemless upgrade, so we'll add a warning @@ -53,6 +61,7 @@ async function asyncActPolyfill(cb) { act(() => {}) } +// istanbul ignore next const asyncAct = asyncActSupported ? reactAct : asyncActPolyfill export default act diff --git a/src/react-dom-16.9.0-is-released.js b/src/react-dom-16.9.0-is-released.js new file mode 100644 index 00000000..33053dfa --- /dev/null +++ b/src/react-dom-16.9.0-is-released.js @@ -0,0 +1,2 @@ +// we don't want to warn until react-dom@16.9.0 is actually released +export const reactDomSixteenPointNineIsReleased = false