Skip to content

Commit 9d851fc

Browse files
committed
tighter static members forwarding
1 parent e4bee4e commit 9d851fc

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

runtime/proxy.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,16 +261,22 @@ class ProxyComponent {
261261
}
262262
}
263263

264-
// TODO we should probably delete statics that were added on the previous
265-
// iteration, to avoid the case where something removed in the code would
266-
// remain available, and HMR would produce a different result than non-HMR --
267-
// namely, we'd expect a crash if a static method is still used somewhere but
268-
// removed from the code, and HMR would hide that until next reload
269-
const copyStatics = (component, proxy) => {
270-
//forward static properties and methods
264+
const syncStatics = (component, proxy, previousKeys) => {
265+
// remove previously copied keys
266+
if (previousKeys) {
267+
for (const key of previousKeys) {
268+
delete proxy[key]
269+
}
270+
}
271+
272+
// forward static properties and methods
273+
const keys = []
271274
for (const key in component) {
275+
keys.push(key)
272276
proxy[key] = component[key]
273277
}
278+
279+
return keys
274280
}
275281

276282
const globalListeners = {}
@@ -380,7 +386,7 @@ export function createProxy({
380386
}[name]
381387

382388
// initialize static members
383-
copyStatics(current.Component, proxy)
389+
let previousStatics = syncStatics(current.Component, proxy)
384390

385391
const update = newState => Object.assign(current, newState)
386392

@@ -390,7 +396,7 @@ export function createProxy({
390396

391397
// copy statics before doing anything because a static prop/method
392398
// could be used somewhere in the create/render call
393-
copyStatics(current.Component, proxy)
399+
previousStatics = syncStatics(current.Component, proxy, previousStatics)
394400

395401
const errors = []
396402

0 commit comments

Comments
 (0)