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

Merged
merged 43 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
3e1a686
Update `react-redux` to 9.1.2
aryaemami59 May 11, 2024
19104b1
Run tests against different versions of React during CI
aryaemami59 May 11, 2024
3bb2014
Remove unnecessary `tick` and `runAllTimers` from `cleanup.test.tsx`
aryaemami59 May 11, 2024
c373d7b
Remove redundant `act` wrappers around `fireEvent` method calls
aryaemami59 May 11, 2024
8e5953b
Workaround issue `userEvent` not working with fake timers
aryaemami59 May 11, 2024
7e7117e
Fix test names in `fork.test.ts`
aryaemami59 May 11, 2024
657e579
Fix issue with `console` spy inside `buildHooks.test.tsx`
aryaemami59 May 14, 2024
052bb8b
Fix `act` related issues in `buildHooks.test.tsx`
aryaemami59 May 14, 2024
1bafa74
Fix issues related to spies and stubbing environments in `utils.spec.ts`
aryaemami59 May 14, 2024
d49c177
Fix `console` spy related issues in `effectScenarios.test.ts`
aryaemami59 May 14, 2024
e69a09c
Fix `console` spy related issues in `listenerMiddleware.test.ts`
aryaemami59 May 14, 2024
f8f5464
Fix `console` spy related issues in `createApi.test.ts`
aryaemami59 May 14, 2024
002c0ef
Fix wrong `test.each` and `describe.each` calls
aryaemami59 May 14, 2024
033a167
Fix `console` spy related issues in `devWarnings.test.tsx`
aryaemami59 May 14, 2024
ee7ac6b
Fix `console` spy related issues in `injectEndpoints.test.tsx`
aryaemami59 May 14, 2024
2edc4f6
Fix issue with test names in `queryFn.test.tsx`
aryaemami59 May 14, 2024
273975f
Migrate docs to React 19
aryaemami59 May 14, 2024
32e5cb6
Update `peerDependencies` of toolkit to include React v19
aryaemami59 May 14, 2024
17f6bcf
Update React and React-DOM to the new rc version
aryaemami59 May 11, 2024
fb51f2d
Fix issues related to `console` spies in `createAsyncThunk.test.ts`
aryaemami59 May 16, 2024
341dd1e
Fix issues related to stubbing envs in `createAsyncThunk.test.ts`
aryaemami59 May 16, 2024
d72d514
Fix issues related to `console` spies in `createReducer.test.ts`
aryaemami59 May 16, 2024
8b727c2
Fix issues related to stubbing envs in `createReducer.test.ts`
aryaemami59 May 16, 2024
00d2c7b
Fix issues related to `console` spies in `createSlice.test.ts`
aryaemami59 May 16, 2024
5cb8292
Fix issues related to stubbing envs in `createSlice.test.ts`
aryaemami59 May 16, 2024
4e6e0a5
Fix issues related to `console` spies in `immutableStateInvariantMidd…
aryaemami59 May 16, 2024
0b2d854
Fix issues related to `console` spies in `serializableStateInvariantM…
aryaemami59 May 16, 2024
9470fe2
Change `.toHaveBeenCalledTimes(1)` to `.toHaveBeenCalledOnce()`
aryaemami59 May 16, 2024
d194a55
Change `.toHaveBeenCalledTimes(0)` to `.not.toHaveBeenCalled()`
aryaemami59 May 16, 2024
0b01841
Set `@types/react` and `@types/react-dom` to temporary types packages
aryaemami59 May 11, 2024
7b4f651
Add `areErrorsEqual` equality tester
aryaemami59 Aug 1, 2024
0ffbdaa
Fix `console` spy related issues in `fakeBaseQuery.test.tsx`
aryaemami59 Aug 1, 2024
18ace12
Fix `console` spy related issues in `queryFn.test.tsx`
aryaemami59 Aug 1, 2024
d3ab03c
Remove `satisfies` operators in `queryFn.test.tsx`
aryaemami59 Aug 1, 2024
a182aef
Remove `jest-snapshot` from `resolutions` field
aryaemami59 Aug 1, 2024
36a83f2
Remove `console-testing-library` as it is no longer needed
aryaemami59 Aug 2, 2024
87bed72
Fix minor JSX related type issues
aryaemami59 Dec 3, 2024
7c516a0
Bump `jsdom` to version 25.0.1
aryaemami59 May 11, 2024
a54282d
Bump `@testing-library/react` to version 16.1.0
aryaemami59 Dec 6, 2024
2ef14cb
Properly `await` assertion in `tests/fork.test.ts`
aryaemami59 Dec 6, 2024
36e3bff
Properly `await` assertion in `src/query/tests/errorHandling.test.tsx`
aryaemami59 Dec 6, 2024
6410899
Migrate to React 19
aryaemami59 Dec 6, 2024
19acec8
Bump TS version in website
markerikson Dec 11, 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: '^19',
types: '^19',
react-dom: { version: '^19', types: '^19' },
},
]

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: ['5.0', '5.1', '5.2', '5.3', '5.4', '5.5']
react:
[
{
version: '^18',
types: ^18,
react-dom: { version: '^18', types: '^18' },
},
{
version: '^19',
types: '^19',
react-dom: { version: '^19', types: '^19' },
},
]

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": "^19.0.1",
"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
24 changes: 16 additions & 8 deletions docs/tutorials/rtk-query.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,27 @@ export const store = configureStore({

// file: index.tsx
import * as React from 'react'
import { render } from 'react-dom'
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": "^19.0.1",
"@types/react-dom": "^19.0.1",
"clsx": "1.1.1",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-redux": "^9.1.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-redux": "^9.1.2",
"react-scripts": "5.0.1",
"typescript": "~4.9"
},
Expand Down
Loading
Loading