Skip to content

Commit 9abfdaf

Browse files
committed
Merge branch 'master' of https://github.com/reduxjs/redux-toolkit into configs
2 parents 3339947 + 4578c74 commit 9abfdaf

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

packages/toolkit/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@reduxjs/toolkit",
3-
"version": "2.2.4",
3+
"version": "2.2.5",
44
"description": "The official, opinionated, batteries-included toolset for efficient Redux development",
55
"author": "Mark Erikson <[email protected]>",
66
"license": "MIT",
@@ -102,7 +102,7 @@
102102
"format:check": "prettier --check .",
103103
"lint": "eslint . --cache --cache-strategy content",
104104
"lint:fix": "eslint --fix .",
105-
"test": "vitest --run --typecheck",
105+
"test": "vitest --typecheck --run ",
106106
"test:watch": "vitest --watch",
107107
"type-tests": "yarn tsc -p tsconfig.test.json --noEmit",
108108
"prepack": "yarn build",

packages/toolkit/src/entities/tests/sorted_state_adapter.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
createAction,
44
createSlice,
55
nanoid,
6+
PayloadAction,
67
} from '@reduxjs/toolkit'
78
import type { EntityAdapter, EntityState } from '../..'
89
import { createNextState } from '../..'
@@ -786,6 +787,30 @@ describe('Sorted State Adapter', () => {
786787
//expect(numSorts).toBeLessThan(25_000)
787788
})
788789

790+
it('should not throw an Immer `current` error when `state.ids` is a plain array', () => {
791+
const book1: BookModel = { id: 'a', title: 'First' }
792+
const initialState = adapter.getInitialState()
793+
const withItems = adapter.addMany(initialState, [book1])
794+
const booksSlice = createSlice({
795+
name: 'books',
796+
initialState,
797+
reducers: {
798+
testCurrentBehavior(state, action: PayloadAction<BookModel>) {
799+
// Will overwrite `state.ids` with a plain array
800+
adapter.removeAll(state)
801+
802+
// will call `splitAddedUpdatedEntities` and call `current(state.ids)`
803+
adapter.upsertMany(state, [book1])
804+
},
805+
},
806+
})
807+
808+
booksSlice.reducer(
809+
initialState,
810+
booksSlice.actions.testCurrentBehavior(book1),
811+
)
812+
})
813+
789814
describe('can be used mutably when wrapped in createNextState', () => {
790815
test('removeAll', () => {
791816
const withTwo = adapter.addMany(state, [TheGreatGatsby, AnimalFarm])

packages/toolkit/src/entities/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function splitAddedUpdatedEntities<T, Id extends EntityId>(
4747
): [T[], Array<Update<T, Id>>, Id[]] {
4848
newEntities = ensureEntitiesArray(newEntities)
4949

50-
const existingIdsArray = current(state.ids) as Id[]
50+
const existingIdsArray = getCurrent(state.ids) as Id[]
5151
const existingIds = new Set<Id>(existingIdsArray)
5252

5353
const added: T[] = []

0 commit comments

Comments
 (0)