@vobs/runtime 1.3.6 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/hmr.cjs CHANGED
@@ -52,24 +52,24 @@ function resolveComponent(component, moduleId, exportName) {
52
52
  return proxy;
53
53
  }
54
54
  __name(resolveComponent, "resolveComponent");
55
- function updateHmrModule(_moduleId, nextModule) {
56
- const modules = [...hmrGlobal.modules.values()];
57
- for (const module2 of modules) {
58
- let changed = false;
59
- for (const [name, proxy] of module2.components) {
60
- const next = nextModule[name];
61
- if (typeof next !== "function") continue;
62
- const hmrProxy = proxy;
63
- hmrProxy.current = next;
64
- Object.defineProperty(hmrProxy, "displayName", { configurable: true, value: next.name || name });
65
- changed = true;
66
- }
67
- if (!changed) continue;
68
- for (const instance of module2.instances) {
69
- try {
70
- instance.refresh();
71
- } catch {
72
- }
55
+ function updateHmrModule(moduleId, nextModule) {
56
+ const module2 = hmrGlobal.modules.get(moduleId);
57
+ if (!module2) return;
58
+ let changed = false;
59
+ for (const [name, proxy] of module2.components) {
60
+ const next = nextModule[name];
61
+ if (typeof next !== "function") continue;
62
+ const hmrProxy = proxy;
63
+ hmrProxy.current = next;
64
+ Object.defineProperty(hmrProxy, "displayName", { configurable: true, value: next.name || name });
65
+ changed = true;
66
+ }
67
+ if (!changed) return;
68
+ const instances = [...module2.instances];
69
+ for (const instance of instances) {
70
+ try {
71
+ instance.refresh();
72
+ } catch {
73
73
  }
74
74
  }
75
75
  }
package/dist/hmr.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hmr.ts"],"sourcesContent":["import type { VobsNode } from './fragment'\n\nexport type HmrComponent<Props extends object = Record<string, unknown>> =\n (props: Props) => VobsNode\n\nexport interface HmrStateStore {\n get<T>(key: string, initial: T | (() => T)): T\n set<T>(key: string, value: T): void\n has(key: string): boolean\n delete(key: string): void\n clear(): void\n}\n\nexport interface HmrInstance {\n node: VobsNode\n parent: Node | null\n refresh(): void\n}\n\ninterface HmrModuleState {\n readonly components: Map<string, HmrComponent>\n readonly state: Map<string, unknown>\n readonly instances: Set<HmrInstance>\n}\n\ninterface HmrGlobal {\n modules: Map<string, HmrModuleState>\n /** 编译器生成的 hmrStateRef 注册表:键为 `${moduleId}#${声明名}`,值跨模块重执行保活。 */\n states: Map<string, unknown>\n}\n\nconst globalTarget = globalThis as typeof globalThis & { __VOBS_HMR__?: HmrGlobal }\nconst hmrGlobal = globalTarget.__VOBS_HMR__ ?? { modules: new Map<string, HmrModuleState>(), states: new Map<string, unknown>() }\nglobalTarget.__VOBS_HMR__ = hmrGlobal\n\nexport function resolveComponent<Props extends object>(\n component: HmrComponent<Props>,\n moduleId: string,\n exportName: string\n): HmrComponent<Props> {\n const module = getModule(moduleId)\n const existing = module.components.get(exportName)\n if (existing) return existing as HmrComponent<Props>\n\n const proxy = ((props: Props) => {\n const current = (proxy as HmrComponent<Props> & { current: HmrComponent<Props> }).current\n return current(props)\n }) as HmrComponent<Props> & { current: HmrComponent<Props> }\n proxy.current = component\n Object.defineProperties(proxy, {\n displayName: { configurable: true, value: component.name || exportName },\n hmrKey: { configurable: false, value: `${moduleId}:${exportName}` }\n })\n module.components.set(exportName, proxy as HmrComponent)\n return proxy\n}\n\nexport function updateHmrModule(_moduleId: string, nextModule: Record<string, unknown>): void {\n const modules = [...hmrGlobal.modules.values()]\n for (const module of modules) {\n let changed = false\n for (const [name, proxy] of module.components) {\n const next = nextModule[name]\n if (typeof next !== 'function') continue\n const hmrProxy = proxy as HmrComponent & { current: HmrComponent; displayName?: string }\n hmrProxy.current = next as HmrComponent\n Object.defineProperty(hmrProxy, 'displayName', { configurable: true, value: next.name || name })\n changed = true\n }\n if (!changed) continue\n for (const instance of module.instances) {\n try {\n instance.refresh()\n } catch {\n // HMR failures remain application errors on the next normal render.\n }\n }\n }\n}\n\nexport function disposeHmrModule(_moduleId: string): void {\n // State and component proxies intentionally survive module disposal.\n}\n\nexport function createHmrStateStore(moduleId: string): HmrStateStore {\n const state = getModule(moduleId).state\n return {\n get<T>(key: string, initial: T | (() => T)): T {\n if (!state.has(key)) state.set(key, typeof initial === 'function' ? (initial as () => T)() : initial)\n return state.get(key) as T\n },\n set<T>(key: string, value: T): void {\n state.set(key, value)\n },\n has: key => state.has(key),\n delete: key => { state.delete(key) },\n clear: () => { state.clear() }\n }\n}\n\n/**\n * 编译器为模块顶层 state() 声明生成的取值入口。键为 `${moduleId}#${声明名}`,\n * 与手动 store 键空间隔离。模块热更新重执行时复用既有信号实例:旧导入方持有的\n * 实例与新模块实例共享同一份状态,消除\"两份模块、两份状态\"导致的编辑不生效/页面半边失灵。\n */\nexport function hmrStateRef<T>(key: string, create: () => T): T {\n const states = hmrGlobal.states\n if (states.has(key)) return states.get(key) as T\n const value = create()\n states.set(key, value)\n return value\n}\n\nexport function registerHmrInstance(moduleId: string, instance: HmrInstance): () => void {\n const instances = getModule(moduleId).instances\n instances.add(instance)\n return () => instances.delete(instance)\n}\n\nexport function markHmrInstanceMounted(node: VobsNode, parent: Node): void {\n const instance = hmrInstances.get(node as object)\n if (instance) instance.parent = parent\n}\n\nfunction getModule(moduleId: string): HmrModuleState {\n let module = hmrGlobal.modules.get(moduleId)\n if (!module) {\n module = { components: new Map(), state: new Map(), instances: new Set() }\n hmrGlobal.modules.set(moduleId, module)\n }\n return module\n}\n\nconst hmrInstances = new WeakMap<object, HmrInstance>()\n\nexport function associateHmrInstance(node: VobsNode, instance: HmrInstance): void {\n hmrInstances.set(node as object, instance)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA+BA,IAAM,eAAe;AACrB,IAAM,YAAY,aAAa,gBAAgB,EAAE,SAAS,oBAAI,IAA4B,GAAG,QAAQ,oBAAI,IAAqB,EAAE;AAChI,aAAa,eAAe;AAErB,SAAS,iBACd,WACA,UACA,YACqB;AACrB,QAAMA,UAAS,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from './fragment'\n\nexport type HmrComponent<Props extends object = Record<string, unknown>> =\n (props: Props) => VobsNode\n\nexport interface HmrStateStore {\n get<T>(key: string, initial: T | (() => T)): T\n set<T>(key: string, value: T): void\n has(key: string): boolean\n delete(key: string): void\n clear(): void\n}\n\nexport interface HmrInstance {\n node: VobsNode\n parent: Node | null\n refresh(): void\n}\n\ninterface HmrModuleState {\n readonly components: Map<string, HmrComponent>\n readonly state: Map<string, unknown>\n readonly instances: Set<HmrInstance>\n}\n\ninterface HmrGlobal {\n modules: Map<string, HmrModuleState>\n /** 编译器生成的 hmrStateRef 注册表:键为 `${moduleId}#${声明名}`,值跨模块重执行保活。 */\n states: Map<string, unknown>\n}\n\nconst globalTarget = globalThis as typeof globalThis & { __VOBS_HMR__?: HmrGlobal }\nconst hmrGlobal = globalTarget.__VOBS_HMR__ ?? { modules: new Map<string, HmrModuleState>(), states: new Map<string, unknown>() }\nglobalTarget.__VOBS_HMR__ = hmrGlobal\n\nexport function resolveComponent<Props extends object>(\n component: HmrComponent<Props>,\n moduleId: string,\n exportName: string\n): HmrComponent<Props> {\n const module = getModule(moduleId)\n const existing = module.components.get(exportName)\n if (existing) return existing as HmrComponent<Props>\n\n const proxy = ((props: Props) => {\n const current = (proxy as HmrComponent<Props> & { current: HmrComponent<Props> }).current\n return current(props)\n }) as HmrComponent<Props> & { current: HmrComponent<Props> }\n proxy.current = component\n Object.defineProperties(proxy, {\n displayName: { configurable: true, value: component.name || exportName },\n hmrKey: { configurable: false, value: `${moduleId}:${exportName}` }\n })\n module.components.set(exportName, proxy as HmrComponent)\n return proxy\n}\n\nexport function updateHmrModule(moduleId: string, nextModule: Record<string, unknown>): void {\n const module = hmrGlobal.modules.get(moduleId)\n if (!module) return\n let changed = false\n for (const [name, proxy] of module.components) {\n const next = nextModule[name]\n if (typeof next !== 'function') continue\n const hmrProxy = proxy as HmrComponent & { current: HmrComponent; displayName?: string }\n hmrProxy.current = next as HmrComponent\n Object.defineProperty(hmrProxy, 'displayName', { configurable: true, value: next.name || name })\n changed = true\n }\n if (!changed) return\n // 快照后正序遍历:实例在自身渲染开始前注册,祖先必然先于后代入列——\n // 祖先先刷新会 dispose 上一轮渲染作用域,其树内旧后代实例的 refresh\n // 命中已销毁守卫被跳过,避免同一组件在一次热更新中重渲染两次。\n // 同时 refresh 重渲染以新代码创建的全新实例不在快照中,天然不会再刷新。\n const instances = [...module.instances]\n for (const instance of instances) {\n try {\n instance.refresh()\n } catch {\n // HMR failures remain application errors on the next normal render.\n }\n }\n}\n\nexport function disposeHmrModule(_moduleId: string): void {\n // State and component proxies intentionally survive module disposal.\n}\n\nexport function createHmrStateStore(moduleId: string): HmrStateStore {\n const state = getModule(moduleId).state\n return {\n get<T>(key: string, initial: T | (() => T)): T {\n if (!state.has(key)) state.set(key, typeof initial === 'function' ? (initial as () => T)() : initial)\n return state.get(key) as T\n },\n set<T>(key: string, value: T): void {\n state.set(key, value)\n },\n has: key => state.has(key),\n delete: key => { state.delete(key) },\n clear: () => { state.clear() }\n }\n}\n\n/**\n * 编译器为模块顶层 state() 声明生成的取值入口。键为 `${moduleId}#${声明名}`,\n * 与手动 store 键空间隔离。模块热更新重执行时复用既有信号实例:旧导入方持有的\n * 实例与新模块实例共享同一份状态,消除\"两份模块、两份状态\"导致的编辑不生效/页面半边失灵。\n */\nexport function hmrStateRef<T>(key: string, create: () => T): T {\n const states = hmrGlobal.states\n if (states.has(key)) return states.get(key) as T\n const value = create()\n states.set(key, value)\n return value\n}\n\nexport function registerHmrInstance(moduleId: string, instance: HmrInstance): () => void {\n const instances = getModule(moduleId).instances\n instances.add(instance)\n return () => instances.delete(instance)\n}\n\nexport function markHmrInstanceMounted(node: VobsNode, parent: Node): void {\n const instance = hmrInstances.get(node as object)\n if (instance) instance.parent = parent\n}\n\nfunction getModule(moduleId: string): HmrModuleState {\n let module = hmrGlobal.modules.get(moduleId)\n if (!module) {\n module = { components: new Map(), state: new Map(), instances: new Set() }\n hmrGlobal.modules.set(moduleId, module)\n }\n return module\n}\n\nconst hmrInstances = new WeakMap<object, HmrInstance>()\n\nexport function associateHmrInstance(node: VobsNode, instance: HmrInstance): void {\n hmrInstances.set(node as object, instance)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA+BA,IAAM,eAAe;AACrB,IAAM,YAAY,aAAa,gBAAgB,EAAE,SAAS,oBAAI,IAA4B,GAAG,QAAQ,oBAAI,IAAqB,EAAE;AAChI,aAAa,eAAe;AAErB,SAAS,iBACd,WACA,UACA,YACqB;AACrB,QAAMA,UAAS,UAAU,QAAQ;AACjC,QAAM,WAAWA,QAAO,WAAW,IAAI,UAAU;AACjD,MAAI,SAAU,QAAO;AAErB,QAAM,QAAS,yBAAC,UAAiB;AAC/B,UAAM,UAAW,MAAiE;AAClF,WAAO,QAAQ,KAAK;AAAA,EACtB,IAHe;AAIf,QAAM,UAAU;AAChB,SAAO,iBAAiB,OAAO;AAAA,IAC7B,aAAa,EAAE,cAAc,MAAM,OAAO,UAAU,QAAQ,WAAW;AAAA,IACvE,QAAQ,EAAE,cAAc,OAAO,OAAO,GAAG,QAAQ,IAAI,UAAU,GAAG;AAAA,EACpE,CAAC;AACD,EAAAA,QAAO,WAAW,IAAI,YAAY,KAAqB;AACvD,SAAO;AACT;AApBgB;AAsBT,SAAS,gBAAgB,UAAkB,YAA2C;AAC3F,QAAMA,UAAS,UAAU,QAAQ,IAAI,QAAQ;AAC7C,MAAI,CAACA,QAAQ;AACb,MAAI,UAAU;AACd,aAAW,CAAC,MAAM,KAAK,KAAKA,QAAO,YAAY;AAC7C,UAAM,OAAO,WAAW,IAAI;AAC5B,QAAI,OAAO,SAAS,WAAY;AAChC,UAAM,WAAW;AACjB,aAAS,UAAU;AACnB,WAAO,eAAe,UAAU,eAAe,EAAE,cAAc,MAAM,OAAO,KAAK,QAAQ,KAAK,CAAC;AAC/F,cAAU;AAAA,EACZ;A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AAIA,UAAS,UAAU,QAAQ,IAAI,QAAQ;AAC3C,MAAI,CAACA,SAAQ;AACX,IAAAA,UAAS,EAAE,YAAY,oBAAI,IAAI,GAAG,OAAO,oBAAI,IAAI,GAAG,WAAW,oBAAI,IAAI,EAAE;AACzE,cAAU,QAAQ,IAAI,UAAUA,OAAM;AAAA,EACxC;AACA,SAAOA;AACT;AAPS;AAST,IAAM,eAAe,oBAAI,QAA6B;AAE/C,SAAS,qBAAqB,MAAgB,UAA6B;AAChF,eAAa,IAAI,MAAgB,QAAQ;AAC3C;AAFgB;","names":["module"]}
package/dist/hmr.d.cts CHANGED
@@ -14,7 +14,7 @@ interface HmrInstance {
14
14
  refresh(): void;
15
15
  }
16
16
  declare function resolveComponent<Props extends object>(component: HmrComponent<Props>, moduleId: string, exportName: string): HmrComponent<Props>;
17
- declare function updateHmrModule(_moduleId: string, nextModule: Record<string, unknown>): void;
17
+ declare function updateHmrModule(moduleId: string, nextModule: Record<string, unknown>): void;
18
18
  declare function disposeHmrModule(_moduleId: string): void;
19
19
  declare function createHmrStateStore(moduleId: string): HmrStateStore;
20
20
  /**
package/dist/hmr.d.ts CHANGED
@@ -14,7 +14,7 @@ interface HmrInstance {
14
14
  refresh(): void;
15
15
  }
16
16
  declare function resolveComponent<Props extends object>(component: HmrComponent<Props>, moduleId: string, exportName: string): HmrComponent<Props>;
17
- declare function updateHmrModule(_moduleId: string, nextModule: Record<string, unknown>): void;
17
+ declare function updateHmrModule(moduleId: string, nextModule: Record<string, unknown>): void;
18
18
  declare function disposeHmrModule(_moduleId: string): void;
19
19
  declare function createHmrStateStore(moduleId: string): HmrStateStore;
20
20
  /**
package/dist/hmr.js CHANGED
@@ -22,24 +22,24 @@ function resolveComponent(component, moduleId, exportName) {
22
22
  return proxy;
23
23
  }
24
24
  __name(resolveComponent, "resolveComponent");
25
- function updateHmrModule(_moduleId, nextModule) {
26
- const modules = [...hmrGlobal.modules.values()];
27
- for (const module of modules) {
28
- let changed = false;
29
- for (const [name, proxy] of module.components) {
30
- const next = nextModule[name];
31
- if (typeof next !== "function") continue;
32
- const hmrProxy = proxy;
33
- hmrProxy.current = next;
34
- Object.defineProperty(hmrProxy, "displayName", { configurable: true, value: next.name || name });
35
- changed = true;
36
- }
37
- if (!changed) continue;
38
- for (const instance of module.instances) {
39
- try {
40
- instance.refresh();
41
- } catch {
42
- }
25
+ function updateHmrModule(moduleId, nextModule) {
26
+ const module = hmrGlobal.modules.get(moduleId);
27
+ if (!module) return;
28
+ let changed = false;
29
+ for (const [name, proxy] of module.components) {
30
+ const next = nextModule[name];
31
+ if (typeof next !== "function") continue;
32
+ const hmrProxy = proxy;
33
+ hmrProxy.current = next;
34
+ Object.defineProperty(hmrProxy, "displayName", { configurable: true, value: next.name || name });
35
+ changed = true;
36
+ }
37
+ if (!changed) return;
38
+ const instances = [...module.instances];
39
+ for (const instance of instances) {
40
+ try {
41
+ instance.refresh();
42
+ } catch {
43
43
  }
44
44
  }
45
45
  }
package/dist/hmr.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hmr.ts"],"sourcesContent":["import type { VobsNode } from './fragment'\n\nexport type HmrComponent<Props extends object = Record<string, unknown>> =\n (props: Props) => VobsNode\n\nexport interface HmrStateStore {\n get<T>(key: string, initial: T | (() => T)): T\n set<T>(key: string, value: T): void\n has(key: string): boolean\n delete(key: string): void\n clear(): void\n}\n\nexport interface HmrInstance {\n node: VobsNode\n parent: Node | null\n refresh(): void\n}\n\ninterface HmrModuleState {\n readonly components: Map<string, HmrComponent>\n readonly state: Map<string, unknown>\n readonly instances: Set<HmrInstance>\n}\n\ninterface HmrGlobal {\n modules: Map<string, HmrModuleState>\n /** 编译器生成的 hmrStateRef 注册表:键为 `${moduleId}#${声明名}`,值跨模块重执行保活。 */\n states: Map<string, unknown>\n}\n\nconst globalTarget = globalThis as typeof globalThis & { __VOBS_HMR__?: HmrGlobal }\nconst hmrGlobal = globalTarget.__VOBS_HMR__ ?? { modules: new Map<string, HmrModuleState>(), states: new Map<string, unknown>() }\nglobalTarget.__VOBS_HMR__ = hmrGlobal\n\nexport function resolveComponent<Props extends object>(\n component: HmrComponent<Props>,\n moduleId: string,\n exportName: string\n): HmrComponent<Props> {\n const module = getModule(moduleId)\n const existing = module.components.get(exportName)\n if (existing) return existing as HmrComponent<Props>\n\n const proxy = ((props: Props) => {\n const current = (proxy as HmrComponent<Props> & { current: HmrComponent<Props> }).current\n return current(props)\n }) as HmrComponent<Props> & { current: HmrComponent<Props> }\n proxy.current = component\n Object.defineProperties(proxy, {\n displayName: { configurable: true, value: component.name || exportName },\n hmrKey: { configurable: false, value: `${moduleId}:${exportName}` }\n })\n module.components.set(exportName, proxy as HmrComponent)\n return proxy\n}\n\nexport function updateHmrModule(_moduleId: string, nextModule: Record<string, unknown>): void {\n const modules = [...hmrGlobal.modules.values()]\n for (const module of modules) {\n let changed = false\n for (const [name, proxy] of module.components) {\n const next = nextModule[name]\n if (typeof next !== 'function') continue\n const hmrProxy = proxy as HmrComponent & { current: HmrComponent; displayName?: string }\n hmrProxy.current = next as HmrComponent\n Object.defineProperty(hmrProxy, 'displayName', { configurable: true, value: next.name || name })\n changed = true\n }\n if (!changed) continue\n for (const instance of module.instances) {\n try {\n instance.refresh()\n } catch {\n // HMR failures remain application errors on the next normal render.\n }\n }\n }\n}\n\nexport function disposeHmrModule(_moduleId: string): void {\n // State and component proxies intentionally survive module disposal.\n}\n\nexport function createHmrStateStore(moduleId: string): HmrStateStore {\n const state = getModule(moduleId).state\n return {\n get<T>(key: string, initial: T | (() => T)): T {\n if (!state.has(key)) state.set(key, typeof initial === 'function' ? (initial as () => T)() : initial)\n return state.get(key) as T\n },\n set<T>(key: string, value: T): void {\n state.set(key, value)\n },\n has: key => state.has(key),\n delete: key => { state.delete(key) },\n clear: () => { state.clear() }\n }\n}\n\n/**\n * 编译器为模块顶层 state() 声明生成的取值入口。键为 `${moduleId}#${声明名}`,\n * 与手动 store 键空间隔离。模块热更新重执行时复用既有信号实例:旧导入方持有的\n * 实例与新模块实例共享同一份状态,消除\"两份模块、两份状态\"导致的编辑不生效/页面半边失灵。\n */\nexport function hmrStateRef<T>(key: string, create: () => T): T {\n const states = hmrGlobal.states\n if (states.has(key)) return states.get(key) as T\n const value = create()\n states.set(key, value)\n return value\n}\n\nexport function registerHmrInstance(moduleId: string, instance: HmrInstance): () => void {\n const instances = getModule(moduleId).instances\n instances.add(instance)\n return () => instances.delete(instance)\n}\n\nexport function markHmrInstanceMounted(node: VobsNode, parent: Node): void {\n const instance = hmrInstances.get(node as object)\n if (instance) instance.parent = parent\n}\n\nfunction getModule(moduleId: string): HmrModuleState {\n let module = hmrGlobal.modules.get(moduleId)\n if (!module) {\n module = { components: new Map(), state: new Map(), instances: new Set() }\n hmrGlobal.modules.set(moduleId, module)\n }\n return module\n}\n\nconst hmrInstances = new WeakMap<object, HmrInstance>()\n\nexport function associateHmrInstance(node: VobsNode, instance: HmrInstance): void {\n hmrInstances.set(node as object, instance)\n}\n"],"mappings":";;;;AA+BA,IAAM,eAAe;AACrB,IAAM,YAAY,aAAa,gBAAgB,EAAE,SAAS,oBAAI,IAA4B,GAAG,QAAQ,oBAAI,IAAqB,EAAE;AAChI,aAAa,eAAe;AAErB,SAAS,iBACd,WACA,UACA,YACqB;AACrB,QAAM,SAAS,UAAU,QAAQ;AACjC,QAAM,WAAW,OAAO,WAAW,IAAI,UAAU;AACjD,MAAI,SAAU,QAAO;AAErB,QAAM,QAAS,yBAAC,UAAiB;AAC/B,UAAM,UAAW,MAAiE;AAClF,WAAO,QAAQ,KAAK;AAAA,EACtB,IAHe;AAIf,QAAM,UAAU;AAChB,SAAO,iBAAiB,OAAO;AAAA,IAC7B,aAAa,EAAE,cAAc,MAAM,OAAO,UAAU,QAAQ,WAAW;AAAA,IACvE,QAAQ,EAAE,cAAc,OAAO,OAAO,GAAG,QAAQ,IAAI,UAAU,GAAG;AAAA,EACpE,CAAC;AACD,SAAO,WAAW,IAAI,YAAY,KAAqB;AACvD,SAAO;A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C1C,QAAM,QAAQ,OAAO;AACrB,SAAO,IAAI,KAAK,KAAK;AACrB,SAAO;AACT;AANgB;AAQT,SAAS,oBAAoB,UAAkB,UAAmC;AACvF,QAAM,YAAY,UAAU,QAAQ,EAAE;AACtC,YAAU,IAAI,QAAQ;AACtB,SAAO,MAAM,UAAU,OAAO,QAAQ;AACxC;AAJgB;AAMT,SAAS,uBAAuB,MAAgB,QAAoB;AACzE,QAAM,WAAW,aAAa,IAAI,IAAc;AAChD,MAAI,SAAU,UAAS,SAAS;AAClC;AAHgB;AAKhB,SAAS,UAAU,UAAkC;AACnD,MAAI,SAAS,UAAU,QAAQ,IAAI,QAAQ;AAC3C,MAAI,CAAC,QAAQ;AACX,aAAS,EAAE,YAAY,oBAAI,IAAI,GAAG,OAAO,oBAAI,IAAI,GAAG,WAAW,oBAAI,IAAI,EAAE;AACzE,cAAU,QAAQ,IAAI,UAAU,MAAM;AAAA,EACxC;AACA,SAAO;AACT;AAPS;AAST,IAAM,eAAe,oBAAI,QAA6B;AAE/C,SAAS,qBAAqB,MAAgB,UAA6B;AAChF,eAAa,IAAI,MAAgB,QAAQ;AAC3C;AAFgB;","names":[]}
1
+ {"version":3,"sources":["../src/hmr.ts"],"sourcesContent":["import type { VobsNode } from './fragment'\n\nexport type HmrComponent<Props extends object = Record<string, unknown>> =\n (props: Props) => VobsNode\n\nexport interface HmrStateStore {\n get<T>(key: string, initial: T | (() => T)): T\n set<T>(key: string, value: T): void\n has(key: string): boolean\n delete(key: string): void\n clear(): void\n}\n\nexport interface HmrInstance {\n node: VobsNode\n parent: Node | null\n refresh(): void\n}\n\ninterface HmrModuleState {\n readonly components: Map<string, HmrComponent>\n readonly state: Map<string, unknown>\n readonly instances: Set<HmrInstance>\n}\n\ninterface HmrGlobal {\n modules: Map<string, HmrModuleState>\n /** 编译器生成的 hmrStateRef 注册表:键为 `${moduleId}#${声明名}`,值跨模块重执行保活。 */\n states: Map<string, unknown>\n}\n\nconst globalTarget = globalThis as typeof globalThis & { __VOBS_HMR__?: HmrGlobal }\nconst hmrGlobal = globalTarget.__VOBS_HMR__ ?? { modules: new Map<string, HmrModuleState>(), states: new Map<string, unknown>() }\nglobalTarget.__VOBS_HMR__ = hmrGlobal\n\nexport function resolveComponent<Props extends object>(\n component: HmrComponent<Props>,\n moduleId: string,\n exportName: string\n): HmrComponent<Props> {\n const module = getModule(moduleId)\n const existing = module.components.get(exportName)\n if (existing) return existing as HmrComponent<Props>\n\n const proxy = ((props: Props) => {\n const current = (proxy as HmrComponent<Props> & { current: HmrComponent<Props> }).current\n return current(props)\n }) as HmrComponent<Props> & { current: HmrComponent<Props> }\n proxy.current = component\n Object.defineProperties(proxy, {\n displayName: { configurable: true, value: component.name || exportName },\n hmrKey: { configurable: false, value: `${moduleId}:${exportName}` }\n })\n module.components.set(exportName, proxy as HmrComponent)\n return proxy\n}\n\nexport function updateHmrModule(moduleId: string, nextModule: Record<string, unknown>): void {\n const module = hmrGlobal.modules.get(moduleId)\n if (!module) return\n let changed = false\n for (const [name, proxy] of module.components) {\n const next = nextModule[name]\n if (typeof next !== 'function') continue\n const hmrProxy = proxy as HmrComponent & { current: HmrComponent; displayName?: string }\n hmrProxy.current = next as HmrComponent\n Object.defineProperty(hmrProxy, 'displayName', { configurable: true, value: next.name || name })\n changed = true\n }\n if (!changed) return\n // 快照后正序遍历:实例在自身渲染开始前注册,祖先必然先于后代入列——\n // 祖先先刷新会 dispose 上一轮渲染作用域,其树内旧后代实例的 refresh\n // 命中已销毁守卫被跳过,避免同一组件在一次热更新中重渲染两次。\n // 同时 refresh 重渲染以新代码创建的全新实例不在快照中,天然不会再刷新。\n const instances = [...module.instances]\n for (const instance of instances) {\n try {\n instance.refresh()\n } catch {\n // HMR failures remain application errors on the next normal render.\n }\n }\n}\n\nexport function disposeHmrModule(_moduleId: string): void {\n // State and component proxies intentionally survive module disposal.\n}\n\nexport function createHmrStateStore(moduleId: string): HmrStateStore {\n const state = getModule(moduleId).state\n return {\n get<T>(key: string, initial: T | (() => T)): T {\n if (!state.has(key)) state.set(key, typeof initial === 'function' ? (initial as () => T)() : initial)\n return state.get(key) as T\n },\n set<T>(key: string, value: T): void {\n state.set(key, value)\n },\n has: key => state.has(key),\n delete: key => { state.delete(key) },\n clear: () => { state.clear() }\n }\n}\n\n/**\n * 编译器为模块顶层 state() 声明生成的取值入口。键为 `${moduleId}#${声明名}`,\n * 与手动 store 键空间隔离。模块热更新重执行时复用既有信号实例:旧导入方持有的\n * 实例与新模块实例共享同一份状态,消除\"两份模块、两份状态\"导致的编辑不生效/页面半边失灵。\n */\nexport function hmrStateRef<T>(key: string, create: () => T): T {\n const states = hmrGlobal.states\n if (states.has(key)) return states.get(key) as T\n const value = create()\n states.set(key, value)\n return value\n}\n\nexport function registerHmrInstance(moduleId: string, instance: HmrInstance): () => void {\n const instances = getModule(moduleId).instances\n instances.add(instance)\n return () => instances.delete(instance)\n}\n\nexport function markHmrInstanceMounted(node: VobsNode, parent: Node): void {\n const instance = hmrInstances.get(node as object)\n if (instance) instance.parent = parent\n}\n\nfunction getModule(moduleId: string): HmrModuleState {\n let module = hmrGlobal.modules.get(moduleId)\n if (!module) {\n module = { components: new Map(), state: new Map(), instances: new Set() }\n hmrGlobal.modules.set(moduleId, module)\n }\n return module\n}\n\nconst hmrInstances = new WeakMap<object, HmrInstance>()\n\nexport function associateHmrInstance(node: VobsNode, instance: HmrInstance): void {\n hmrInstances.set(node as object, instance)\n}\n"],"mappings":";;;;AA+BA,IAAM,eAAe;AACrB,IAAM,YAAY,aAAa,gBAAgB,EAAE,SAAS,oBAAI,IAA4B,GAAG,QAAQ,oBAAI,IAAqB,EAAE;AAChI,aAAa,eAAe;AAErB,SAAS,iBACd,WACA,UACA,YACqB;AACrB,QAAM,SAAS,UAAU,QAAQ;AACjC,QAAM,WAAW,OAAO,WAAW,IAAI,UAAU;AACjD,MAAI,SAAU,QAAO;AAErB,QAAM,QAAS,yBAAC,UAAiB;AAC/B,UAAM,UAAW,MAAiE;AAClF,WAA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AAM,IAAI,GAAG,GAApB;AAAA,IACL,QAAQ,gCAAO;AAAE,YAAM,OAAO,GAAG;AAAA,IAAE,GAA3B;AAAA,IACR,OAAO,6BAAM;AAAE,YAAM,MAAM;AAAA,IAAE,GAAtB;AAAA,EACT;AACF;AAdgB;AAqBT,SAAS,YAAe,KAAa,QAAoB;AAC9D,QAAM,SAAS,UAAU;AACzB,MAAI,OAAO,IAAI,GAAG,EAAG,QAAO,OAAO,IAAI,GAAG;AAC1C,QAAM,QAAQ,OAAO;AACrB,SAAO,IAAI,KAAK,KAAK;AACrB,SAAO;AACT;AANgB;AAQT,SAAS,oBAAoB,UAAkB,UAAmC;AACvF,QAAM,YAAY,UAAU,QAAQ,EAAE;AACtC,YAAU,IAAI,QAAQ;AACtB,SAAO,MAAM,UAAU,OAAO,QAAQ;AACxC;AAJgB;AAMT,SAAS,uBAAuB,MAAgB,QAAoB;AACzE,QAAM,WAAW,aAAa,IAAI,IAAc;AAChD,MAAI,SAAU,UAAS,SAAS;AAClC;AAHgB;AAKhB,SAAS,UAAU,UAAkC;AACnD,MAAI,SAAS,UAAU,QAAQ,IAAI,QAAQ;AAC3C,MAAI,CAAC,QAAQ;AACX,aAAS,EAAE,YAAY,oBAAI,IAAI,GAAG,OAAO,oBAAI,IAAI,GAAG,WAAW,oBAAI,IAAI,EAAE;AACzE,cAAU,QAAQ,IAAI,UAAU,MAAM;AAAA,EACxC;AACA,SAAO;AACT;AAPS;AAST,IAAM,eAAe,oBAAI,QAA6B;AAE/C,SAAS,qBAAqB,MAAgB,UAA6B;AAChF,eAAa,IAAI,MAAgB,QAAQ;AAC3C;AAFgB;","names":[]}
package/dist/index.cjs CHANGED
@@ -188,24 +188,24 @@ function resolveComponent(component, moduleId, exportName) {
188
188
  return proxy;
189
189
  }
190
190
  __name(resolveComponent, "resolveComponent");
191
- function updateHmrModule(_moduleId, nextModule) {
192
- const modules = [...hmrGlobal.modules.values()];
193
- for (const module2 of modules) {
194
- let changed = false;
195
- for (const [name, proxy] of module2.components) {
196
- const next = nextModule[name];
197
- if (typeof next !== "function") continue;
198
- const hmrProxy = proxy;
199
- hmrProxy.current = next;
200
- Object.defineProperty(hmrProxy, "displayName", { configurable: true, value: next.name || name });
201
- changed = true;
202
- }
203
- if (!changed) continue;
204
- for (const instance of module2.instances) {
205
- try {
206
- instance.refresh();
207
- } catch {
208
- }
191
+ function updateHmrModule(moduleId, nextModule) {
192
+ const module2 = hmrGlobal.modules.get(moduleId);
193
+ if (!module2) return;
194
+ let changed = false;
195
+ for (const [name, proxy] of module2.components) {
196
+ const next = nextModule[name];
197
+ if (typeof next !== "function") continue;
198
+ const hmrProxy = proxy;
199
+ hmrProxy.current = next;
200
+ Object.defineProperty(hmrProxy, "displayName", { configurable: true, value: next.name || name });
201
+ changed = true;
202
+ }
203
+ if (!changed) return;
204
+ const instances = [...module2.instances];
205
+ for (const instance of instances) {
206
+ try {
207
+ instance.refresh();
208
+ } catch {
209
209
  }
210
210
  }
211
211
  }
@@ -336,6 +336,7 @@ __name(createComment, "createComment");
336
336
  function insertBefore(parent, child, anchor) {
337
337
  if (isVobsFragment(child)) {
338
338
  child.mount(parent, isVobsFragment(anchor) ? anchor.start : anchor);
339
+ markHmrInstanceMounted(child, parent);
339
340
  return;
340
341
  }
341
342
  getRenderer().insertBefore(parent, child, isVobsFragment(anchor) ? anchor.start : anchor);
@@ -517,6 +518,16 @@ function createComponent(component, props, source) {
517
518
  attachComponentContext(reason, componentName, owner.id);
518
519
  throw reason;
519
520
  });
521
+ const hmrKey = component.hmrKey;
522
+ let instance = null;
523
+ if (hmrKey) {
524
+ const separator = hmrKey.lastIndexOf(":");
525
+ const moduleId = separator < 0 ? hmrKey : hmrKey.slice(0, separator);
526
+ instance = { node: null, parent: null, refresh: /* @__PURE__ */ __name(() => refreshInstance(), "refresh") };
527
+ const cleanup = registerHmrInstance(moduleId, instance);
528
+ owner.onDispose(cleanup);
529
+ }
530
+ const renderScope = owner.mark();
520
531
  let node;
521
532
  try {
522
533
  node = owner.run(() => (0, import_reactivity2.untrack)(() => component(props)));
@@ -527,30 +538,29 @@ function createComponent(component, props, source) {
527
538
  throw error;
528
539
  }
529
540
  associateNodeOwner(node, owner);
530
- const hmrKey = component.hmrKey;
531
- if (hmrKey) {
532
- const instance = {
533
- node,
534
- parent: null,
535
- refresh() {
536
- const previous = instance.node;
537
- const next = owner.run(() => (0, import_reactivity2.untrack)(() => component(props)));
538
- if (instance.parent && !isVobsFragment(previous) && !isVobsFragment(next)) {
539
- getRenderer().insertBefore(instance.parent, next, previous);
540
- getRenderer().removeChild(instance.parent, previous);
541
- }
542
- nodeOwners.delete(previous);
543
- nodeOwners.set(next, owner);
544
- associateHmrInstance(next, instance);
545
- instance.node = next;
546
- }
547
- };
541
+ if (instance) {
542
+ instance.node = node;
548
543
  associateHmrInstance(node, instance);
549
- const separator = hmrKey.lastIndexOf(":");
550
- const moduleId = separator < 0 ? hmrKey : hmrKey.slice(0, separator);
551
- const cleanup = registerHmrInstance(moduleId, instance);
552
- owner.onDispose(cleanup);
553
544
  }
545
+ function refreshInstance() {
546
+ if (owner.disposed) return;
547
+ const previous = instance.node;
548
+ owner.disposeSince(renderScope);
549
+ const next = owner.run(() => (0, import_reactivity2.untrack)(() => component(props)));
550
+ const parent = instance.parent;
551
+ if (parent) {
552
+ const anchor = isVobsFragment(previous) ? previous.start : previous;
553
+ if (isVobsFragment(next)) next.mount(parent, anchor);
554
+ else getRenderer().insertBefore(parent, next, anchor);
555
+ if (isVobsFragment(previous)) previous.unmount(parent);
556
+ else getRenderer().removeChild(parent, previous);
557
+ }
558
+ nodeOwners.delete(previous);
559
+ nodeOwners.set(next, owner);
560
+ associateHmrInstance(next, instance);
561
+ instance.node = next;
562
+ }
563
+ __name(refreshInstance, "refreshInstance");
554
564
  return node;
555
565
  }
556
566
  __name(createComponent, "createComponent");