Skip to content

Commit 933502c

Browse files
Georg Wicke-Arndtmarkerikson
Georg Wicke-Arndt
authored andcommittedApr 16, 2023
Use original instead of immer draft for perf
1 parent 23a78ca commit 933502c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed
 

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ import type {
3232
QueryDefinition,
3333
} from '../endpointDefinitions'
3434
import type { Patch } from 'immer'
35-
import { applyPatches } from 'immer'
35+
import { isDraft } from 'immer'
36+
import { applyPatches, original } from 'immer'
3637
import { onFocus, onFocusLost, onOffline, onOnline } from './setupListeners'
3738
import {
3839
isDocumentVisible,
@@ -208,7 +209,12 @@ export function buildSlice({
208209
// Assign or safely update the cache data.
209210
substate.data =
210211
definitions[meta.arg.endpointName].structuralSharing ?? true
211-
? copyWithStructuralSharing(substate.data, payload)
212+
? copyWithStructuralSharing(
213+
isDraft(substate.data)
214+
? original(substate.data)
215+
: substate.data,
216+
payload
217+
)
212218
: payload
213219
}
214220

0 commit comments

Comments
 (0)
Please sign in to comment.