Skip to content

Commit 0c8d3e3

Browse files
Georg Wicke-Arndtmarkerikson
authored andcommitted
Use original instead of immer draft for perf
1 parent 23a78ca commit 0c8d3e3

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

packages/toolkit/src/query/core/buildSlice.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import type {
3131
EndpointDefinitions,
3232
QueryDefinition,
3333
} from '../endpointDefinitions'
34-
import type { Patch } from 'immer'
35-
import { applyPatches } from 'immer'
34+
import { isDraft, Patch } from 'immer'
35+
import { applyPatches, original } from 'immer'
3636
import { onFocus, onFocusLost, onOffline, onOnline } from './setupListeners'
3737
import {
3838
isDocumentVisible,
@@ -208,7 +208,12 @@ export function buildSlice({
208208
// Assign or safely update the cache data.
209209
substate.data =
210210
definitions[meta.arg.endpointName].structuralSharing ?? true
211-
? copyWithStructuralSharing(substate.data, payload)
211+
? copyWithStructuralSharing(
212+
isDraft(substate.data)
213+
? original(substate.data)
214+
: substate.data,
215+
payload
216+
)
212217
: payload
213218
}
214219

0 commit comments

Comments
 (0)