Skip to content

Commit

Permalink
Merge pull request #3089 from reduxjs/v2.0-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson authored Dec 4, 2023
2 parents cf24419 + 0fa46d4 commit 350e79f
Show file tree
Hide file tree
Showing 285 changed files with 14,756 additions and 8,470 deletions.
5 changes: 3 additions & 2 deletions .codesandbox/ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"github/reduxjs/rtk-github-issues-example",
"/examples/query/react/basic",
"/examples/query/react/advanced",
"/examples/action-listener/counter"
"/examples/action-listener/counter",
"/examples/publish-ci/cra5"
],
"node": "14",
"node": "16",
"buildCommand": "build:packages",
"packages": [
"packages/toolkit",
Expand Down
64 changes: 44 additions & 20 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: ['16.x']
node: ['18.x']

steps:
- name: Checkout repo
Expand All @@ -47,7 +47,7 @@ jobs:

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

- name: Check updated version
run: jq .version package.json
Expand All @@ -67,7 +67,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['16.x']
node: ['18.x']
steps:
- name: Checkout repo
uses: actions/checkout@v2
Expand All @@ -91,7 +91,7 @@ jobs:
- 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 ./jest.config.js ./src/tests/*.* ./src/query/tests/*.*
- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json ./vitest.config.ts ./src/tests/*.* ./src/query/tests/*.*

- name: Run tests, against dist
run: yarn test
Expand All @@ -104,8 +104,8 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['16.x']
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']
node: ['18.x']
ts: ['4.7', '4.8', '4.9', '5.0', '5.1', '5.2', '5.3']
steps:
- name: Checkout repo
uses: actions/checkout@v2
Expand Down Expand Up @@ -133,7 +133,7 @@ jobs:
- name: Show installed RTK versions
run: yarn info @reduxjs/toolkit

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

- name: Test types
run: |
Expand All @@ -148,17 +148,8 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['16.x']
example:
[
'cra4',
'cra5',
'next',
'vite',
'node-standard',
'node-esm',
'are-the-types-wrong',
]
node: ['18.x']
example: ['cra4', 'cra5', 'next', 'vite', 'node-standard', 'node-esm']
defaults:
run:
working-directory: ./examples/publish-ci/${{ matrix.example }}
Expand Down Expand Up @@ -190,10 +181,43 @@ jobs:
run: yarn add ./package.tgz

- name: Show installed RTK versions
run: yarn info @reduxjs/toolkit
run: yarn info @reduxjs/toolkit && yarn why @reduxjs/toolkit

- name: Build example
run: yarn build
run: NODE_OPTIONS=--openssl-legacy-provider yarn build

- name: Run test step
run: yarn test

are-the-types-wrong:
name: Check package config with are-the-types-wrong

needs: [build]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node: ['18.x']
steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Use node ${{ matrix.node }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
cache: 'yarn'

- name: Install deps
run: yarn install

- uses: actions/download-artifact@v2
with:
name: package
path: packages/toolkit

- name: show folder
run: ls -l .

- name: Run are-the-types-wrong
run: yarn attw ./package.tgz --format table --ignore-rules false-cjs
41 changes: 41 additions & 0 deletions .yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
diff --git a/src/index.js b/src/index.js
index 90ff7fa3d7d4fa62dbbf638958ae4e28abd089a8..28434687b5163b7472e86bdb11bed69e0868e660 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,4 +1,4 @@
-import { mockConsole, createConsole } from './pure';
+import { mockConsole, createConsole } from './pure.js';

// Keep an instance of the original console and export it
const originalConsole = global.console;
diff --git a/src/pure.js b/src/pure.js
index b00ea2abbaea833e336676aa46e7ced2d59d6d88..42b83ed83fa16cf2234571500fe09868debd9f01 100644
--- a/src/pure.js
+++ b/src/pure.js
@@ -228,10 +228,11 @@ export function restore() {
global.console = global.originalConsole;
}

+/*
if (typeof expect === 'function' && typeof expect.extend === 'function') {
expect.extend({
toMatchInlineSnapshot(received, ...args) {
- /* ------- Workaround for custom inline snapshot matchers ------- */
+ // Workaround for custom inline snapshot matchers
const error = new Error();
const stacks = error.stack.split('\n');

@@ -245,7 +246,6 @@ if (typeof expect === 'function' && typeof expect.extend === 'function') {
error.stack = stacks.join('\n');

const context = Object.assign(this, { error });
- /* -------------------------------------------------------------- */

const testingConsoleInstance =
(received && received.testingConsole) || received;
@@ -270,3 +270,4 @@ if (typeof expect === 'function' && typeof expect.extend === 'function') {
},
});
}
+*/
\ No newline at end of file
3 changes: 2 additions & 1 deletion docs/api/actionCreatorMiddleware.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default function (state = {}, action: any) {
import {
configureStore,
createActionCreatorInvariantMiddleware,
Tuple,
} from '@reduxjs/toolkit'
import reducer from './reducer'

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

const store = configureStore({
reducer,
middleware: [actionCreatorMiddleware],
middleware: () => new Tuple(actionCreatorMiddleware),
})
```
28 changes: 21 additions & 7 deletions docs/api/autoBatchEnhancer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,9 @@ const counterSlice = createSlice({
})
const { incrementBatched, decrementUnbatched } = counterSlice.actions

// includes batch enhancer by default, as of RTK 2.0
const store = configureStore({
reducer: counterSlice.reducer,
// highlight-start
enhancers: (existingEnhancers) => {
// Add the autobatch enhancer to the store setup
return existingEnhancers.concat(autoBatchEnhancer())
},
// highlight-end
})
```

Expand All @@ -74,6 +69,25 @@ type AutoBatchOptions =
export type autoBatchEnhancer = (options?: AutoBatchOptions) => StoreEnhancer
```
:::tip
As of RTK 2.0, the `autoBatchEnhancer` is included by default when calling `configureStore`.
This means to configure it, you should instead pass an callback that receives `getDefaultEnhancers` and calls it with your desired settings.
```ts title="Configuring autoBatchEnhancer with getDefaultEnhancers"
import { configureStore } from '@reduxjs/toolkit'

const store = configureStore({
reducer: () => 0,
enhancers: (getDefaultEnhancers) =>
getDefaultEnhancers({
autoBatch: { type: 'tick' },
}),
})
```

:::

Creates a new instance of the autobatch store enhancer.

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:
Expand Down Expand Up @@ -140,4 +154,4 @@ This allows Redux users to selectively tag certain actions for effective batchin
### RTK Query and Batching
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.
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.
8 changes: 6 additions & 2 deletions docs/api/codemods.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ hide_title: true

# Codemods

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.
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.

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

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`.
The codemods package is available on NPM as [**`@reduxjs/rtk-codemods`**](https://www.npmjs.com/package/@reduxjs/rtk-codemods). It currently contains these codemods:

- `createReducerBuilder`: migrates `createReducer` calls that use the removed object syntax to the builder callback syntax
- `createSliceBuilder`: migrates `createSlice` calls that use the removed object syntax for `extraReducers` to the builder callback syntax
- `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

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

Expand Down
Loading

0 comments on commit 350e79f

Please sign in to comment.