Skip to content

Commit bff87d3

Browse files
committed
Merge remote-tracking branch 'upstream/v2.0-integration' into eature/EntityAdapter-DraftableEn...
2 parents 9b2a56f + eae9bda commit bff87d3

File tree

248 files changed

+11703
-7955
lines changed

Some content is hidden

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

248 files changed

+11703
-7955
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: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -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
@@ -105,7 +105,7 @@ jobs:
105105
fail-fast: false
106106
matrix:
107107
node: ['16.x']
108-
ts: ['4.1', '4.2', '4.3', '4.4', '4.5', '4.6', '4.7', '4.8', '4.9.2-rc']
108+
ts: ['4.7', '4.8', '4.9', '5.0']
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: |
@@ -149,16 +149,7 @@ jobs:
149149
fail-fast: false
150150
matrix:
151151
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-
]
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,34 @@ 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
196187
run: 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: ['16.x']
201+
steps:
202+
- name: Checkout repo
203+
uses: actions/checkout@v3
204+
205+
- uses: actions/download-artifact@v2
206+
with:
207+
name: package
208+
path: packages/toolkit
209+
210+
- name: show folder
211+
run: ls -l .
212+
213+
- name: Run are-the-types-wrong
214+
run: npx @arethetypeswrong/cli ./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: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface CounterState {
2727

2828
const counterSlice = createSlice({
2929
name: 'counter',
30-
initialState: { value: 0 } satisfies CounterState as CounterState,
30+
initialState: { value: 0 } as CounterState,
3131
reducers: {
3232
incrementBatched: {
3333
// Batched, low-priority
@@ -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.

0 commit comments

Comments
 (0)