fix: use keys for hmr modules (#11123)

* fix: use keys for hmr modules

* simplify

* lint

* ts
pull/11121/head
Dominic Gannaway 1 year ago committed by GitHub
parent 1183984f68
commit b01af747e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: use keys for hmr modules

@ -427,7 +427,12 @@ export function client_component(source, analysis, options) {
b.export_default(
b.conditional(
b.import_meta_hot(),
b.call('$.hmr', b.member(b.import_meta_hot(), b.id('data')), b.id(analysis.name)),
b.call(
'$.hmr',
b.member(b.import_meta_hot(), b.id('data')),
b.id(analysis.name),
b.member(b.member(b.literal('import'), b.literal('meta')), b.literal('url'))
),
b.id(analysis.name)
)
),

@ -5,15 +5,26 @@ import { get } from '../runtime.js';
/**
* @template {(anchor: Comment, props: any) => any} Component
* @param {{ source: import("#client").Source<Component>; wrapper: Component; }} data
* @param {{ components: Map<string, { source: import("#client").Source<Component>; wrapper: null | Component; }> }} hot_data
* @param {string} key
* @param {Component} component
*/
export function hmr(data, component) {
if (data.source) {
set(data.source, component);
export function hmr(hot_data, component, key) {
var components = (hot_data.components ??= new Map());
var data = components.get(key);
if (data === undefined) {
components.set(
key,
(data = {
source: source(component),
wrapper: null
})
);
} else {
data.source = source(component);
set(data.source, component);
}
const component_source = data.source;
return (data.wrapper ??= /** @type {Component} */ (
(anchor, props) => {
@ -23,7 +34,7 @@ export function hmr(data, component) {
let effect;
block(() => {
const component = get(data.source);
const component = get(component_source);
if (effect) {
// @ts-ignore

Loading…
Cancel
Save