Skip to content

Commit 350e79f

Browse files
authored
Merge pull request #3089 from reduxjs/v2.0-integration
2 parents cf24419 + 0fa46d4 commit 350e79f

File tree

285 files changed

+14756
-8470
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

285 files changed

+14756
-8470
lines changed

.codesandbox/ci.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
"github/reduxjs/rtk-github-issues-example",
66
"/examples/query/react/basic",
77
"/examples/query/react/advanced",
8-
"/examples/action-listener/counter"
8+
"/examples/action-listener/counter",
9+
"/examples/publish-ci/cra5"
910
],
10-
"node": "14",
11+
"node": "16",
1112
"buildCommand": "build:packages",
1213
"packages": [
1314
"packages/toolkit",

.github/workflows/tests.yml

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
runs-on: ubuntu-latest
3131
strategy:
3232
matrix:
33-
node: ['16.x']
33+
node: ['18.x']
3434

3535
steps:
3636
- name: Checkout repo
@@ -47,7 +47,7 @@ jobs:
4747

4848
# Read existing version, reuse that, add a Git short hash
4949
- name: Set build version to Git commit
50-
run: node scripts/writeGitVersion.js $(git rev-parse --short HEAD)
50+
run: node scripts/writeGitVersion.mjs $(git rev-parse --short HEAD)
5151

5252
- name: Check updated version
5353
run: jq .version package.json
@@ -67,7 +67,7 @@ jobs:
6767
strategy:
6868
fail-fast: false
6969
matrix:
70-
node: ['16.x']
70+
node: ['18.x']
7171
steps:
7272
- name: Checkout repo
7373
uses: actions/checkout@v2
@@ -91,7 +91,7 @@ jobs:
9191
- name: Install build artifact
9292
run: yarn workspace @reduxjs/toolkit add $(pwd)/package.tgz
9393

94-
- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json ./jest.config.js ./src/tests/*.* ./src/query/tests/*.*
94+
- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json ./vitest.config.ts ./src/tests/*.* ./src/query/tests/*.*
9595

9696
- name: Run tests, against dist
9797
run: yarn test
@@ -104,8 +104,8 @@ jobs:
104104
strategy:
105105
fail-fast: false
106106
matrix:
107-
node: ['16.x']
108-
ts: ['4.1', '4.2', '4.3', '4.4', '4.5', '4.6', '4.7', '4.8', '4.9.5', '5.0', '5.1', '5.2']
107+
node: ['18.x']
108+
ts: ['4.7', '4.8', '4.9', '5.0', '5.1', '5.2', '5.3']
109109
steps:
110110
- name: Checkout repo
111111
uses: actions/checkout@v2
@@ -133,7 +133,7 @@ jobs:
133133
- name: Show installed RTK versions
134134
run: yarn info @reduxjs/toolkit
135135

136-
- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json ./jest.config.js ./src/tests/*.* ./src/query/tests/*.*
136+
- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json ./vitest.config.ts ./src/tests/*.* ./src/query/tests/*.*
137137

138138
- name: Test types
139139
run: |
@@ -148,17 +148,8 @@ jobs:
148148
strategy:
149149
fail-fast: false
150150
matrix:
151-
node: ['16.x']
152-
example:
153-
[
154-
'cra4',
155-
'cra5',
156-
'next',
157-
'vite',
158-
'node-standard',
159-
'node-esm',
160-
'are-the-types-wrong',
161-
]
151+
node: ['18.x']
152+
example: ['cra4', 'cra5', 'next', 'vite', 'node-standard', 'node-esm']
162153
defaults:
163154
run:
164155
working-directory: ./examples/publish-ci/${{ matrix.example }}
@@ -190,10 +181,43 @@ jobs:
190181
run: yarn add ./package.tgz
191182

192183
- name: Show installed RTK versions
193-
run: yarn info @reduxjs/toolkit
184+
run: yarn info @reduxjs/toolkit && yarn why @reduxjs/toolkit
194185

195186
- name: Build example
196-
run: yarn build
187+
run: NODE_OPTIONS=--openssl-legacy-provider yarn build
197188

198189
- name: Run test step
199190
run: yarn test
191+
192+
are-the-types-wrong:
193+
name: Check package config with are-the-types-wrong
194+
195+
needs: [build]
196+
runs-on: ubuntu-latest
197+
strategy:
198+
fail-fast: false
199+
matrix:
200+
node: ['18.x']
201+
steps:
202+
- name: Checkout repo
203+
uses: actions/checkout@v2
204+
205+
- name: Use node ${{ matrix.node }}
206+
uses: actions/setup-node@v2
207+
with:
208+
node-version: ${{ matrix.node }}
209+
cache: 'yarn'
210+
211+
- name: Install deps
212+
run: yarn install
213+
214+
- uses: actions/download-artifact@v2
215+
with:
216+
name: package
217+
path: packages/toolkit
218+
219+
- name: show folder
220+
run: ls -l .
221+
222+
- name: Run are-the-types-wrong
223+
run: yarn attw ./package.tgz --format table --ignore-rules false-cjs
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
diff --git a/src/index.js b/src/index.js
2+
index 90ff7fa3d7d4fa62dbbf638958ae4e28abd089a8..28434687b5163b7472e86bdb11bed69e0868e660 100644
3+
--- a/src/index.js
4+
+++ b/src/index.js
5+
@@ -1,4 +1,4 @@
6+
-import { mockConsole, createConsole } from './pure';
7+
+import { mockConsole, createConsole } from './pure.js';
8+
9+
// Keep an instance of the original console and export it
10+
const originalConsole = global.console;
11+
diff --git a/src/pure.js b/src/pure.js
12+
index b00ea2abbaea833e336676aa46e7ced2d59d6d88..42b83ed83fa16cf2234571500fe09868debd9f01 100644
13+
--- a/src/pure.js
14+
+++ b/src/pure.js
15+
@@ -228,10 +228,11 @@ export function restore() {
16+
global.console = global.originalConsole;
17+
}
18+
19+
+/*
20+
if (typeof expect === 'function' && typeof expect.extend === 'function') {
21+
expect.extend({
22+
toMatchInlineSnapshot(received, ...args) {
23+
- /* ------- Workaround for custom inline snapshot matchers ------- */
24+
+ // Workaround for custom inline snapshot matchers
25+
const error = new Error();
26+
const stacks = error.stack.split('\n');
27+
28+
@@ -245,7 +246,6 @@ if (typeof expect === 'function' && typeof expect.extend === 'function') {
29+
error.stack = stacks.join('\n');
30+
31+
const context = Object.assign(this, { error });
32+
- /* -------------------------------------------------------------- */
33+
34+
const testingConsoleInstance =
35+
(received && received.testingConsole) || received;
36+
@@ -270,3 +270,4 @@ if (typeof expect === 'function' && typeof expect.extend === 'function') {
37+
},
38+
});
39+
}
40+
+*/
41+
\ No newline at end of file

