Skip to content

Commit ac66d10

Browse files
fix(proxy-state-tree): always remove proxies if needed, even if not tracking path in production
1 parent 1dd4a8c commit ac66d10

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -179,23 +179,24 @@ export class Proxifier {
179179

180180
trackingTree && trackingTree.proxifier.trackPath(nestedPath)
181181

182+
const method = String(prop)
183+
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+
182193
if (
183194
arrayMutations.has(String(prop)) &&
184195
proxifier.shouldTrackMutations(nestedPath)
185196
) {
186197
proxifier.ensureMutationTrackingIsEnabled(nestedPath)
187198
return (...args) => {
188199
const mutationTree = proxifier.getMutationTree()
189-
const method = String(prop)
190-
191-
// On POP we can optimally remove cached proxy by removing the specific one
192-
// that was removed. If it is a PUSH, we do not have to remove anything, as
193-
// existing proxies stays the same
194-
if (method === 'pop') {
195-
proxifier.tree.master.removeProxy(nestedPath)
196-
} else if (method !== 'push') {
197-
proxifier.tree.master.removeProxy(path)
198-
}
199200

200201
mutationTree.addMutation({
201202
method,
@@ -297,6 +298,10 @@ export class Proxifier {
297298
proxifier.ensureMutationTrackingIsEnabled(nestedPath)
298299
proxifier.ensureValueDosntExistInStateTreeElsewhere(value)
299300

301+
if (isPlainObject(target[prop]) || Array.isArray(target[prop])) {
302+
proxifier.tree.master.removeProxy(nestedPath)
303+
}
304+
300305
if (proxifier.shouldTrackMutations(nestedPath)) {
301306
let objectChangePath
302307

@@ -306,10 +311,6 @@ export class Proxifier {
306311

307312
const mutationTree = proxifier.getMutationTree()
308313

309-
if (isPlainObject(target[prop]) || Array.isArray(target[prop])) {
310-
proxifier.tree.master.removeProxy(nestedPath)
311-
}
312-
313314
mutationTree.addMutation(
314315
{
315316
method: 'set',
@@ -331,6 +332,10 @@ export class Proxifier {
331332

332333
proxifier.ensureMutationTrackingIsEnabled(nestedPath)
333334

335+
if (isPlainObject(target[prop]) || Array.isArray(target[prop])) {
336+
proxifier.tree.master.removeProxy(nestedPath)
337+
}
338+
334339
if (proxifier.shouldTrackMutations(nestedPath)) {
335340
let objectChangePath
336341
if (prop in target) {
@@ -339,10 +344,6 @@ export class Proxifier {
339344

340345
const mutationTree = proxifier.getMutationTree()
341346

342-
if (isPlainObject(target[prop]) || Array.isArray(target[prop])) {
343-
proxifier.tree.master.removeProxy(nestedPath)
344-
}
345-
346347
mutationTree.addMutation(
347348
{
348349
method: 'unset',

0 commit comments

Comments
 (0)