Skip to content

fix(act): wait until react-dom-16.9.0 is released #344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions src/__tests__/old-act.js
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
13 changes: 11 additions & 2 deletions src/act-compat.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
Expand All @@ -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
Expand All @@ -53,6 +61,7 @@ async function asyncActPolyfill(cb) {
act(() => {})
}

// istanbul ignore next
const asyncAct = asyncActSupported ? reactAct : asyncActPolyfill

export default act
Expand Down
2 changes: 2 additions & 0 deletions src/react-dom-16.9.0-is-released.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// we don't want to warn until [email protected] is actually released
export const reactDomSixteenPointNineIsReleased = false