docs/api/actionCreatorMiddleware.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export default function (state = {}, action: any) {
4747
import {
4848
configureStore,
4949
createActionCreatorInvariantMiddleware,
50+
Tuple,
5051
} from '@reduxjs/toolkit'
5152
import reducer from './reducer'
5253

@@ -62,6 +63,6 @@ const actionCreatorMiddleware = createActionCreatorInvariantMiddleware({
6263

6364
const store = configureStore({
6465
reducer,
65-
middleware: [actionCreatorMiddleware],
66+
middleware: () => new Tuple(actionCreatorMiddleware),
6667
})
6768
```

docs/api/autoBatchEnhancer.mdx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,9 @@ const counterSlice = createSlice({
4848
})
4949
const { incrementBatched, decrementUnbatched } = counterSlice.actions
5050

51+
// includes batch enhancer by default, as of RTK 2.0
5152
const store = configureStore({
5253
reducer: counterSlice.reducer,
53-
// highlight-start
54-
enhancers: (existingEnhancers) => {
55-
// Add the autobatch enhancer to the store setup
56-
return existingEnhancers.concat(autoBatchEnhancer())
57-
},
58-
// highlight-end
5954
})
6055
```
6156

@@ -74,6 +69,25 @@ type AutoBatchOptions =
7469
export type autoBatchEnhancer = (options?: AutoBatchOptions) => StoreEnhancer
7570
```
7671
72+
:::tip
73+
As of RTK 2.0, the `autoBatchEnhancer` is included by default when calling `configureStore`.
74+
75+
This means to configure it, you should instead pass an callback that receives `getDefaultEnhancers` and calls it with your desired settings.
76+
77+
```ts title="Configuring autoBatchEnhancer with getDefaultEnhancers"
78+
import { configureStore } from '@reduxjs/toolkit'
79+
80+
const store = configureStore({
81+
reducer: () => 0,
82+
enhancers: (getDefaultEnhancers) =>
83+
getDefaultEnhancers({
84+
autoBatch: { type: 'tick' },
85+
}),
86+
})
87+
```
88+
89+
:::
90+
7791
Creates a new instance of the autobatch store enhancer.
7892

7993
Any action that is tagged with `action.meta[SHOULD_AUTOBATCH] = true` will be treated as "low-priority", and a notification callback will be queued. The enhancer will delay notifying subscribers until either:
@@ -140,4 +154,4 @@ This allows Redux users to selectively tag certain actions for effective batchin
140154
141155
### RTK Query and Batching
142156
143-
RTK Query already marks several of its key internal action types as batchable. If you add the `autoBatchEnhancer` to the store setup, it will improve the overall UI performance, especially when rendering large lists of components that use the RTKQ query hooks.
157+
RTK Query already marks several of its key internal action types as batchable. By adding the `autoBatchEnhancer` to the store setup, it improves the overall UI performance, especially when rendering large lists of components that use the RTKQ query hooks.

docs/api/codemods.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ hide_title: true
99

1010
# Codemods
1111

12-
Per [the description in `1.9.0-alpha.0`](https://github.com/reduxjs/redux-toolkit/releases/tag/v1.9.0-alpha.0), we plan to remove the "object" argument from `createReducer` and `createSlice.extraReducers` in the future RTK 2.0 major version. In `1.9.0-alpha.0`, we added a one-shot runtime warning to each of those APIs.
12+
Per [the description in `1.9.0`](https://github.com/reduxjs/redux-toolkit/releases/tag/v1.9.0), we have removed the "object" argument from `createReducer` and `createSlice.extraReducers` in the RTK 2.0 major version. We've also added a new optional form of `createSlice.reducers` that uses a callback instead of an object.
1313

1414
To simplify upgrading codebases, we've published a set of codemods that will automatically transform the deprecated "object" syntax into the equivalent "builder" syntax.
1515

16-
The codemods package is available on NPM as [**`@reduxjs/rtk-codemods`**](https://www.npmjs.com/package/@reduxjs/rtk-codemods). It currently contains two codemods: `createReducerBuilder` and `createSliceBuilder`.
16+
The codemods package is available on NPM as [**`@reduxjs/rtk-codemods`**](https://www.npmjs.com/package/@reduxjs/rtk-codemods). It currently contains these codemods:
17+
18+
- `createReducerBuilder`: migrates `createReducer` calls that use the removed object syntax to the builder callback syntax
19+
- `createSliceBuilder`: migrates `createSlice` calls that use the removed object syntax for `extraReducers` to the builder callback syntax
20+
- `createSliceReducerBuilder`: migrates `createSlice` calls that use the still-standard object syntax for `reducers` to the optional new builder callback syntax, including uses of prepared reducers
1721

1822
To run the codemods against your codebase, run `npx @reduxjs/rtk-codemods <TRANSFORM NAME> path/of/files/ or/some**/*glob.js`.
1923

0 commit comments

Comments
 (0)