Skip to content
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

Migrate to React 19 #4409

Draft
wants to merge 57 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
e4de96b
Update `react` and `react-dom` to v19 beta
aryaemami59 May 11, 2024
6ace22c
Set `@types/react` and `@types/react-dom` to temporary types packages
aryaemami59 May 11, 2024
0a93873
Add `react` and `react-dom` to `devDependencies` of toolkit
aryaemami59 May 11, 2024
47f95fd
Update `react-redux` to 9.1.2
aryaemami59 May 11, 2024
ef3aa47
Run tests against different versions of React during CI
aryaemami59 May 11, 2024
fbde6cb
Bump `@testing-library/react` to version 15.0.7
aryaemami59 May 11, 2024
05c1696
Bump `@testing-library/user-event` to 14.5.2
aryaemami59 May 11, 2024
e8acd1f
Bump `jsdom` to 24.0.0
aryaemami59 May 11, 2024
7c82cba
Remove unnecessary `React` import from `cleanup.test.tsx`
aryaemami59 May 11, 2024
ba8a1e4
Remove unnecessary `tick` and `runAllTimers` from `cleanup.test.tsx`
aryaemami59 May 11, 2024
9a56382
Remove redundant `act` wrappers around `fireEvent` method calls
aryaemami59 May 11, 2024
7527bc8
Workaround issue `userEvent` not working with fake timers
aryaemami59 May 11, 2024
83ff0f1
Fix test names in `fork.test.ts`
aryaemami59 May 11, 2024
b5fbcd8
Fix issue with `console` spy inside `buildHooks.test.tsx`
aryaemami59 May 14, 2024
ced2a4d
Fix `act` related issues in `buildHooks.test.tsx`
aryaemami59 May 14, 2024
de0ecb9
Fix issues related to spies and stubbing environments in `utils.spec.ts`
aryaemami59 May 14, 2024
c8489bb
Fix `console` spy related issues in `effectScenarios.test.ts`
aryaemami59 May 14, 2024
edf74cc
Fix `console` spy related issues in `listenerMiddleware.test.ts`
aryaemami59 May 14, 2024
59a61b5
Fix `console` spy related issues in `createApi.test.ts`
aryaemami59 May 14, 2024
c5e5a26
Fix wrong `test.each` and `describe.each` calls
aryaemami59 May 14, 2024
be40596
Fix `console` spy related issues in `devWarnings.test.tsx`
aryaemami59 May 14, 2024
caaab51
Fix `console` spy related issues in `injectEndpoints.test.tsx`
aryaemami59 May 14, 2024
3376ab4
Fix issue with test names in `queryFn.test.tsx`
aryaemami59 May 14, 2024
28d08d2
Remove failing assertion in `buildHooks.test.tsx`
aryaemami59 May 14, 2024
f3f2c14
Migrate docs to React 19
aryaemami59 May 14, 2024
01cb3cd
Update `peerDependencies` of toolkit to include React v19
aryaemami59 May 14, 2024
803f2a2
Bump React to the new rc
aryaemami59 May 16, 2024
50be30d
Test against rc version of React during CI
aryaemami59 May 16, 2024
a6543f6
Fix issues related to `console` spies in `createAsyncThunk.test.ts`
aryaemami59 May 16, 2024
086e59d
Fix issues related to stubbing envs in `createAsyncThunk.test.ts`
aryaemami59 May 16, 2024
5ad0da9
Fix issues related to `console` spies in `createReducer.test.ts`
aryaemami59 May 16, 2024
4c84ebd
Fix issues related to stubbing envs in `createReducer.test.ts`
aryaemami59 May 16, 2024
b9bd487
Fix issues related to `console` spies in `createSlice.test.ts`
aryaemami59 May 16, 2024
c3bd5a7
Fix issues related to stubbing envs in `createSlice.test.ts`
aryaemami59 May 16, 2024
15c68e5
Fix issues related to `console` spies in `immutableStateInvariantMidd…
aryaemami59 May 16, 2024
8899359
Fix issues related to `console` spies in `serializableStateInvariantM…
aryaemami59 May 16, 2024
bd502fb
Remove `vi.resetAllMocks()` call from `utils.spec.ts`
aryaemami59 May 16, 2024
a53abba
Change `.toHaveBeenCalledTimes(1)` to `.toHaveBeenCalledOnce()`
aryaemami59 May 16, 2024
5f9946f
Change `.toHaveBeenCalledTimes(0)` to `.not.toHaveBeenCalled()`
aryaemami59 May 16, 2024
7f8a6b7
Bump `immer` in lockfile
aryaemami59 May 16, 2024
d0a2a99
Bump `@types/react` and `@types/react-dom` to rc versions
aryaemami59 May 25, 2024
ad40fbc
Bump `@types/react` and `@types/react-dom` to rc versions during CI
aryaemami59 May 25, 2024
20de5a3
Bump `jsdom` to version 24.1.0
aryaemami59 Jun 3, 2024
662ea44
Bump `@testing-library/react` to version 16.0.0
aryaemami59 Jun 3, 2024
201990f
Bump `@testing-library/dom` to version 10.3.2
aryaemami59 Jul 20, 2024
5a36a02
Bump `@testing-library/dom` to version 10.4.0
aryaemami59 Jul 23, 2024
6054697
Bump `jsdom` to version 24.1.1
aryaemami59 Jul 23, 2024
0b27310
Add `areErrorsEqual` equality tester
aryaemami59 Aug 1, 2024
c627876
Fix `console` spy related issues in `fakeBaseQuery.test.tsx`
aryaemami59 Aug 1, 2024
9887f34
Fix `console` spy related issues in `queryFn.test.tsx`
aryaemami59 Aug 1, 2024
f91d181
Remove `satisfies` operators in `queryFn.test.tsx`
aryaemami59 Aug 1, 2024
10190d4
Remove `jest-snapshot` from `resolutions` field
aryaemami59 Aug 1, 2024
b869bac
Remove `console-testing-library` as it is no longer needed
aryaemami59 Aug 2, 2024
e340937
Update lockfile
aryaemami59 Aug 6, 2024
d64caae
Bump `jsdom` to version 25.0.0
aryaemami59 Aug 27, 2024
23c32ed
Update lockfile
aryaemami59 Sep 4, 2024
60e7bff
Bump `@testing-library/react` to version 16.0.1
aryaemami59 Sep 4, 2024
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
50 changes: 44 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,27 @@ jobs:
path: packages/toolkit/package.tgz

