Skip to content

Commit c038b25

Browse files
committed
Merge branch 'master' into monorepo-and-tests
2 parents 9a897e8 + 64a86c6 commit c038b25

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-15
lines changed

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
{
22
"name": "svelte-hmr-monorepo",
33
"private": true,
4+
"description": "Bundler agnostic HMR utils for Svelte 3",
5+
"license": "ISC",
6+
"homepage": "https://github.com/sveltejs/svelte-hmr",
7+
"bugs": {
8+
"url": "https://github.com/sveltejs/svelte-hmr/issues"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/sveltejs/svelte-hmr"
13+
},
414
"devDependencies": {
515
"@changesets/cli": "^2.16.0",
616
"@changesets/get-github-info": "^0.5.0",

packages/svelte-hmr/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

packages/svelte-hmr/runtime/svelte-hooks.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ export const createProxiedComponent = (
138138
return comp
139139
}
140140

141-
targetCmp.$$.on_before_hmr = []
142141
targetCmp.$$.on_hmr = []
143142

144143
// `conservative: true` means we want to be sure that the new component has
@@ -162,7 +161,12 @@ export const createProxiedComponent = (
162161
}
163162
) => {
164163
const restore = captureState(targetCmp)
165-
assignOptions(target, anchor, restore, preserveLocalState)
164+
assignOptions(
165+
target || options.target,
166+
anchor,
167+
restore,
168+
preserveLocalState
169+
)
166170

167171
const callbacks = cmp.$$.on_hmr
168172

packages/svelte-hmr/runtime/svelte-native/proxy-adapter-native.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,10 @@ export const adapter = class ProxyAdapterNative extends ProxyAdapterDom {
137137
delete originalNativeView.on
138138
}
139139
} else {
140-
throw new Error(
141-
'Unexpected call: has underlying svelte-native code changed?'
142-
)
140+
//some other handler wireup, we will just pass it on.
141+
if (on) {
142+
on(type, handler);
143+
}
143144
}
144145
}
145146
}
@@ -160,7 +161,8 @@ export const adapter = class ProxyAdapterNative extends ProxyAdapterDom {
160161
// TODO is it really true that components' elements cannot move in the
161162
// DOM? what about keyed list?
162163
//
163-
const isNativePage = target.tagName === 'fragment'
164+
165+
const isNativePage = (target.tagName === 'fragment' || target.tagName === 'frame') && target.firstChild && target.firstChild.tagName == 'page'
164166
if (isNativePage) {
165167
const nativePageElement = target.firstChild
166168
this.interceptPageNavigation(nativePageElement)

0 commit comments

Comments
 (0)