Skip to content

Commit db94d5d

Browse files
fix(proxy-state-tree): only remove array proxies when actually doing an array mutation
1 parent 84fe6c6 commit db94d5d

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

packages/node_modules/overmind/src/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,15 +525,21 @@ export class Overmind<Config extends Configuration> implements Configuration {
525525
if (key === '__esModule') {
526526
return aggr
527527
}
528+
const originalDescriptor = Object.getOwnPropertyDescriptor(state, key)
529+
530+
if (originalDescriptor && 'get' in originalDescriptor) {
531+
Object.defineProperty(aggr, key, originalDescriptor as any)
532+
533+
return aggr
534+
}
528535

529536
const value = state[key]
537+
530538
if (isPlainObject(value)) {
531539
aggr[key] = this.processState(value)
532540
} else if (typeof value === 'function') {
533541
aggr[key] = new Derived(value)
534542
} else {
535-
var originalDescriptor = Object.getOwnPropertyDescriptor(state, key)
536-
537543
Object.defineProperty(aggr, key, originalDescriptor as any)
538544
}
539545

packages/node_modules/proxy-state-tree/src/Proxyfier.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,19 @@ export class Proxifier {
181181

182182
const method = String(prop)
183183

184-
// On POP we can optimally remove cached proxy by removing the specific one
185-
// that was removed. If it is a PUSH, we do not have to remove anything, as
186-
// existing proxies stays the same
187-
if (method === 'pop') {
188-
proxifier.tree.master.removeProxy(nestedPath)
189-
} else if (method !== 'push') {
190-
proxifier.tree.master.removeProxy(path)
191-
}
192-
193184
if (
194-
arrayMutations.has(String(prop)) &&
185+
arrayMutations.has(method) &&
195186
proxifier.shouldTrackMutations(nestedPath)
196187
) {
188+
// On POP we can optimally remove cached proxy by removing the specific one
189+
// that was removed. If it is a PUSH, we do not have to remove anything, as
190+
// existing proxies stays the same
191+
if (method === 'pop') {
192+
proxifier.tree.master.removeProxy(nestedPath)
193+
} else if (method !== 'push') {
194+
proxifier.tree.master.removeProxy(path)
195+
}
196+
197197
proxifier.ensureMutationTrackingIsEnabled(nestedPath)
198198
return (...args) => {
199199
const mutationTree = proxifier.getMutationTree()

0 commit comments

Comments
 (0)