test-dist:
name: Test against dist
name: Run local tests against build artifact (React ${{ matrix.react.version }})
needs: [build]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node: ['20.x']
react:
[
{
version: '^18',
types: ^18,
react-dom: { version: '^18', types: '^18' },
},
{
version: 'rc',
types: 'npm:types-react@rc',
react-dom: { version: 'rc', types: 'npm:types-react-dom@rc' },
},
]

steps:
- name: Checkout repo
uses: actions/checkout@v4
Expand All @@ -82,17 +96,23 @@ jobs:
- name: Install deps
run: yarn install

- uses: actions/download-artifact@v4
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: package
path: packages/toolkit

- run: ls -lah
- name: Check folder contents
run: ls -lah

- name: Install React ${{ matrix.react.version }} and React-DOM ${{ matrix.react.react-dom.version }}
run: yarn up react@${{ matrix.react.version }} react-dom@${{ matrix.react.react-dom.version }} @types/react@${{ matrix.react.types }} @types/react-dom@${{ matrix.react.react-dom.types }}

- name: Install build artifact
run: yarn workspace @reduxjs/toolkit add $(pwd)/package.tgz

- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json
- name: Erase path aliases
run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json

- name: Run tests, against dist
env:
Expand All @@ -103,7 +123,7 @@ jobs:
run: rm -rf dist && yarn tsc -p . --moduleResolution Bundler --module ESNext --noEmit false --declaration --emitDeclarationOnly --outDir dist --target ESNext && rm -rf dist

test-types:
name: 'Test Types: TS ${{ matrix.ts }}'
name: 'Test Types: TS ${{ matrix.ts }} and React ${{ matrix.react.version }}'

needs: [build]
runs-on: ubuntu-latest
Expand All @@ -112,6 +132,20 @@ jobs:
matrix:
node: ['20.x']
ts: ['4.7', '4.8', '4.9', '5.0', '5.1', '5.2', '5.3', '5.4', '5.5']
react:
[
{
version: '^18',
types: ^18,
react-dom: { version: '^18', types: '^18' },
},
{
version: 'rc',
types: 'npm:types-react@rc',
react-dom: { version: 'rc', types: 'npm:types-react-dom@rc' },
},
]

steps:
- name: Checkout repo
uses: actions/checkout@v4
Expand All @@ -125,6 +159,9 @@ jobs:
- name: Install deps
run: yarn install

- name: Install React ${{ matrix.react.version }} and React-DOM ${{ matrix.react.react-dom.version }}
run: yarn up react@${{ matrix.react.version }} react-dom@${{ matrix.react.react-dom.version }} @types/react@${{ matrix.react.types }} @types/react-dom@${{ matrix.react.react-dom.types }}

- name: Install TypeScript ${{ matrix.ts }}
run: yarn add typescript@${{ matrix.ts }}

Expand All @@ -139,7 +176,8 @@ jobs:
- name: Show installed RTK versions
run: yarn info @reduxjs/toolkit

- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json
- name: Erase path aliases
run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json

- name: Test types
env:
Expand Down
68 changes: 0 additions & 68 deletions .yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch

This file was deleted.

26 changes: 0 additions & 26 deletions .yarn/patches/console-testing-library__npm_0.3.1.patch

