Skip to content

Commit

Permalink
Use original instead of immer draft for perf
Browse files Browse the repository at this point in the history
  • Loading branch information
Georg Wicke-Arndt authored and markerikson committed Apr 16, 2023
1 parent 23a78ca commit 0c8d3e3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/toolkit/src/query/core/buildSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import type {
EndpointDefinitions,
QueryDefinition,
} from '../endpointDefinitions'
import type { Patch } from 'immer'
import { applyPatches } from 'immer'
import { isDraft, Patch } from 'immer'
import { applyPatches, original } from 'immer'
import { onFocus, onFocusLost, onOffline, onOnline } from './setupListeners'
import {
isDocumentVisible,
Expand Down Expand Up @@ -208,7 +208,12 @@ export function buildSlice({
// Assign or safely update the cache data.
substate.data =
definitions[meta.arg.endpointName].structuralSharing ?? true
? copyWithStructuralSharing(substate.data, payload)
? copyWithStructuralSharing(
isDraft(substate.data)
? original(substate.data)
: substate.data,
payload
)
: payload
}

Expand Down

0 comments on commit 0c8d3e3

Please sign in to comment.