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 diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index 1d3a9ef2fa..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", @@ -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", 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[] = []