This file was deleted.

2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"devDependencies": {
"@manaflair/redux-batch": "^1.0.0",
"@types/nanoid": "^2.1.0",
"@types/react": "^18.0",
"@types/react": "npm:types-react@rc",
"async-mutex": "^0.3.2",
"axios": "^0.20.0",
"formik": "^2.1.5",
Expand Down
50 changes: 34 additions & 16 deletions docs/tutorials/quick-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,30 @@ export const store = configureStore({

// file: index.tsx
import React from 'react'
import ReactDOM from 'react-dom'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App'
// highlight-start
import { store } from './app/store'
import { Provider } from 'react-redux'
// highlight-end

ReactDOM.render(
// highlight-next-line
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
)
const container = document.getElementById('root')

if (container) {
const root = createRoot(container)

root.render(
// highlight-next-line
<Provider store={store}>
<App />
</Provider>,
)
} else {
throw new Error(
"Root element with ID 'root' was not found in the document. Ensure there is a corresponding HTML element with the ID 'root' in your HTML file.",
)
}
```

### Create a Redux State Slice
Expand Down Expand Up @@ -214,18 +223,27 @@ export type RootState = ReturnType<typeof store.getState>

// file: index.tsx noEmit
import React from 'react'
import ReactDOM from 'react-dom'
import { createRoot } from 'react-dom/client'
import { Counter } from './features/counter/Counter'
import { store } from './app/store'
import { Provider } from 'react-redux'

ReactDOM.render(
// highlight-next-line
<Provider store={store}>
<Counter />
</Provider>,
document.getElementById('root')
)
const container = document.getElementById('root')

if (container) {
const root = createRoot(container)

root.render(
// highlight-next-line
<Provider store={store}>
<Counter />
</Provider>,
)
} else {
throw new Error(
"Root element with ID 'root' was not found in the document. Ensure there is a corresponding HTML element with the ID 'root' in your HTML file.",
)
}

// file: features/counter/Counter.tsx
import React from 'react'
Expand Down
26 changes: 17 additions & 9 deletions docs/tutorials/rtk-query.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,28 @@ export const store = configureStore({
})

// file: index.tsx
import * as React from 'react'
import { render } from 'react-dom'
import React from 'react'
import { createRoot } from 'react-dom/client'
import { Provider } from 'react-redux'

import App from './App'
import { store } from './store'

const rootElement = document.getElementById('root')
render(
<Provider store={store}>
<App />
</Provider>,
rootElement
)
const container = document.getElementById('root')

if (container) {
const root = createRoot(container)

root.render(
<Provider store={store}>
<App />
</Provider>,
)
} else {
throw new Error(
"Root element with ID 'root' was not found in the document. Ensure there is a corresponding HTML element with the ID 'root' in your HTML file.",
)
}
```

## Use the query in a component
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/nextjs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export default function StoreProvider({
children: React.ReactNode
}) {
// highlight-start
const storeRef = useRef<AppStore>()
const storeRef = useRef<AppStore>(undefined)
if (!storeRef.current) {
// Create the store instance the first time this renders
storeRef.current = makeStore()
Expand Down
26 changes: 18 additions & 8 deletions docs/usage/usage-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,7 @@ configureStore({
If using Redux-Persist, you should specifically ignore all the action types it dispatches:

```jsx
import { createRoot } from 'react-dom/client'
import { configureStore } from '@reduxjs/toolkit'
import {
persistStore,
Expand Down Expand Up @@ -1078,14 +1079,23 @@ const store = configureStore({

let persistor = persistStore(store)

ReactDOM.render(
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<App />
</PersistGate>
</Provider>,
document.getElementById('root'),
)
const container = document.getElementById('root')

if (container) {
const root = createRoot(container)

root.render(
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<App />
</PersistGate>
</Provider>,
)
} else {
throw new Error(
"Root element with ID 'root' was not found in the document. Ensure there is a corresponding HTML element with the ID 'root' in your HTML file.",
)
}
```

Additionally, you can purge any persisted state by adding an extra reducer to the specific slice that you would like to clear when calling persistor.purge(). This is especially helpful when you are looking to clear persisted state on a dispatched logout action.
Expand Down
10 changes: 5 additions & 5 deletions examples/action-listener/counter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"dependencies": {
"@reduxjs/toolkit": "^1.8.0",
"@types/node": "^12.0.0",
"@types/react": "^18.0.12",
"@types/react-dom": "^18.0.5",
"@types/react": "npm:types-react@rc",
"@types/react-dom": "npm:types-react-dom@rc",
"clsx": "1.1.1",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-redux": "^9.1.0",
"react": "19.0.0-rc-f65ac7bd-20240826",
"react-dom": "19.0.0-rc-f65ac7bd-20240826",
"react-redux": "^9.1.2",
"react-scripts": "5.0.1",
"typescript": "~4.9"
},
Expand Down
Loading