From b0a14b240ab7468cdec8565902d230b573296c98 Mon Sep 17 00:00:00 2001 From: Wase-Zahin Date: Mon, 13 May 2024 20:33:05 +0800 Subject: [PATCH 1/4] fix: fix typo --- docs/tutorials/quick-start.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/tutorials/quick-start.mdx b/docs/tutorials/quick-start.mdx index eedafecc7b..7f26aec087 100644 --- a/docs/tutorials/quick-start.mdx +++ b/docs/tutorials/quick-start.mdx @@ -49,7 +49,7 @@ npm install @reduxjs/toolkit react-redux Create a file named `src/app/store.js`. Import the `configureStore` API from Redux Toolkit. We'll start by creating an empty Redux store, and exporting it: -```ts title="app/store.js" +```ts title="app/store.ts" import { configureStore } from '@reduxjs/toolkit' export const store = configureStore({ @@ -303,4 +303,4 @@ Here's the complete counter application as a running CodeSandbox: ## What's Next? -We recommend going through [**the "Redux Essentials" and "Redux Fundamentals" tutorials in the Redux core docs**](https://redux.js.org/tutorials/index), which will give you a complete understanding of how Redux works, what Redux Toolkit does, and how to use it correctly. +We recommend going through [**the "Redux Essentials" and "Redux Fundamentals" tutorials in the Redux core docs**](https://redux.js.org/tutorials/index), which will give you a complete understanding of how Redux works, what Redux Toolkit does, and how to use it correctly. \ No newline at end of file From 87e2e59796c9297b7ef76cb4bfe414294bc029ca Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Wed, 15 May 2024 22:25:10 -0700 Subject: [PATCH 2/4] Switch vitest args to allow file filtering by name again --- packages/toolkit/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index 1d3a9ef2fa..c473d8ef06 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -103,7 +103,7 @@ "format": "prettier --write \"(src|examples)/**/*.{ts,tsx}\" \"**/*.md\"", "format:check": "prettier --list-different \"(src|examples)/**/*.{ts,tsx}\" \"docs/*/**.md\"", "lint": "eslint src examples", - "test": "vitest --run --typecheck", + "test": "vitest --typecheck --run ", "test:watch": "vitest --watch", "type-tests": "yarn tsc -p tsconfig.test.json --noEmit", "prepack": "yarn build", From 4cc7b1f01a42ad1c028d46f33768adcb8d022272 Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Wed, 15 May 2024 22:26:26 -0700 Subject: [PATCH 3/4] Fix Immer `current` usage when the value may not be a draft --- .../tests/sorted_state_adapter.test.ts | 25 +++++++++++++++++++ packages/toolkit/src/entities/utils.ts | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/toolkit/src/entities/tests/sorted_state_adapter.test.ts b/packages/toolkit/src/entities/tests/sorted_state_adapter.test.ts index cc1bf568de..fb09089ece 100644 --- a/packages/toolkit/src/entities/tests/sorted_state_adapter.test.ts +++ b/packages/toolkit/src/entities/tests/sorted_state_adapter.test.ts @@ -5,6 +5,7 @@ import { createSlice, configureStore, nanoid, + PayloadAction, } from '@reduxjs/toolkit' import type { BookModel } from './fixtures/book' import { @@ -783,6 +784,30 @@ describe('Sorted State Adapter', () => { //expect(numSorts).toBeLessThan(25_000) }) + it('should not throw an Immer `current` error when `state.ids` is a plain array', () => { + const book1: BookModel = { id: 'a', title: 'First' } + const initialState = adapter.getInitialState() + const withItems = adapter.addMany(initialState, [book1]) + const booksSlice = createSlice({ + name: 'books', + initialState, + reducers: { + testCurrentBehavior(state, action: PayloadAction) { + // Will overwrite `state.ids` with a plain array + adapter.removeAll(state) + + // will call `splitAddedUpdatedEntities` and call `current(state.ids)` + adapter.upsertMany(state, [book1]) + }, + }, + }) + + booksSlice.reducer( + initialState, + booksSlice.actions.testCurrentBehavior(book1), + ) + }) + describe('can be used mutably when wrapped in createNextState', () => { test('removeAll', () => { const withTwo = adapter.addMany(state, [TheGreatGatsby, AnimalFarm]) diff --git a/packages/toolkit/src/entities/utils.ts b/packages/toolkit/src/entities/utils.ts index 895ef2b35f..c073a17daa 100644 --- a/packages/toolkit/src/entities/utils.ts +++ b/packages/toolkit/src/entities/utils.ts @@ -47,7 +47,7 @@ export function splitAddedUpdatedEntities( ): [T[], Update[], Id[]] { newEntities = ensureEntitiesArray(newEntities) - const existingIdsArray = current(state.ids) as Id[] + const existingIdsArray = getCurrent(state.ids) as Id[] const existingIds = new Set(existingIdsArray) const added: T[] = [] From 4578c74c45e0f4cd7c6d3b156711d5eef1ded389 Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Thu, 16 May 2024 00:03:15 -0700 Subject: [PATCH 4/4] Release 2.2.5 --- packages/toolkit/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index c473d8ef06..7701141c74 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -1,6 +1,6 @@ { "name": "@reduxjs/toolkit", - "version": "2.2.4", + "version": "2.2.5", "description": "The official, opinionated, batteries-included toolset for efficient Redux development", "author": "Mark Erikson ", "license": "MIT",