Skip to content

Commit 66d031d

Browse files
committed
Drop support for React < 18.0.0-rc.1
1 parent 97b1c80 commit 66d031d

File tree

9 files changed

+48
-452
lines changed

9 files changed

+48
-452
lines changed

.github/workflows/validate.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ on:
1212
pull_request: {}
1313
jobs:
1414
main:
15-
continue-on-error: ${{ matrix.react != 'latest' }}
15+
continue-on-error: ${{ matrix.react != 'current' }}
1616
# ignore all-contributors PRs
1717
if: ${{ !contains(github.head_ref, 'all-contributors') }}
1818
strategy:
1919
fail-fast: false
2020
matrix:
2121
# TODO: relax `'16.9.1'` to `16` once GitHub has 16.9.1 cached. 16.9.0 is broken due to https://github.com/nodejs/node/issues/40030
2222
node: [12, 14, '16.9.1']
23-
react: [latest, next, experimental]
23+
react: [current, next, experimental]
2424
runs-on: ubuntu-latest
2525
steps:
2626
- name: 🛑 Cancel Previous Runs
@@ -47,6 +47,7 @@ jobs:
4747
# https://reactjs.org/blog/2019/10/22/react-release-channels.html#using-the-next-channel-for-integration-testing
4848
- name: ⚛️ Setup react
4949
run: npm install react@${{ matrix.react }} react-dom@${{ matrix.react }}
50+
if: ${{ matrix.react != 'current' }}
5051

5152
- name: ▶️ Run validate script
5253
run: npm run validate

jest.config.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

package.json

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@
5353
"dotenv-cli": "^4.0.0",
5454
"kcd-scripts": "^11.1.0",
5555
"npm-run-all": "^4.1.5",
56-
"react": "^17.0.1",
57-
"react-dom": "^17.0.1",
56+
"react": "18.0.0-rc.1",
57+
"react-dom": "18.0.0-rc.1",
5858
"rimraf": "^3.0.2",
5959
"typescript": "^4.1.2"
6060
},
6161
"peerDependencies": {
62-
"react": "*",
63-
"react-dom": "*"
62+
"react": "18.0.0-rc.1",
63+
"react-dom": "18.0.0-rc.1"
6464
},
6565
"eslintConfig": {
6666
"extends": "./node_modules/kcd-scripts/eslint.js",
@@ -69,14 +69,6 @@
6969
"react/no-adjacent-inline-elements": "off",
7070
"import/no-unassigned-import": "off",
7171
"import/named": "off",
72-
"import/no-unresolved": [
73-
"error",
74-
{
75-
"ignore": [
76-
"react-dom/client"
77-
]
78-
}
79-
],
8072
"testing-library/no-container": "off",
8173
"testing-library/no-dom-import": "off",
8274
"testing-library/no-unnecessary-act": "off",

src/__tests__/new-act.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jest.mock('react-dom/test-utils', () => ({
88

99
beforeEach(() => {
1010
jest.resetModules()
11-
asyncAct = require('../act-compat').asyncAct
11+
asyncAct = require('../act-compat').default
1212
jest.spyOn(console, 'error').mockImplementation(() => {})
1313
})
1414

src/__tests__/no-act.js

Lines changed: 0 additions & 100 deletions
This file was deleted.

src/__tests__/old-act.js

Lines changed: 0 additions & 142 deletions
This file was deleted.

src/__tests__/render.js

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as React from 'react'
22
import ReactDOM from 'react-dom'
3-
import ReactDOMClient from 'react-dom/client'
43
import ReactDOMServer from 'react-dom/server'
54
import {fireEvent, render, screen} from '../'
65

@@ -110,23 +109,6 @@ test('flushes useEffect cleanup functions sync on unmount()', () => {
110109
expect(spy).toHaveBeenCalledTimes(1)
111110
})
112111

113-
test('throws if `legacyRoot: false` is used with an incomaptible version', () => {
114-
const isConcurrentReact = typeof ReactDOMClient.createRoot === 'function'
115-
116-
const performConcurrentRender = () => render(<div />, {legacyRoot: false})
117-
118-
// eslint-disable-next-line jest/no-if -- jest doesn't support conditional tests
119-
if (isConcurrentReact) {
120-
// eslint-disable-next-line jest/no-conditional-expect -- yes, jest still doesn't support conditional tests
121-
expect(performConcurrentRender).not.toThrow()
122-
} else {
123-
// eslint-disable-next-line jest/no-conditional-expect -- yes, jest still doesn't support conditional tests
124-
expect(performConcurrentRender).toThrowError(
125-
`Attempted to use concurrent React with \`react-dom@${ReactDOM.version}\`. Be sure to use the \`next\` or \`experimental\` release channel (https://reactjs.org/docs/release-channels.html).`,
126-
)
127-
}
128-
})
129-
130112
test('can be called multiple times on the same container', () => {
131113
const container = document.createElement('div')
132114

@@ -169,3 +151,28 @@ test('hydrate will make the UI interactive', () => {
169151

170152
expect(container).toHaveTextContent('clicked:1')
171153
})
154+
155+
test('legacyRoot uses legacy ReactDOM.render', () => {
156+
jest.spyOn(console, 'error').mockImplementation(() => {})
157+
render(<div />, {legacyRoot: true})
158+
159+
expect(console.error).toHaveBeenCalledTimes(1)
160+
expect(console.error).toHaveBeenNthCalledWith(
161+
1,
162+
"Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot",
163+
)
164+
})
165+
166+
test('legacyRoot uses legacy ReactDOM.hydrate', () => {
167+
jest.spyOn(console, 'error').mockImplementation(() => {})
168+
const ui = <div />
169+
const container = document.createElement('div')
170+
container.innerHTML = ReactDOMServer.renderToString(ui)
171+
render(ui, {container, hydrate: true, legacyRoot: true})
172+
173+
expect(console.error).toHaveBeenCalledTimes(1)
174+
expect(console.error).toHaveBeenNthCalledWith(
175+
1,
176+
"Warning: ReactDOM.hydrate is no longer supported in React 18. Use hydrateRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot",
177+
)
178+
})

0 commit comments

Comments
 (0)