@llui/dom 0.0.38 → 0.0.40
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.d.ts +31 -0
- package/dist/hmr.d.ts.map +1 -1
- package/dist/hmr.js +134 -78
- package/dist/hmr.js.map +1 -1
- package/dist/mount.d.ts.map +1 -1
- package/dist/mount.js +49 -6
- package/dist/mount.js.map +1 -1
- package/dist/primitives/each.js +13 -4
- package/dist/primitives/each.js.map +1 -1
- package/dist/primitives/virtual-each.d.ts.map +1 -1
- package/dist/primitives/virtual-each.js +7 -0
- package/dist/primitives/virtual-each.js.map +1 -1
- package/package.json +1 -1
package/dist/hmr.d.ts
CHANGED
|
@@ -18,4 +18,35 @@ export declare function unregisterForHmr(name: string, inst: object): void;
|
|
|
18
18
|
* or null if no instances are registered (first mount).
|
|
19
19
|
*/
|
|
20
20
|
export declare function replaceComponent<S, M, E, D = void>(name: string, newDef: ComponentDef<S, M, E, D>): AppHandle | null;
|
|
21
|
+
/**
|
|
22
|
+
* Container-scoped hot-swap. Used by `mountApp` / `hydrateApp`'s HMR
|
|
23
|
+
* fast path: when the same `def.name` is mounted into multiple distinct
|
|
24
|
+
* containers (e.g. a page's onMount iterating placeholders and mounting
|
|
25
|
+
* an inline widget into each), a re-entry of the mount/hydrate path for
|
|
26
|
+
* a fresh container must NOT swap any of the existing entries — those
|
|
27
|
+
* are independent mounts, not module re-execution targeting the same
|
|
28
|
+
* root. Only swap when the existing entry's container is the very same
|
|
29
|
+
* node we're being asked to mount into.
|
|
30
|
+
*
|
|
31
|
+
* Returns the swapped handle when a matching container entry exists,
|
|
32
|
+
* `null` otherwise so the caller can fall through to a fresh mount.
|
|
33
|
+
*/
|
|
34
|
+
export declare function replaceComponentForContainer<S, M, E, D = void>(name: string, newDef: ComponentDef<S, M, E, D>, container: HTMLElement): AppHandle | null;
|
|
35
|
+
/**
|
|
36
|
+
* Anchor-scoped hot-swap. The anchor-rooted analog of
|
|
37
|
+
* `replaceComponentForContainer` — used by `mountAtAnchor` /
|
|
38
|
+
* `hydrateAtAnchor`'s HMR fast path. A second call to the anchor-rooted
|
|
39
|
+
* mount entry on the same anchor (typical of HMR module re-execution
|
|
40
|
+
* for a vike persistent layout layer) hot-swaps in place rather than
|
|
41
|
+
* leaving the prior instance orphaned with a stale end sentinel.
|
|
42
|
+
*
|
|
43
|
+
* Matches on anchor identity (not name alone): independent mounts of
|
|
44
|
+
* the same-named component at different anchors must not collide with
|
|
45
|
+
* each other.
|
|
46
|
+
*
|
|
47
|
+
* Returns the swapped handle when a matching anchor entry exists,
|
|
48
|
+
* `null` otherwise so the caller can fall through to fresh mount /
|
|
49
|
+
* hydrate.
|
|
50
|
+
*/
|
|
51
|
+
export declare function replaceComponentForAnchor<S, M, E, D = void>(name: string, newDef: ComponentDef<S, M, E, D>, anchor: Comment): AppHandle | null;
|
|
21
52
|
//# sourceMappingURL=hmr.d.ts.map
|
package/dist/hmr.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmr.d.ts","sourceRoot":"","sources":["../src/hmr.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAWzD;;;GAGG;AACH,wBAAgB,SAAS,IAAI,IAAI,
|
|
1
|
+
{"version":3,"file":"hmr.d.ts","sourceRoot":"","sources":["../src/hmr.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAWzD;;;GAGG;AACH,wBAAgB,SAAS,IAAI,IAAI,CAUhC;AAmBD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,GAAG,IAAI,CAIvF;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,OAAO,GACnB,IAAI,CAIN;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAMjE;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,EAChD,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAC/B,SAAS,GAAG,IAAI,CAYlB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,4BAA4B,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,EAC5D,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAChC,SAAS,EAAE,WAAW,GACrB,SAAS,GAAG,IAAI,CAWlB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,EACzD,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAChC,MAAM,EAAE,OAAO,GACd,SAAS,GAAG,IAAI,CAUlB"}
|
package/dist/hmr.js
CHANGED
|
@@ -17,6 +17,8 @@ export function enableHmr() {
|
|
|
17
17
|
registerForAnchor,
|
|
18
18
|
unregisterForHmr,
|
|
19
19
|
replaceComponent,
|
|
20
|
+
replaceComponentForContainer,
|
|
21
|
+
replaceComponentForAnchor,
|
|
20
22
|
});
|
|
21
23
|
}
|
|
22
24
|
const hmrRegistry = new Map();
|
|
@@ -56,88 +58,142 @@ export function replaceComponent(name, newDef) {
|
|
|
56
58
|
return null;
|
|
57
59
|
let handle = null;
|
|
58
60
|
for (const entry of entries) {
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
61
|
+
const h = swapEntry(entry, name, newDef);
|
|
62
|
+
if (!handle)
|
|
63
|
+
handle = h;
|
|
64
|
+
}
|
|
65
|
+
console.log(`[LLui HMR] ${name} updated — state preserved`);
|
|
66
|
+
return handle;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Container-scoped hot-swap. Used by `mountApp` / `hydrateApp`'s HMR
|
|
70
|
+
* fast path: when the same `def.name` is mounted into multiple distinct
|
|
71
|
+
* containers (e.g. a page's onMount iterating placeholders and mounting
|
|
72
|
+
* an inline widget into each), a re-entry of the mount/hydrate path for
|
|
73
|
+
* a fresh container must NOT swap any of the existing entries — those
|
|
74
|
+
* are independent mounts, not module re-execution targeting the same
|
|
75
|
+
* root. Only swap when the existing entry's container is the very same
|
|
76
|
+
* node we're being asked to mount into.
|
|
77
|
+
*
|
|
78
|
+
* Returns the swapped handle when a matching container entry exists,
|
|
79
|
+
* `null` otherwise so the caller can fall through to a fresh mount.
|
|
80
|
+
*/
|
|
81
|
+
export function replaceComponentForContainer(name, newDef, container) {
|
|
82
|
+
const entries = hmrRegistry.get(name);
|
|
83
|
+
if (!entries || entries.length === 0)
|
|
84
|
+
return null;
|
|
85
|
+
const matching = entries.find((e) => e.kind === 'container' && e.container === container);
|
|
86
|
+
if (!matching)
|
|
87
|
+
return null;
|
|
88
|
+
const handle = swapEntry(matching, name, newDef);
|
|
89
|
+
console.log(`[LLui HMR] ${name} updated — state preserved`);
|
|
90
|
+
return handle;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Anchor-scoped hot-swap. The anchor-rooted analog of
|
|
94
|
+
* `replaceComponentForContainer` — used by `mountAtAnchor` /
|
|
95
|
+
* `hydrateAtAnchor`'s HMR fast path. A second call to the anchor-rooted
|
|
96
|
+
* mount entry on the same anchor (typical of HMR module re-execution
|
|
97
|
+
* for a vike persistent layout layer) hot-swaps in place rather than
|
|
98
|
+
* leaving the prior instance orphaned with a stale end sentinel.
|
|
99
|
+
*
|
|
100
|
+
* Matches on anchor identity (not name alone): independent mounts of
|
|
101
|
+
* the same-named component at different anchors must not collide with
|
|
102
|
+
* each other.
|
|
103
|
+
*
|
|
104
|
+
* Returns the swapped handle when a matching anchor entry exists,
|
|
105
|
+
* `null` otherwise so the caller can fall through to fresh mount /
|
|
106
|
+
* hydrate.
|
|
107
|
+
*/
|
|
108
|
+
export function replaceComponentForAnchor(name, newDef, anchor) {
|
|
109
|
+
const entries = hmrRegistry.get(name);
|
|
110
|
+
if (!entries || entries.length === 0)
|
|
111
|
+
return null;
|
|
112
|
+
const matching = entries.find((e) => e.kind === 'anchor' && e.anchor === anchor);
|
|
113
|
+
if (!matching)
|
|
114
|
+
return null;
|
|
115
|
+
const handle = swapEntry(matching, name, newDef);
|
|
116
|
+
console.log(`[LLui HMR] ${name} updated — state preserved`);
|
|
117
|
+
return handle;
|
|
118
|
+
}
|
|
119
|
+
function swapEntry(entry, name, newDef) {
|
|
120
|
+
const typedInst = entry.inst;
|
|
121
|
+
typedInst.def = {
|
|
122
|
+
...typedInst.def,
|
|
123
|
+
update: newDef.update,
|
|
124
|
+
view: newDef.view,
|
|
125
|
+
onEffect: newDef.onEffect,
|
|
126
|
+
__dirty: newDef.__dirty,
|
|
127
|
+
__update: newDef.__update,
|
|
128
|
+
__handlers: newDef.__handlers,
|
|
129
|
+
};
|
|
130
|
+
// Snapshot focus + selection + scroll BEFORE disposal — once the
|
|
131
|
+
// root lifetime tears down its DOM, the activeElement and any
|
|
132
|
+
// scrollable subtree are detached and can't be queried. We
|
|
133
|
+
// restore best-effort after the new view renders. The cost of
|
|
134
|
+
// skipping this step is the every-edit experience: the user
|
|
135
|
+
// types in an input, saves, the input rebuilds and loses focus
|
|
136
|
+
// and cursor position. That kills incremental editing flow.
|
|
137
|
+
const ownerRoot = entry.kind === 'container' ? entry.container : (entry.anchor.parentElement ?? null);
|
|
138
|
+
const focusSnapshot = ownerRoot ? captureFocus(ownerRoot) : null;
|
|
139
|
+
const scrollSnapshot = ownerRoot ? captureScroll(ownerRoot) : null;
|
|
140
|
+
disposeLifetime(typedInst.rootLifetime);
|
|
141
|
+
// Clear the owned region per-kind.
|
|
142
|
+
if (entry.kind === 'container') {
|
|
143
|
+
entry.container.textContent = '';
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
// anchor kind — wipe siblings between anchor and endSentinel, keep the
|
|
147
|
+
// anchor AND the end sentinel (they bracket the fresh render).
|
|
148
|
+
let sib = entry.anchor.nextSibling;
|
|
149
|
+
while (sib !== null && sib !== entry.endSentinel) {
|
|
150
|
+
const next = sib.nextSibling;
|
|
151
|
+
sib.parentNode.removeChild(sib);
|
|
152
|
+
sib = next;
|
|
121
153
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
154
|
+
}
|
|
155
|
+
typedInst.rootLifetime = createLifetime(null);
|
|
156
|
+
typedInst.rootLifetime._kind = 'root';
|
|
157
|
+
typedInst.allBindings = [];
|
|
158
|
+
typedInst.structuralBlocks = [];
|
|
159
|
+
setFlatBindings(typedInst.allBindings);
|
|
160
|
+
setRenderContext({
|
|
161
|
+
rootLifetime: typedInst.rootLifetime,
|
|
162
|
+
state: typedInst.state,
|
|
163
|
+
allBindings: typedInst.allBindings,
|
|
164
|
+
structuralBlocks: typedInst.structuralBlocks,
|
|
165
|
+
dom: typedInst.dom,
|
|
166
|
+
container: entry.kind === 'container' ? entry.container : (entry.anchor.parentElement ?? undefined),
|
|
167
|
+
send: typedInst.send,
|
|
168
|
+
instance: typedInst,
|
|
169
|
+
});
|
|
170
|
+
const nodes = typedInst.def.view(createView(typedInst.send));
|
|
171
|
+
clearRenderContext();
|
|
172
|
+
setFlatBindings(null);
|
|
173
|
+
if (entry.kind === 'container') {
|
|
174
|
+
for (const node of nodes) {
|
|
175
|
+
entry.container.appendChild(node);
|
|
134
176
|
}
|
|
135
|
-
|
|
136
|
-
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
for (const node of nodes) {
|
|
180
|
+
entry.anchor.parentNode.insertBefore(node, entry.endSentinel);
|
|
137
181
|
}
|
|
138
182
|
}
|
|
139
|
-
|
|
140
|
-
|
|
183
|
+
// Restore focus, selection, and scroll positions in the freshly
|
|
184
|
+
// rendered DOM. Best-effort: when the new view's DOM has diverged
|
|
185
|
+
// structurally (different IDs, different element ordering, the
|
|
186
|
+
// input that was focused no longer exists), the restorers no-op
|
|
187
|
+
// silently. This is the right tradeoff — failing loudly on
|
|
188
|
+
// structural divergence would just mean every meaningful view
|
|
189
|
+
// edit prints an error.
|
|
190
|
+
if (ownerRoot) {
|
|
191
|
+
if (focusSnapshot)
|
|
192
|
+
restoreFocus(ownerRoot, focusSnapshot);
|
|
193
|
+
if (scrollSnapshot)
|
|
194
|
+
restoreScroll(ownerRoot, scrollSnapshot);
|
|
195
|
+
}
|
|
196
|
+
return makeReplacementHandle(name, entry, typedInst);
|
|
141
197
|
}
|
|
142
198
|
function makeReplacementHandle(name, entry, typedInst) {
|
|
143
199
|
const listeners = new Set();
|
package/dist/hmr.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmr.js","sourceRoot":"","sources":["../src/hmr.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/D,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAA;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C;;;GAGG;AACH,MAAM,UAAU,SAAS;IACvB,aAAa,CAAC;QACZ,SAAS;QACT,cAAc;QACd,iBAAiB;QACjB,gBAAgB;QAChB,gBAAgB;KACjB,CAAC,CAAA;AACJ,CAAC;AAiBD,MAAM,WAAW,GAAG,IAAI,GAAG,EAAsB,CAAA;AAEjD,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,IAAY,EAAE,SAAsB;IAC/E,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAA;IAC3C,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,IA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AAgB,CAAC,aAAa,IAAI,UAAU,CAAC,QAAQ,CAAA;QAClE,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,IAAI,GAAG,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC,CAAA;YACnC,IAAI,IAAI,IAAK,IAA0B,CAAC,QAAQ,CAAC,IAAI,CAAC;gBAAE,OAAO,IAAI,CAAA;QACrE,CAAC;IACH,CAAC;IACD,IAAI,GAAG,GAAS,IAAY,CAAA;IAC5B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,KAAK,GAAG,GAAG,CAAC,UAAU,CAAA;QAC1B,IAAI,CAAC,GAAG,CAAC,CAAA;QACT,OAAO,KAAK,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;YACxB,KAAK,GAAG,KAAK,CAAC,WAAW,CAAA;YACzB,CAAC,EAAE,CAAA;QACL,CAAC;QACD,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAA;QACvB,GAAG,GAAG,KAAK,CAAA;IACb,CAAC;IACD,OAAO,GAAG,YAAY,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAA;AAC5C,CAAC","sourcesContent":["import type { ComponentDef, AppHandle } from './types.js'\nimport type { ComponentInstance } from './update-loop.js'\nimport { flushInstance } from './update-loop.js'\nimport { createLifetime, disposeLifetime } from './lifetime.js'\nimport { setRenderContext, clearRenderContext } from './render-context.js'\nimport { setFlatBindings } from './binding.js'\nimport { getBindingDescriptors } from './binding-descriptors.js'\nimport { unregisterInstance } from './runtime.js'\nimport { _setHmrModule } from './mount.js'\nimport { createView } from './view-helpers.js'\n\n/**\n * Enable HMR state preservation. Called by compiler-generated dev code.\n * Importing this module registers it with mountApp for hot-swapping.\n */\nexport function enableHmr(): void {\n _setHmrModule({\n enableHmr,\n registerForHmr,\n registerForAnchor,\n unregisterForHmr,\n replaceComponent,\n })\n}\n\n// ── HMR Registry ─────────────────────────────────────────────────\n\ntype HmrEntry =\n | {\n kind: 'container'\n inst: ComponentInstance\n container: HTMLElement\n }\n | {\n kind: 'anchor'\n inst: ComponentInstance\n anchor: Comment\n endSentinel: Comment\n }\n\nconst hmrRegistry = new Map<string, HmrEntry[]>()\n\nexport function registerForHmr(name: string, inst: object, container: HTMLElement): void {\n const entries = hmrRegistry.get(name) ?? []\n entries.push({ kind: 'container', inst: inst as ComponentInstance, container })\n hmrRegistry.set(name, entries)\n}\n\nexport function registerForAnchor(\n name: string,\n inst: object,\n anchor: Comment,\n endSentinel: Comment,\n): void {\n const entries = hmrRegistry.get(name) ?? []\n entries.push({ kind: 'anchor', inst: inst as ComponentInstance, anchor, endSentinel })\n hmrRegistry.set(name, entries)\n}\n\nexport function unregisterForHmr(name: string, inst: object): void {\n const entries = hmrRegistry.get(name)\n if (!entries) return\n const idx = entries.findIndex((e) => e.inst === inst)\n if (idx !== -1) entries.splice(idx, 1)\n if (entries.length === 0) hmrRegistry.delete(name)\n}\n\n/**\n * Hot-swap a component definition on all live instances.\n *\n * Preserves the current state. Replaces update, view, onEffect, and __dirty.\n * Disposes the old scope tree (removing old DOM and bindings),\n * re-runs view(currentState, send) to rebuild fresh DOM.\n *\n * Returns an AppHandle for the first instance (for mountApp compatibility),\n * or null if no instances are registered (first mount).\n */\nexport function replaceComponent<S, M, E, D = void>(\n name: string,\n newDef: ComponentDef<S, M, E, D>,\n): AppHandle | null {\n const entries = hmrRegistry.get(name)\n if (!entries || entries.length === 0) return null\n\n let handle: AppHandle | null = null\n\n for (const entry of entries) {\n const typedInst = entry.inst as ComponentInstance<S, M, E>\n\n typedInst.def = {\n ...typedInst.def,\n update: newDef.update,\n view: newDef.view,\n onEffect: newDef.onEffect,\n __dirty: newDef.__dirty,\n __update: newDef.__update,\n __handlers: newDef.__handlers,\n }\n\n // Snapshot focus + selection + scroll BEFORE disposal — once the\n // root lifetime tears down its DOM, the activeElement and any\n // scrollable subtree are detached and can't be queried. We\n // restore best-effort after the new view renders. The cost of\n // skipping this step is the every-edit experience: the user\n // types in an input, saves, the input rebuilds and loses focus\n // and cursor position. That kills incremental editing flow.\n const ownerRoot: ParentNode | null =\n entry.kind === 'container' ? entry.container : (entry.anchor.parentElement ?? null)\n const focusSnapshot = ownerRoot ? captureFocus(ownerRoot) : null\n const scrollSnapshot = ownerRoot ? captureScroll(ownerRoot) : null\n\n disposeLifetime(typedInst.rootLifetime)\n\n // Clear the owned region per-kind.\n if (entry.kind === 'container') {\n entry.container.textContent = ''\n } else {\n // anchor kind — wipe siblings between anchor and endSentinel, keep the\n // anchor AND the end sentinel (they bracket the fresh render).\n let sib = entry.anchor.nextSibling\n while (sib !== null && sib !== entry.endSentinel) {\n const next = sib.nextSibling\n sib.parentNode!.removeChild(sib)\n sib = next\n }\n }\n\n typedInst.rootLifetime = createLifetime(null)\n typedInst.rootLifetime._kind = 'root'\n typedInst.allBindings = []\n typedInst.structuralBlocks = []\n\n setFlatBindings(typedInst.allBindings)\n setRenderContext({\n rootLifetime: typedInst.rootLifetime,\n state: typedInst.state,\n allBindings: typedInst.allBindings,\n structuralBlocks: typedInst.structuralBlocks,\n dom: typedInst.dom,\n container:\n entry.kind === 'container' ? entry.container : (entry.anchor.parentElement ?? undefined),\n send: typedInst.send as (msg: unknown) => void,\n instance: typedInst as ComponentInstance,\n })\n const nodes = typedInst.def.view(createView<S, M>(typedInst.send))\n clearRenderContext()\n setFlatBindings(null)\n\n if (entry.kind === 'container') {\n for (const node of nodes) {\n entry.container.appendChild(node)\n }\n } else {\n for (const node of nodes) {\n entry.anchor.parentNode!.insertBefore(node, entry.endSentinel)\n }\n }\n\n // Restore focus, selection, and scroll positions in the freshly\n // rendered DOM. Best-effort: when the new view's DOM has diverged\n // structurally (different IDs, different element ordering, the\n // input that was focused no longer exists), the restorers no-op\n // silently. This is the right tradeoff — failing loudly on\n // structural divergence would just mean every meaningful view\n // edit prints an error.\n if (ownerRoot) {\n if (focusSnapshot) restoreFocus(ownerRoot, focusSnapshot)\n if (scrollSnapshot) restoreScroll(ownerRoot, scrollSnapshot)\n }\n\n if (!handle) {\n handle = makeReplacementHandle(name, entry, typedInst)\n }\n }\n\n console.log(`[LLui HMR] ${name} updated — state preserved`)\n\n return handle\n}\n\nfunction makeReplacementHandle<S, M, E>(\n name: string,\n entry: HmrEntry,\n typedInst: ComponentInstance<S, M, E>,\n): AppHandle {\n const listeners = new Set<(s: unknown) => void>()\n typedInst._onCommit = (state: unknown) => {\n for (const l of Array.from(listeners)) {\n try {\n l(state)\n } catch (err) {\n console.error('[llui] listener threw:', err)\n }\n }\n }\n let disposed = false\n return {\n dispose() {\n if (disposed) return\n disposed = true\n listeners.clear()\n typedInst._onCommit = undefined\n unregisterForHmr(name, entry.inst)\n entry.inst.abortController.abort()\n unregisterInstance(entry.inst)\n disposeLifetime(typedInst.rootLifetime)\n if (entry.kind === 'container') {\n entry.container.textContent = ''\n } else {\n let sib = entry.anchor.nextSibling\n while (sib !== null && sib !== entry.endSentinel) {\n const next = sib.nextSibling\n sib.parentNode!.removeChild(sib)\n sib = next\n }\n entry.endSentinel.parentNode?.removeChild(entry.endSentinel)\n }\n },\n flush() {\n flushInstance(entry.inst)\n },\n send(msg: unknown) {\n ;(typedInst.send as (m: unknown) => void)(msg)\n },\n getState() {\n return typedInst.state\n },\n subscribe(listener: (state: unknown) => void) {\n if (disposed) return () => {}\n listeners.add(listener)\n return () => listeners.delete(listener)\n },\n getBindingDescriptors() {\n if (disposed) return []\n return getBindingDescriptors(typedInst as ComponentInstance)\n },\n swapUpdate(newUpdate, newOnEffect) {\n if (disposed) return\n flushInstance(entry.inst)\n ;(typedInst.def as { update: typeof newUpdate }).update = newUpdate\n if (newOnEffect !== undefined) {\n ;(typedInst.def as { onEffect?: typeof newOnEffect }).onEffect = newOnEffect\n }\n },\n runReducer(msg) {\n if (disposed) return null\n const [state, effects] = (\n typedInst.def.update as (s: unknown, m: unknown) => [unknown, unknown[]]\n )(typedInst.state, msg)\n return { state, effects: effects as unknown[] }\n },\n setOnBindingError(hook) {\n if (disposed) return\n typedInst._onBindingError = hook ?? undefined\n },\n }\n}\n\n// ── Focus / selection / scroll preservation across HMR ──────────\n\n/**\n * What we record before disposing the root DOM. The locator is a\n * structural pointer: prefer `id` (resilient to view restructuring),\n * fall back to a child-index path through the rendered subtree. If\n * the new DOM doesn't match either, the restore call no-ops.\n */\ntype FocusSnapshot = {\n /** The element's `id` if it had one, else `null`. */\n id: string | null\n /** Sibling-index path from `ownerRoot` down to the focused element. */\n path: number[]\n /** Selection range if the focused element is a text input/textarea. */\n selection: { start: number; end: number; direction: 'forward' | 'backward' | 'none' } | null\n}\n\ntype ScrollSnapshot = Array<{\n id: string | null\n path: number[]\n scrollTop: number\n scrollLeft: number\n}>\n\nfunction captureFocus(root: ParentNode): FocusSnapshot | null {\n const doc = (root as Element).ownerDocument ?? globalThis.document\n if (!doc) return null\n const active = doc.activeElement\n if (!active || active === doc.body) return null\n // Only capture focus for elements inside our owned subtree —\n // anything outside is not ours to restore.\n if (!(root as ParentNode & Node).contains(active)) return null\n\n const path = pathFromAncestor(root as Node, active)\n if (path === null) return null\n\n let selection: FocusSnapshot['selection'] = null\n if (active instanceof HTMLInputElement || active instanceof HTMLTextAreaElement) {\n // Some input types (number, email, etc.) reject selectionStart access.\n // Wrapper try/catch keeps the snapshot resilient to those cases.\n try {\n if (active.selectionStart !== null && active.selectionEnd !== null) {\n selection = {\n start: active.selectionStart,\n end: active.selectionEnd,\n direction: (active.selectionDirection ?? 'none') as 'forward' | 'backward' | 'none',\n }\n }\n } catch {\n selection = null\n }\n }\n\n return {\n id: active.id || null,\n path,\n selection,\n }\n}\n\nfunction restoreFocus(root: ParentNode, snap: FocusSnapshot): void {\n const target = locate(root, snap.id, snap.path)\n if (!target || !(target instanceof HTMLElement)) return\n try {\n target.focus({ preventScroll: true })\n } catch {\n return\n }\n if (\n snap.selection &&\n (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement)\n ) {\n try {\n target.setSelectionRange(snap.selection.start, snap.selection.end, snap.selection.direction)\n } catch {\n // Some input types throw on setSelectionRange; ignore.\n }\n }\n}\n\nfunction captureScroll(root: ParentNode): ScrollSnapshot {\n // Walk the subtree and snapshot every element with non-zero\n // scroll. Most subtrees have at most a handful, so the per-edit\n // cost is small. Capturing all-zeroes wastes the restore work for\n // no benefit; the filter keeps things tight.\n const out: ScrollSnapshot = []\n const walk = (node: Node): void => {\n if (node instanceof HTMLElement) {\n if (node.scrollTop !== 0 || node.scrollLeft !== 0) {\n const path = pathFromAncestor(root as Node, node)\n if (path !== null) {\n out.push({\n id: node.id || null,\n path,\n scrollTop: node.scrollTop,\n scrollLeft: node.scrollLeft,\n })\n }\n }\n }\n for (let c = node.firstChild; c !== null; c = c.nextSibling) {\n walk(c)\n }\n }\n walk(root as Node)\n return out\n}\n\nfunction restoreScroll(root: ParentNode, snap: ScrollSnapshot): void {\n for (const s of snap) {\n const target = locate(root, s.id, s.path)\n if (!target || !(target instanceof HTMLElement)) continue\n target.scrollTop = s.scrollTop\n target.scrollLeft = s.scrollLeft\n }\n}\n\n/**\n * Compute the child-index path from `ancestor` down to `target`, or\n * `null` if `target` isn't in the subtree. The path is what gets\n * walked on restore — no document-wide selectors, no string-encoded\n * selectors that can break on punctuation in IDs.\n */\nfunction pathFromAncestor(ancestor: Node, target: Node): number[] | null {\n const path: number[] = []\n let cur: Node | null = target\n while (cur !== null && cur !== ancestor) {\n const parent: Node | null = cur.parentNode\n if (parent === null) return null\n let idx = 0\n let sib: Node | null = parent.firstChild\n while (sib !== null && sib !== cur) {\n idx++\n sib = sib.nextSibling\n }\n if (sib === null) return null\n path.push(idx)\n cur = parent\n }\n if (cur !== ancestor) return null\n return path.reverse()\n}\n\n/**\n * Restore lookup: try `id` first (cheap and resilient to structural\n * change), then walk the captured child-index path. Returns `null`\n * if neither lookup succeeds — the restore caller silently no-ops.\n */\nfunction locate(root: ParentNode, id: string | null, path: number[]): Element | null {\n if (id) {\n const doc = (root as Element).ownerDocument ?? globalThis.document\n if (doc) {\n const byId = doc.getElementById(id)\n if (byId && (root as ParentNode & Node).contains(byId)) return byId\n }\n }\n let cur: Node = root as Node\n for (const idx of path) {\n let child = cur.firstChild\n let i = 0\n while (child && i < idx) {\n child = child.nextSibling\n i++\n }\n if (!child) return null\n cur = child\n }\n return cur instanceof Element ? cur : null\n}\n"]}
|
|
1
|
+
{"version":3,"file":"hmr.js","sourceRoot":"","sources":["../src/hmr.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/D,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAA;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C;;;GAGG;AACH,MAAM,UAAU,SAAS;IACvB,aAAa,CAAC;QACZ,SAAS;QACT,cAAc;QACd,iBAAiB;QACjB,gBAAgB;QAChB,gBAAgB;QAChB,4BAA4B;QAC5B,yBAAyB;KAC1B,CAAC,CAAA;AACJ,CAAC;AAiBD,MAAM,WAAW,GAAG,IAAI,GAAG,EAAsB,CAAA;AAEjD,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,IAAY,EAAE,SAAsB;IAC/E,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAA;IAC3C,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,IAAyB,EAAE,SAAS,EAAE,CAAC,CAAA;IAC/E,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,OA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AgB,EAAE,EAAiB,EAAE,IAAc;IACjE,IAAI,EAAE,EAAE,CAAC;QACP,MAAM,GAAG,GAAI,IAAgB,CAAC,aAAa,IAAI,UAAU,CAAC,QAAQ,CAAA;QAClE,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,IAAI,GAAG,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC,CAAA;YACnC,IAAI,IAAI,IAAK,IAA0B,CAAC,QAAQ,CAAC,IAAI,CAAC;gBAAE,OAAO,IAAI,CAAA;QACrE,CAAC;IACH,CAAC;IACD,IAAI,GAAG,GAAS,IAAY,CAAA;IAC5B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,KAAK,GAAG,GAAG,CAAC,UAAU,CAAA;QAC1B,IAAI,CAAC,GAAG,CAAC,CAAA;QACT,OAAO,KAAK,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;YACxB,KAAK,GAAG,KAAK,CAAC,WAAW,CAAA;YACzB,CAAC,EAAE,CAAA;QACL,CAAC;QACD,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAA;QACvB,GAAG,GAAG,KAAK,CAAA;IACb,CAAC;IACD,OAAO,GAAG,YAAY,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAA;AAC5C,CAAC","sourcesContent":["import type { ComponentDef, AppHandle } from './types.js'\nimport type { ComponentInstance } from './update-loop.js'\nimport { flushInstance } from './update-loop.js'\nimport { createLifetime, disposeLifetime } from './lifetime.js'\nimport { setRenderContext, clearRenderContext } from './render-context.js'\nimport { setFlatBindings } from './binding.js'\nimport { getBindingDescriptors } from './binding-descriptors.js'\nimport { unregisterInstance } from './runtime.js'\nimport { _setHmrModule } from './mount.js'\nimport { createView } from './view-helpers.js'\n\n/**\n * Enable HMR state preservation. Called by compiler-generated dev code.\n * Importing this module registers it with mountApp for hot-swapping.\n */\nexport function enableHmr(): void {\n _setHmrModule({\n enableHmr,\n registerForHmr,\n registerForAnchor,\n unregisterForHmr,\n replaceComponent,\n replaceComponentForContainer,\n replaceComponentForAnchor,\n })\n}\n\n// ── HMR Registry ─────────────────────────────────────────────────\n\ntype HmrEntry =\n | {\n kind: 'container'\n inst: ComponentInstance\n container: HTMLElement\n }\n | {\n kind: 'anchor'\n inst: ComponentInstance\n anchor: Comment\n endSentinel: Comment\n }\n\nconst hmrRegistry = new Map<string, HmrEntry[]>()\n\nexport function registerForHmr(name: string, inst: object, container: HTMLElement): void {\n const entries = hmrRegistry.get(name) ?? []\n entries.push({ kind: 'container', inst: inst as ComponentInstance, container })\n hmrRegistry.set(name, entries)\n}\n\nexport function registerForAnchor(\n name: string,\n inst: object,\n anchor: Comment,\n endSentinel: Comment,\n): void {\n const entries = hmrRegistry.get(name) ?? []\n entries.push({ kind: 'anchor', inst: inst as ComponentInstance, anchor, endSentinel })\n hmrRegistry.set(name, entries)\n}\n\nexport function unregisterForHmr(name: string, inst: object): void {\n const entries = hmrRegistry.get(name)\n if (!entries) return\n const idx = entries.findIndex((e) => e.inst === inst)\n if (idx !== -1) entries.splice(idx, 1)\n if (entries.length === 0) hmrRegistry.delete(name)\n}\n\n/**\n * Hot-swap a component definition on all live instances.\n *\n * Preserves the current state. Replaces update, view, onEffect, and __dirty.\n * Disposes the old scope tree (removing old DOM and bindings),\n * re-runs view(currentState, send) to rebuild fresh DOM.\n *\n * Returns an AppHandle for the first instance (for mountApp compatibility),\n * or null if no instances are registered (first mount).\n */\nexport function replaceComponent<S, M, E, D = void>(\n name: string,\n newDef: ComponentDef<S, M, E, D>,\n): AppHandle | null {\n const entries = hmrRegistry.get(name)\n if (!entries || entries.length === 0) return null\n\n let handle: AppHandle | null = null\n for (const entry of entries) {\n const h = swapEntry<S, M, E, D>(entry, name, newDef)\n if (!handle) handle = h\n }\n\n console.log(`[LLui HMR] ${name} updated — state preserved`)\n return handle\n}\n\n/**\n * Container-scoped hot-swap. Used by `mountApp` / `hydrateApp`'s HMR\n * fast path: when the same `def.name` is mounted into multiple distinct\n * containers (e.g. a page's onMount iterating placeholders and mounting\n * an inline widget into each), a re-entry of the mount/hydrate path for\n * a fresh container must NOT swap any of the existing entries — those\n * are independent mounts, not module re-execution targeting the same\n * root. Only swap when the existing entry's container is the very same\n * node we're being asked to mount into.\n *\n * Returns the swapped handle when a matching container entry exists,\n * `null` otherwise so the caller can fall through to a fresh mount.\n */\nexport function replaceComponentForContainer<S, M, E, D = void>(\n name: string,\n newDef: ComponentDef<S, M, E, D>,\n container: HTMLElement,\n): AppHandle | null {\n const entries = hmrRegistry.get(name)\n if (!entries || entries.length === 0) return null\n const matching = entries.find(\n (e): e is Extract<HmrEntry, { kind: 'container' }> =>\n e.kind === 'container' && e.container === container,\n )\n if (!matching) return null\n const handle = swapEntry<S, M, E, D>(matching, name, newDef)\n console.log(`[LLui HMR] ${name} updated — state preserved`)\n return handle\n}\n\n/**\n * Anchor-scoped hot-swap. The anchor-rooted analog of\n * `replaceComponentForContainer` — used by `mountAtAnchor` /\n * `hydrateAtAnchor`'s HMR fast path. A second call to the anchor-rooted\n * mount entry on the same anchor (typical of HMR module re-execution\n * for a vike persistent layout layer) hot-swaps in place rather than\n * leaving the prior instance orphaned with a stale end sentinel.\n *\n * Matches on anchor identity (not name alone): independent mounts of\n * the same-named component at different anchors must not collide with\n * each other.\n *\n * Returns the swapped handle when a matching anchor entry exists,\n * `null` otherwise so the caller can fall through to fresh mount /\n * hydrate.\n */\nexport function replaceComponentForAnchor<S, M, E, D = void>(\n name: string,\n newDef: ComponentDef<S, M, E, D>,\n anchor: Comment,\n): AppHandle | null {\n const entries = hmrRegistry.get(name)\n if (!entries || entries.length === 0) return null\n const matching = entries.find(\n (e): e is Extract<HmrEntry, { kind: 'anchor' }> => e.kind === 'anchor' && e.anchor === anchor,\n )\n if (!matching) return null\n const handle = swapEntry<S, M, E, D>(matching, name, newDef)\n console.log(`[LLui HMR] ${name} updated — state preserved`)\n return handle\n}\n\nfunction swapEntry<S, M, E, D = void>(\n entry: HmrEntry,\n name: string,\n newDef: ComponentDef<S, M, E, D>,\n): AppHandle {\n const typedInst = entry.inst as ComponentInstance<S, M, E>\n\n typedInst.def = {\n ...typedInst.def,\n update: newDef.update,\n view: newDef.view,\n onEffect: newDef.onEffect,\n __dirty: newDef.__dirty,\n __update: newDef.__update,\n __handlers: newDef.__handlers,\n }\n\n // Snapshot focus + selection + scroll BEFORE disposal — once the\n // root lifetime tears down its DOM, the activeElement and any\n // scrollable subtree are detached and can't be queried. We\n // restore best-effort after the new view renders. The cost of\n // skipping this step is the every-edit experience: the user\n // types in an input, saves, the input rebuilds and loses focus\n // and cursor position. That kills incremental editing flow.\n const ownerRoot: ParentNode | null =\n entry.kind === 'container' ? entry.container : (entry.anchor.parentElement ?? null)\n const focusSnapshot = ownerRoot ? captureFocus(ownerRoot) : null\n const scrollSnapshot = ownerRoot ? captureScroll(ownerRoot) : null\n\n disposeLifetime(typedInst.rootLifetime)\n\n // Clear the owned region per-kind.\n if (entry.kind === 'container') {\n entry.container.textContent = ''\n } else {\n // anchor kind — wipe siblings between anchor and endSentinel, keep the\n // anchor AND the end sentinel (they bracket the fresh render).\n let sib = entry.anchor.nextSibling\n while (sib !== null && sib !== entry.endSentinel) {\n const next = sib.nextSibling\n sib.parentNode!.removeChild(sib)\n sib = next\n }\n }\n\n typedInst.rootLifetime = createLifetime(null)\n typedInst.rootLifetime._kind = 'root'\n typedInst.allBindings = []\n typedInst.structuralBlocks = []\n\n setFlatBindings(typedInst.allBindings)\n setRenderContext({\n rootLifetime: typedInst.rootLifetime,\n state: typedInst.state,\n allBindings: typedInst.allBindings,\n structuralBlocks: typedInst.structuralBlocks,\n dom: typedInst.dom,\n container:\n entry.kind === 'container' ? entry.container : (entry.anchor.parentElement ?? undefined),\n send: typedInst.send as (msg: unknown) => void,\n instance: typedInst as ComponentInstance,\n })\n const nodes = typedInst.def.view(createView<S, M>(typedInst.send))\n clearRenderContext()\n setFlatBindings(null)\n\n if (entry.kind === 'container') {\n for (const node of nodes) {\n entry.container.appendChild(node)\n }\n } else {\n for (const node of nodes) {\n entry.anchor.parentNode!.insertBefore(node, entry.endSentinel)\n }\n }\n\n // Restore focus, selection, and scroll positions in the freshly\n // rendered DOM. Best-effort: when the new view's DOM has diverged\n // structurally (different IDs, different element ordering, the\n // input that was focused no longer exists), the restorers no-op\n // silently. This is the right tradeoff — failing loudly on\n // structural divergence would just mean every meaningful view\n // edit prints an error.\n if (ownerRoot) {\n if (focusSnapshot) restoreFocus(ownerRoot, focusSnapshot)\n if (scrollSnapshot) restoreScroll(ownerRoot, scrollSnapshot)\n }\n\n return makeReplacementHandle(name, entry, typedInst)\n}\n\nfunction makeReplacementHandle<S, M, E>(\n name: string,\n entry: HmrEntry,\n typedInst: ComponentInstance<S, M, E>,\n): AppHandle {\n const listeners = new Set<(s: unknown) => void>()\n typedInst._onCommit = (state: unknown) => {\n for (const l of Array.from(listeners)) {\n try {\n l(state)\n } catch (err) {\n console.error('[llui] listener threw:', err)\n }\n }\n }\n let disposed = false\n return {\n dispose() {\n if (disposed) return\n disposed = true\n listeners.clear()\n typedInst._onCommit = undefined\n unregisterForHmr(name, entry.inst)\n entry.inst.abortController.abort()\n unregisterInstance(entry.inst)\n disposeLifetime(typedInst.rootLifetime)\n if (entry.kind === 'container') {\n entry.container.textContent = ''\n } else {\n let sib = entry.anchor.nextSibling\n while (sib !== null && sib !== entry.endSentinel) {\n const next = sib.nextSibling\n sib.parentNode!.removeChild(sib)\n sib = next\n }\n entry.endSentinel.parentNode?.removeChild(entry.endSentinel)\n }\n },\n flush() {\n flushInstance(entry.inst)\n },\n send(msg: unknown) {\n ;(typedInst.send as (m: unknown) => void)(msg)\n },\n getState() {\n return typedInst.state\n },\n subscribe(listener: (state: unknown) => void) {\n if (disposed) return () => {}\n listeners.add(listener)\n return () => listeners.delete(listener)\n },\n getBindingDescriptors() {\n if (disposed) return []\n return getBindingDescriptors(typedInst as ComponentInstance)\n },\n swapUpdate(newUpdate, newOnEffect) {\n if (disposed) return\n flushInstance(entry.inst)\n ;(typedInst.def as { update: typeof newUpdate }).update = newUpdate\n if (newOnEffect !== undefined) {\n ;(typedInst.def as { onEffect?: typeof newOnEffect }).onEffect = newOnEffect\n }\n },\n runReducer(msg) {\n if (disposed) return null\n const [state, effects] = (\n typedInst.def.update as (s: unknown, m: unknown) => [unknown, unknown[]]\n )(typedInst.state, msg)\n return { state, effects: effects as unknown[] }\n },\n setOnBindingError(hook) {\n if (disposed) return\n typedInst._onBindingError = hook ?? undefined\n },\n }\n}\n\n// ── Focus / selection / scroll preservation across HMR ──────────\n\n/**\n * What we record before disposing the root DOM. The locator is a\n * structural pointer: prefer `id` (resilient to view restructuring),\n * fall back to a child-index path through the rendered subtree. If\n * the new DOM doesn't match either, the restore call no-ops.\n */\ntype FocusSnapshot = {\n /** The element's `id` if it had one, else `null`. */\n id: string | null\n /** Sibling-index path from `ownerRoot` down to the focused element. */\n path: number[]\n /** Selection range if the focused element is a text input/textarea. */\n selection: { start: number; end: number; direction: 'forward' | 'backward' | 'none' } | null\n}\n\ntype ScrollSnapshot = Array<{\n id: string | null\n path: number[]\n scrollTop: number\n scrollLeft: number\n}>\n\nfunction captureFocus(root: ParentNode): FocusSnapshot | null {\n const doc = (root as Element).ownerDocument ?? globalThis.document\n if (!doc) return null\n const active = doc.activeElement\n if (!active || active === doc.body) return null\n // Only capture focus for elements inside our owned subtree —\n // anything outside is not ours to restore.\n if (!(root as ParentNode & Node).contains(active)) return null\n\n const path = pathFromAncestor(root as Node, active)\n if (path === null) return null\n\n let selection: FocusSnapshot['selection'] = null\n if (active instanceof HTMLInputElement || active instanceof HTMLTextAreaElement) {\n // Some input types (number, email, etc.) reject selectionStart access.\n // Wrapper try/catch keeps the snapshot resilient to those cases.\n try {\n if (active.selectionStart !== null && active.selectionEnd !== null) {\n selection = {\n start: active.selectionStart,\n end: active.selectionEnd,\n direction: (active.selectionDirection ?? 'none') as 'forward' | 'backward' | 'none',\n }\n }\n } catch {\n selection = null\n }\n }\n\n return {\n id: active.id || null,\n path,\n selection,\n }\n}\n\nfunction restoreFocus(root: ParentNode, snap: FocusSnapshot): void {\n const target = locate(root, snap.id, snap.path)\n if (!target || !(target instanceof HTMLElement)) return\n try {\n target.focus({ preventScroll: true })\n } catch {\n return\n }\n if (\n snap.selection &&\n (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement)\n ) {\n try {\n target.setSelectionRange(snap.selection.start, snap.selection.end, snap.selection.direction)\n } catch {\n // Some input types throw on setSelectionRange; ignore.\n }\n }\n}\n\nfunction captureScroll(root: ParentNode): ScrollSnapshot {\n // Walk the subtree and snapshot every element with non-zero\n // scroll. Most subtrees have at most a handful, so the per-edit\n // cost is small. Capturing all-zeroes wastes the restore work for\n // no benefit; the filter keeps things tight.\n const out: ScrollSnapshot = []\n const walk = (node: Node): void => {\n if (node instanceof HTMLElement) {\n if (node.scrollTop !== 0 || node.scrollLeft !== 0) {\n const path = pathFromAncestor(root as Node, node)\n if (path !== null) {\n out.push({\n id: node.id || null,\n path,\n scrollTop: node.scrollTop,\n scrollLeft: node.scrollLeft,\n })\n }\n }\n }\n for (let c = node.firstChild; c !== null; c = c.nextSibling) {\n walk(c)\n }\n }\n walk(root as Node)\n return out\n}\n\nfunction restoreScroll(root: ParentNode, snap: ScrollSnapshot): void {\n for (const s of snap) {\n const target = locate(root, s.id, s.path)\n if (!target || !(target instanceof HTMLElement)) continue\n target.scrollTop = s.scrollTop\n target.scrollLeft = s.scrollLeft\n }\n}\n\n/**\n * Compute the child-index path from `ancestor` down to `target`, or\n * `null` if `target` isn't in the subtree. The path is what gets\n * walked on restore — no document-wide selectors, no string-encoded\n * selectors that can break on punctuation in IDs.\n */\nfunction pathFromAncestor(ancestor: Node, target: Node): number[] | null {\n const path: number[] = []\n let cur: Node | null = target\n while (cur !== null && cur !== ancestor) {\n const parent: Node | null = cur.parentNode\n if (parent === null) return null\n let idx = 0\n let sib: Node | null = parent.firstChild\n while (sib !== null && sib !== cur) {\n idx++\n sib = sib.nextSibling\n }\n if (sib === null) return null\n path.push(idx)\n cur = parent\n }\n if (cur !== ancestor) return null\n return path.reverse()\n}\n\n/**\n * Restore lookup: try `id` first (cheap and resilient to structural\n * change), then walk the captured child-index path. Returns `null`\n * if neither lookup succeeds — the restore caller silently no-ops.\n */\nfunction locate(root: ParentNode, id: string | null, path: number[]): Element | null {\n if (id) {\n const doc = (root as Element).ownerDocument ?? globalThis.document\n if (doc) {\n const byId = doc.getElementById(id)\n if (byId && (root as ParentNode & Node).contains(byId)) return byId\n }\n }\n let cur: Node = root as Node\n for (const idx of path) {\n let child = cur.firstChild\n let i = 0\n while (child && i < idx) {\n child = child.nextSibling\n i++\n }\n if (!child) return null\n cur = child\n }\n return cur instanceof Element ? cur : null\n}\n"]}
|
package/dist/mount.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../src/mount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACnE,OAAO,EAAE,KAAK,MAAM,EAAc,MAAM,cAAc,CAAA;AA4CtD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB,GAAG,CAAC,EAAE;YAAE,GAAG,CAAC,EAAE,OAAO,CAAA;SAAE,CAAA;KACxB;CACF;AAoCD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,QAAQ,CAAA;IACzB;;;;;OAKG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAA;CAClC;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAC9B,SAAS,EAAE,WAAW,EACtB,GAAG,EAAE,YAAY,CAAC,CAAC,EAAE,C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/mount.js
CHANGED
|
@@ -65,13 +65,21 @@ export function _getDevToolsInstall() {
|
|
|
65
65
|
return devToolsInstall;
|
|
66
66
|
}
|
|
67
67
|
export function mountApp(container, def, data, options) {
|
|
68
|
-
// HMR: if this
|
|
69
|
-
// during hot update
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
//
|
|
68
|
+
// HMR: if this exact container already hosts a mount of this
|
|
69
|
+
// component (module re-execution during hot update re-runs the same
|
|
70
|
+
// mountApp call), swap the definition in place instead of creating a
|
|
71
|
+
// second instance. Match on container: when the same component name
|
|
72
|
+
// is mounted into N distinct containers (e.g. a page's onMount
|
|
73
|
+
// iterating placeholders), each call must produce its own fresh
|
|
74
|
+
// mount — swapping the existing entry would re-render into the
|
|
75
|
+
// wrong container and leave the new one empty.
|
|
76
|
+
//
|
|
77
|
+
// HMR swap bypasses parentLifetime — HMR re-mounts the outermost app
|
|
78
|
+
// handle, which in a layout setup means the layout re-mounts at the
|
|
79
|
+
// root and the rest of the chain is re-established via the normal
|
|
80
|
+
// mount path.
|
|
73
81
|
if (hmrModule && def.name && !options?.parentLifetime) {
|
|
74
|
-
const swapped = hmrModule.
|
|
82
|
+
const swapped = hmrModule.replaceComponentForContainer(def.name, def, container);
|
|
75
83
|
if (swapped)
|
|
76
84
|
return swapped;
|
|
77
85
|
}
|
|
@@ -186,6 +194,19 @@ export function mountAtAnchor(anchor, def, data, options) {
|
|
|
186
194
|
if (anchor.parentNode === null) {
|
|
187
195
|
throw new Error(`[LLui] mountAtAnchor: anchor comment must be attached to a live DOM tree before mount`);
|
|
188
196
|
}
|
|
197
|
+
// HMR fast path: a second call into the same anchor (typical of
|
|
198
|
+
// module re-execution that re-runs the user's mountAtAnchor call —
|
|
199
|
+
// e.g. a vike persistent layout layer) hot-swaps in place. Matches
|
|
200
|
+
// on anchor identity so independent mounts at different anchors of
|
|
201
|
+
// the same-named component still each produce their own instance.
|
|
202
|
+
// Without this, the existing end sentinel below would be reused but
|
|
203
|
+
// the prior instance would be fully orphaned (lifetime not disposed,
|
|
204
|
+
// HMR entry not unregistered, activeInstances entry not removed).
|
|
205
|
+
if (hmrModule && def.name && !options?.parentLifetime) {
|
|
206
|
+
const swapped = hmrModule.replaceComponentForAnchor(def.name, def, anchor);
|
|
207
|
+
if (swapped)
|
|
208
|
+
return swapped;
|
|
209
|
+
}
|
|
189
210
|
// Locate or synthesize the end sentinel.
|
|
190
211
|
const existingEnd = _findEndSentinel(anchor);
|
|
191
212
|
let endSentinel;
|
|
@@ -267,6 +288,15 @@ export function hydrateAtAnchor(anchor, def, serverState, options) {
|
|
|
267
288
|
if (anchor.parentNode === null) {
|
|
268
289
|
throw new Error(`[LLui] hydrateAtAnchor: anchor comment must be attached to a live DOM tree before hydrate`);
|
|
269
290
|
}
|
|
291
|
+
// HMR fast path: a second hydrateAtAnchor on the same anchor
|
|
292
|
+
// (typical of HMR module re-execution) hot-swaps in place. Matches
|
|
293
|
+
// mountAtAnchor's behavior. Without this, the second call leaks the
|
|
294
|
+
// first instance and stacks a second HMR entry under the same name.
|
|
295
|
+
if (hmrModule && def.name && !options?.parentLifetime) {
|
|
296
|
+
const swapped = hmrModule.replaceComponentForAnchor(def.name, def, anchor);
|
|
297
|
+
if (swapped)
|
|
298
|
+
return swapped;
|
|
299
|
+
}
|
|
270
300
|
const existingEnd = _findEndSentinel(anchor);
|
|
271
301
|
let endSentinel;
|
|
272
302
|
if (existingEnd !== null) {
|
|
@@ -469,6 +499,19 @@ function buildAppHandle(inst, hmrName, domCleanup) {
|
|
|
469
499
|
};
|
|
470
500
|
}
|
|
471
501
|
export function hydrateApp(container, def, serverState, options) {
|
|
502
|
+
// HMR fast path: a second hydrateApp into the same container
|
|
503
|
+
// (typical of HMR module re-execution) hot-swaps in place. Without
|
|
504
|
+
// this, the second call leaks the first instance — its lifetime is
|
|
505
|
+
// never disposed, its HMR entry stays in the registry, its bindings
|
|
506
|
+
// keep running on detached DOM. State preservation follows the same
|
|
507
|
+
// semantics as mountApp's fast path: the live instance keeps its
|
|
508
|
+
// current state and the new def's `serverState` argument is
|
|
509
|
+
// intentionally ignored on the swap (HMR preserves user state).
|
|
510
|
+
if (hmrModule && def.name && !options?.parentLifetime) {
|
|
511
|
+
const swapped = hmrModule.replaceComponentForContainer(def.name, def, container);
|
|
512
|
+
if (swapped)
|
|
513
|
+
return swapped;
|
|
514
|
+
}
|
|
472
515
|
// Run the original init once to capture its effects. The state it
|
|
473
516
|
// returns is discarded — we use `serverState` (what the server
|
|
474
517
|
// rendered with) instead. The effects are preserved and dispatched
|
package/dist/mount.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount.js","sourceRoot":"","sources":["../src/mount.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,UAAU,EAAE,MAAM,cAAc,CAAA;AACtD,OAAO,EAAE,uBAAuB,EAAE,aAAa,EAA0B,MAAM,kBAAkB,CAAA;AACjG,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAA;AAChE,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAEzF,2EAA2E;AAE3E;;;;GAIG;AACH,SAAS,cAAc,CAAC,MAAe,EAAE,UAAmB;IAC1D,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAA;IAChC,IAAI,MAAM,KAAK,IAAI;QAAE,OAAM;IAC3B,OAAO,MAAM,CAAC,WAAW,KAAK,IAAI,IAAI,MAAM,CAAC,WAAW,KAAK,UAAU,EAAE,CA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aAAa,CAAC,cAAc,CAAC,CAAA;IAE7B,sEAAsE;IACtE,SAAS,CAAC,eAAe,CAAC,GAAG,KAAK,CAAC,CAAA;IAEnC,sEAAsE;IACtE,eAAe,CAAC,YAAY,CAAC,CAAA;IAE7B,sEAAsE;IACtE,kEAAkE;IAClE,qEAAqE;IACrE,qEAAqE;IACrE,mEAAmE;IACnE,mDAAmD;IACnD,IAAI,OAAO,EAAE,uBAAuB,EAAE,CAAC;QACrC,sBAAsB,CAAC,IAAI,CAAC,CAAA;IAC9B,CAAC;SAAM,CAAC;QACN,sBAAsB,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;IAC5C,CAAC;IAED,gBAAgB,CAAC,IAAI,CAAC,CAAA;IACtB,wDAAwD;IACxD,8DAA8D;IAC9D,+DAA+D;IAC/D,gCAAgC;IAChC,IAAI,SAAS,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC;QACjC,SAAS,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC,CAAA;IAC5D,CAAC;IACD,OAAO,cAAc,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,IAAI,IAAI,EAAE,GAAG,EAAE;QACxD,SAAS,CAAC,WAAW,GAAG,EAAE,CAAA;IAC5B,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import type { ComponentDef, AppHandle, Lifetime } from './types.js'\nimport { type DomEnv, browserEnv } from './dom-env.js'\nimport { createComponentInstance, flushInstance, type ComponentInstance } from './update-loop.js'\nimport { disposeLifetime } from './lifetime.js'\nimport { setRenderContext, clearRenderContext } from './render-context.js'\nimport { setFlatBindings } from './binding.js'\nimport { getBindingDescriptors } from './binding-descriptors.js'\nimport { registerInstance, unregisterInstance } from './runtime.js'\nimport { createView } from './view-helpers.js'\nimport { pushMountQueue, popMountQueue, flushMountQueue } from './primitives/on-mount.js'\n\n// ── Sentinel-region helpers (used by anchor-based mount primitives) ─────\n\n/**\n * Remove every sibling from `anchor.nextSibling` up to but not including\n * `stopBefore`. Used by anchor-based mount primitives and their HMR\n * swap path to clear the owned DOM region between the pair.\n */\nfunction _removeBetween(anchor: Comment, stopBefore: Comment): void {\n const parent = anchor.parentNode\n if (parent === null) return\n while (anchor.nextSibling !== null && anchor.nextSibling !== stopBefore) {\n parent.removeChild(anchor.nextSibling)\n }\n}\n\n/**\n * Walk forward from `anchor.nextSibling` looking for an existing\n * `<!-- llui-mount-end -->` sentinel. Used by mount/hydrate at anchor\n * to reuse a server-emitted (or stale) sentinel rather than synthesizing\n * a duplicate. Returns null if no matching comment is found before the\n * end of the parent's children.\n */\nfunction _findEndSentinel(anchor: Comment): Comment | null {\n let node: Node | null = anchor.nextSibling\n while (node !== null) {\n if (node.nodeType === 8 && (node as Comment).nodeValue === 'llui-mount-end') {\n return node as Comment\n }\n node = node.nextSibling\n }\n return null\n}\n\n// Vite injects import.meta.env.DEV — declare the shape for TypeScript\ndeclare global {\n interface ImportMeta {\n env?: { DEV?: boolean }\n }\n}\n\n// ── HMR (dev only) ──────────────────────────────────────────────\n// Set by enableHmr() from '@llui/dom/hmr' — never imported in production.\n\nlet hmrModule: typeof import('./hmr') | null = null\n\n/**\n * @internal Called by enableHmr in the hmr module. Tests use this\n * (paired with `_getHmrModule`) to snapshot/restore prior state across\n * suite boundaries — pass `null` to clear.\n */\nexport function _setHmrModule(m: typeof import('./hmr') | null): void {\n hmrModule = m\n}\n\n/** @internal Read the currently-installed HMR module (or null). */\nexport function _getHmrModule(): typeof import('./hmr') | null {\n return hmrModule\n}\n\n// ── DevTools auto-install (dev only) ────────────────────────────\n// Set by enableDevTools() from '@llui/dom/devtools' — never imported in production.\n\nlet devToolsInstall: ((inst: object) => void) | null = null\n\n/** @internal Called by enableDevTools in the devtools module */\nexport function _setDevToolsInstall(fn: ((inst: object) => void) | null): void {\n devToolsInstall = fn\n}\n\n/** @internal Read the currently-installed devtools-install hook (or null). */\nexport function _getDevToolsInstall(): ((inst: object) => void) | null {\n return devToolsInstall\n}\n\nexport interface MountOptions {\n devTools?: boolean\n /**\n * Parent scope for the mounted component's rootLifetime. When provided,\n * the rootLifetime is created as a child of this scope — context lookups\n * from within the component walk up through the parent's scope tree,\n * and disposing the parent scope cascades into this instance's scope.\n * Used by `@llui/vike`'s persistent-layout machinery to mount a page\n * as a true scope-tree child of its enclosing layout, so layout-\n * provided contexts flow naturally into pages via `useContext`.\n *\n * When omitted (the default), the rootLifetime is detached — same as\n * every `mountApp` call before persistent layouts existed.\n */\n parentLifetime?: Lifetime\n /**\n * DOM env override. Defaults to `browserEnv()` — wraps the browser\n * globals. Specify only when mounting into a non-browser DOM (e.g.\n * a jsdom instance held by a test harness, or isolated DOM per\n * shadow root).\n */\n env?: DomEnv\n /**\n * **`hydrateApp` / `hydrateAtAnchor` only.** When `true`, fire the\n * effects that `init()` returned during hydration the same way\n * `mountApp` does on a fresh mount. Defaults to `false` because the\n * SSR render already ran `init()` on the server, and re-running its\n * effects on the client typically produces duplicate work — an\n * `httpGet` issued from `init()` would fetch on the server *and* on\n * hydration; a subscription would attach twice; etc.\n *\n * Opt in only when:\n * - `init()` returns no effects, OR\n * - all returned effects are idempotent / client-only (e.g.\n * wiring a `window` event listener, opening a `WebSocket`), AND\n * - the SSR path didn't run them (typically when `init()` checks a\n * `loaded` flag in state and returns `[]` on the server).\n *\n * Pre-0.0.31 behavior was to always run init effects on hydrate;\n * the option preserves it on demand for projects that depended on\n * it. The default-off direction matches the safer expectation that\n * \"hydration should be cheap and side-effect-free.\"\n */\n runInitEffectsOnHydrate?: boolean\n}\n\nexport function mountApp<S, M, E>(\n container: HTMLElement,\n def: ComponentDef<S, M, E>,\n data?: undefined,\n options?: MountOptions,\n): AppHandle\nexport function mountApp<S, M, E, D>(\n container: HTMLElement,\n def: ComponentDef<S, M, E, D>,\n data: D,\n options?: MountOptions,\n): AppHandle\nexport function mountApp<S, M, E, D>(\n container: HTMLElement,\n def: ComponentDef<S, M, E, D>,\n data?: D,\n options?: MountOptions,\n): AppHandle {\n // HMR: if this component is already mounted (module re-execution\n // during hot update), swap the definition instead of creating a new instance.\n // HMR swap bypasses parentLifetime — HMR re-mounts the outermost app handle,\n // which in a layout setup means the layout re-mounts at the root and the\n // rest of the chain is re-established via the normal mount path.\n if (hmrModule && def.name && !options?.parentLifetime) {\n const swapped = hmrModule.replaceComponent(def.name, def)\n if (swapped) return swapped\n }\n\n const inst = createComponentInstance(def, data, options?.parentLifetime ?? null, options?.env)\n\n // Dev-only: auto-install devtools if enabled via '@llui/dom/devtools' import\n if (devToolsInstall) devToolsInstall(inst)\n\n // Dev-only: warn if initial state contains non-serializable values.\n // Silent bug-bomb: Date/Map/Set/class instances break SSR, hydration, replay tools.\n if (import.meta.env?.DEV) {\n const offender = findNonSerializable(inst.state)\n if (offender) {\n console.warn(\n `[LLui] <${def.name}> initial state contains a non-serializable value at \"${offender.path}\":`,\n offender.value,\n '\\nState must be plain JSON (no Date/Map/Set/class instances/functions).' +\n '\\nThis will break SSR hydration, state replay, and devtools snapshots.' +\n '\\nhint: Convert to a serializable representation (e.g., Date → ISO string, Map → Record).',\n )\n }\n }\n\n // Run view() within a render context so primitives can register bindings.\n // Also collect onMount callbacks in a queue we'll flush synchronously\n // after node insertion — prevents the race where a user event fires\n // between mount and the queueMicrotask callback running.\n const { queue: onMountQueue, prev: prevMountQueue } = pushMountQueue()\n setFlatBindings(inst.allBindings)\n setRenderContext({\n ...inst,\n container,\n send: inst.send as (msg: unknown) => void,\n instance: inst as ComponentInstance,\n })\n const nodes = def.view(createView<S, M>(inst.send))\n clearRenderContext()\n setFlatBindings(null)\n popMountQueue(prevMountQueue)\n\n // Batch-insert via DocumentFragment — one layout-invalidating operation\n // instead of N individual appendChild calls on a live container element.\n if (nodes.length > 1) {\n const frag = inst.dom.createDocumentFragment()\n for (const node of nodes) frag.appendChild(node)\n container.appendChild(frag)\n } else if (nodes.length === 1) {\n container.appendChild(nodes[0]!)\n }\n\n // Flush onMount callbacks SYNCHRONOUSLY now that the DOM is in place.\n // Any listeners they attach are ready before this function returns,\n // so a synchronous dispatchEvent in the caller's next line fires\n // against a fully-wired tree.\n flushMountQueue(onMountQueue)\n\n registerInstance(inst)\n if (hmrModule && def.name) {\n hmrModule.registerForHmr(def.name, inst, container)\n }\n dispatchInitialEffects(inst)\n return buildAppHandle(inst, def.name ?? null, () => {\n container.textContent = ''\n })\n}\n\n// Walks an object graph looking for non-JSON-serializable values. Returns the\n// first offender found (depth-first), or null if everything is fine. Stops at\n// depth 6 to bound runtime cost for large states.\nfunction findNonSerializable(\n v: unknown,\n path = 'state',\n depth = 0,\n seen = new WeakSet<object>(),\n): { path: string; value: unknown } | null {\n if (depth > 6) return null\n if (v === null || v === undefined) return null\n const t = typeof v\n if (t === 'string' || t === 'number' || t === 'boolean') return null\n if (t === 'function') return { path, value: v }\n if (t === 'symbol' || t === 'bigint') return { path, value: v }\n if (t !== 'object') return null\n const obj = v as object\n if (seen.has(obj)) return null\n seen.add(obj)\n if (obj instanceof Date) return { path: `${path} (Date)`, value: v }\n if (obj instanceof Map) return { path: `${path} (Map)`, value: v }\n if (obj instanceof Set) return { path: `${path} (Set)`, value: v }\n if (obj instanceof RegExp) return { path: `${path} (RegExp)`, value: v }\n if (obj instanceof Promise) return { path: `${path} (Promise)`, value: v }\n // Plain objects/arrays have Object.prototype / Array.prototype. Class instances\n // have a different prototype.\n const proto = Object.getPrototypeOf(obj)\n if (proto !== null && proto !== Object.prototype && proto !== Array.prototype) {\n return { path: `${path} (${proto?.constructor?.name ?? 'class instance'})`, value: v }\n }\n if (Array.isArray(v)) {\n for (let i = 0; i < v.length; i++) {\n const r = findNonSerializable(v[i], `${path}[${i}]`, depth + 1, seen)\n if (r) return r\n }\n return null\n }\n for (const k of Object.keys(obj)) {\n const r = findNonSerializable(\n (obj as Record<string, unknown>)[k],\n `${path}.${k}`,\n depth + 1,\n seen,\n )\n if (r) return r\n }\n return null\n}\n\n/**\n * Mount a component relative to a comment anchor rather than inside a\n * container element. Inserts a synthesized end sentinel (`<!-- llui-mount-end -->`)\n * immediately after the anchor and places the component's nodes between\n * the pair. The anchor must already be attached to a live DOM tree.\n *\n * Unlike `mountApp`, the caller's anchor node is preserved across the\n * handle's lifetime — only the content between the pair (and the end\n * sentinel itself) is disposed. Used by `@llui/vike` persistent layouts\n * to mount chain layers without a wrapper element.\n *\n * If a pre-existing `<!-- llui-mount-end -->` is found after the anchor\n * (e.g. stale from an undisposed prior mount), the content between the\n * anchor and that sentinel is swept and the sentinel is reused. Dev mode\n * warns in that case.\n */\nexport function mountAtAnchor<S, M, E>(\n anchor: Comment,\n def: ComponentDef<S, M, E>,\n data?: undefined,\n options?: MountOptions,\n): AppHandle\nexport function mountAtAnchor<S, M, E, D>(\n anchor: Comment,\n def: ComponentDef<S, M, E, D>,\n data: D,\n options?: MountOptions,\n): AppHandle\nexport function mountAtAnchor<S, M, E, D>(\n anchor: Comment,\n def: ComponentDef<S, M, E, D>,\n data?: D,\n options?: MountOptions,\n): AppHandle {\n if (anchor.parentNode === null) {\n throw new Error(\n `[LLui] mountAtAnchor: anchor comment must be attached to a live DOM tree before mount`,\n )\n }\n\n // Locate or synthesize the end sentinel.\n const existingEnd = _findEndSentinel(anchor)\n let endSentinel: Comment\n if (existingEnd !== null) {\n if (import.meta.env?.DEV) {\n console.warn(\n `[LLui] mountAtAnchor: anchor has a pre-existing end sentinel. ` +\n `A prior mount was not disposed — sweeping stale siblings and reusing the sentinel.`,\n )\n }\n _removeBetween(anchor, existingEnd)\n endSentinel = existingEnd\n } else {\n // Use the caller-provided env if any — end-sentinel creation happens\n // before `inst` exists, so we pick the env directly from options.\n // (browserEnv() fallback matches what createComponentInstance will\n // use below when options.env is undefined.)\n endSentinel = (options?.env ?? browserEnv()).createComment('llui-mount-end')\n anchor.parentNode.insertBefore(endSentinel, anchor.nextSibling)\n }\n\n const inst = createComponentInstance(def, data, options?.parentLifetime ?? null, options?.env)\n\n if (devToolsInstall) devToolsInstall(inst)\n\n if (import.meta.env?.DEV) {\n const offender = findNonSerializable(inst.state)\n if (offender) {\n console.warn(\n `[LLui] <${def.name}> initial state contains a non-serializable value at \"${offender.path}\":`,\n offender.value,\n '\\nState must be plain JSON (no Date/Map/Set/class instances/functions).' +\n '\\nThis will break SSR hydration, state replay, and devtools snapshots.' +\n '\\nhint: Convert to a serializable representation (e.g., Date → ISO string, Map → Record).',\n )\n }\n }\n\n const { queue: onMountQueue, prev: prevMountQueue } = pushMountQueue()\n setFlatBindings(inst.allBindings)\n setRenderContext({\n ...inst,\n container: anchor.parentElement ?? undefined,\n send: inst.send as (msg: unknown) => void,\n instance: inst as ComponentInstance,\n })\n const nodes = def.view(createView<S, M>(inst.send))\n clearRenderContext()\n setFlatBindings(null)\n popMountQueue(prevMountQueue)\n\n // Batch-insert via DocumentFragment — one layout pass instead of N.\n if (nodes.length > 1) {\n const frag = inst.dom.createDocumentFragment()\n for (const node of nodes) frag.appendChild(node)\n anchor.parentNode.insertBefore(frag, endSentinel)\n } else if (nodes.length === 1) {\n anchor.parentNode.insertBefore(nodes[0]!, endSentinel)\n }\n\n flushMountQueue(onMountQueue)\n\n registerInstance(inst)\n if (hmrModule && def.name) {\n hmrModule.registerForAnchor(def.name, inst, anchor, endSentinel)\n }\n dispatchInitialEffects(inst)\n return buildAppHandle(inst, def.name ?? null, () => {\n _removeBetween(anchor, endSentinel)\n endSentinel.parentNode?.removeChild(endSentinel)\n })\n}\n\n/**\n * Hydrate a component relative to a comment anchor rather than inside a\n * container element. Analogous to `hydrateApp` — uses `serverState` as\n * the initial state (not `init()`'s output) while preserving `init()`'s\n * effects for post-mount dispatch.\n *\n * The DOM-handling path is identical to `mountAtAnchor`: reuses a\n * pre-existing end sentinel when present, synthesizes one otherwise.\n * Atomic-swaps the owned region whether or not server content is there\n * to replace. No error for a missing end sentinel — the vike chain's\n * outer `hydrateApp`'s `replaceChildren` wipes inner layers' sentinels,\n * so inner-layer `hydrateAtAnchor` calls routinely find nothing to\n * reuse, and that's normal.\n */\nexport function hydrateAtAnchor<S, M, E, D = void>(\n anchor: Comment,\n def: ComponentDef<S, M, E, D>,\n serverState: S,\n options?: MountOptions,\n): AppHandle {\n if (anchor.parentNode === null) {\n throw new Error(\n `[LLui] hydrateAtAnchor: anchor comment must be attached to a live DOM tree before hydrate`,\n )\n }\n\n const existingEnd = _findEndSentinel(anchor)\n let endSentinel: Comment\n if (existingEnd !== null) {\n _removeBetween(anchor, existingEnd)\n endSentinel = existingEnd\n } else {\n endSentinel = (options?.env ?? browserEnv()).createComment('llui-mount-end')\n anchor.parentNode.insertBefore(endSentinel, anchor.nextSibling)\n }\n\n // Run original init() to capture effects, then override state with server's.\n const [, originalEffects] = (def.init as (data: unknown) => [S, E[]])(undefined)\n const hydrateDef: ComponentDef<S, M, E> = {\n ...def,\n init: () => [serverState, originalEffects],\n }\n\n const inst = createComponentInstance(\n hydrateDef,\n undefined,\n options?.parentLifetime ?? null,\n options?.env,\n )\n\n if (devToolsInstall) devToolsInstall(inst)\n\n const { queue: onMountQueue, prev: prevMountQueue } = pushMountQueue()\n setFlatBindings(inst.allBindings)\n setRenderContext({\n ...inst,\n container: anchor.parentElement ?? undefined,\n send: inst.send as (msg: unknown) => void,\n instance: inst as ComponentInstance,\n })\n const nodes = hydrateDef.view(createView<S, M>(inst.send))\n clearRenderContext()\n setFlatBindings(null)\n popMountQueue(prevMountQueue)\n\n if (nodes.length > 1) {\n const frag = inst.dom.createDocumentFragment()\n for (const node of nodes) frag.appendChild(node)\n anchor.parentNode.insertBefore(frag, endSentinel)\n } else if (nodes.length === 1) {\n anchor.parentNode.insertBefore(nodes[0]!, endSentinel)\n }\n\n flushMountQueue(onMountQueue)\n\n registerInstance(inst)\n if (hmrModule && def.name) {\n hmrModule.registerForAnchor(def.name, inst, anchor, endSentinel)\n }\n // Hydration: skip init's effects by default. The SSR pass already ran\n // them on the server; re-running on the client typically produces\n // duplicate work (double fetches, double subscriptions). Opt back in\n // via `MountOptions.runInitEffectsOnHydrate: true`.\n if (options?.runInitEffectsOnHydrate) {\n dispatchInitialEffects(inst)\n } else {\n warnDroppedInitEffects(inst, 'hydrateAtAnchor')\n }\n return buildAppHandle(inst, def.name ?? null, () => {\n _removeBetween(anchor, endSentinel)\n endSentinel.parentNode?.removeChild(endSentinel)\n })\n}\n\nfunction dispatchInitialEffects<S, M, E>(\n inst: ReturnType<typeof createComponentInstance<S, M, E>>,\n): void {\n if (inst.initialEffects.length === 0 || !inst.def.onEffect) return\n for (const effect of inst.initialEffects) {\n inst.def.onEffect({ effect, send: inst.send, signal: inst.signal })\n }\n inst.initialEffects = []\n}\n\n/**\n * Dev-only warning when a hydrate path silently drops a non-empty\n * `initialEffects` array. The default-skip behavior is deliberate (the\n * server already ran them), but if `init()` produces effects that\n * weren't run on the server — typically client-only init pipelines —\n * silent drop is a footgun. Surface the count and the opt-in.\n */\nfunction warnDroppedInitEffects<S, M, E>(\n inst: ReturnType<typeof createComponentInstance<S, M, E>>,\n via: 'hydrateApp' | 'hydrateAtAnchor',\n): void {\n if (!import.meta.env?.DEV) return\n if (inst.initialEffects.length === 0) return\n const name = inst.def.name ?? '<anonymous>'\n console.warn(\n `[LLui] ${via}: skipped ${inst.initialEffects.length} init effect(s) for \"${name}\". ` +\n `Hydration drops init effects by default since the server already ran them. ` +\n `If these effects only fire on the client, pass \\`runInitEffectsOnHydrate: true\\` to opt in.`,\n )\n}\n\n/**\n * Build the `AppHandle` returned by every mount/hydrate path. Captures\n * the `_onCommit` listener registry, the `disposed` flag, and the\n * standard `flush` / `send` / `getState` / `subscribe` shape — all\n * code that was previously duplicated four times across `mountApp`,\n * `mountAtAnchor`, `hydrateApp`, and `hydrateAtAnchor`.\n *\n * Variation lives in the two parameters:\n * - `hmrName` — the def's name used to call `hmrModule.unregisterForHmr`\n * on dispose. Pass `null` to skip HMR unregistration (no current\n * mount path needs that, but it keeps the helper honest).\n * - `domCleanup` — final teardown step that detaches mounted nodes.\n * Container-rooted paths set `container.textContent = ''`;\n * anchor-rooted paths call `_removeBetween(anchor, endSentinel)`\n * and detach the end sentinel. Runs LAST in the dispose chain to\n * match the historical ordering exactly (lifetime is disposed\n * before nodes are detached, so binding teardown sees attached\n * DOM until the very end).\n *\n * The mount-path-parity test in `mount-path-parity.test.ts` enforces\n * that each public entry point produces structurally identical\n * AppHandle behavior — this helper is the realisation of that\n * promise.\n */\nfunction buildAppHandle<S, M, E>(\n inst: ReturnType<typeof createComponentInstance<S, M, E>>,\n hmrName: string | null,\n domCleanup: () => void,\n): AppHandle {\n let disposed = false\n const listeners = new Set<(s: unknown) => void>()\n\n inst._onCommit = (state: unknown) => {\n for (const l of Array.from(listeners)) {\n try {\n l(state)\n } catch (err) {\n console.error('[llui] listener threw:', err)\n }\n }\n }\n\n return {\n dispose() {\n if (disposed) return\n disposed = true\n listeners.clear()\n inst._onCommit = undefined\n if (hmrModule && hmrName) hmrModule.unregisterForHmr(hmrName, inst)\n inst.abortController.abort()\n unregisterInstance(inst)\n // Tag the root scope so the disposer log reports app-level\n // teardown distinct from in-tree component-unmount events.\n inst.rootLifetime.disposalCause = 'app-unmount'\n disposeLifetime(inst.rootLifetime)\n domCleanup()\n },\n flush() {\n if (disposed) return\n flushInstance(inst)\n },\n send(msg: unknown) {\n if (disposed) return\n ;(inst.send as (m: unknown) => void)(msg)\n },\n getState() {\n if (disposed) {\n throw new Error(\n '[LLui] AppHandle.getState() called after dispose — handle is dead. ' +\n 'Detach your event listener / cancel your timer when the handle ' +\n 'is disposed to avoid stale reads.',\n )\n }\n return inst.state\n },\n subscribe(listener: (state: unknown) => void) {\n if (disposed) return () => {}\n listeners.add(listener)\n return () => listeners.delete(listener)\n },\n getBindingDescriptors() {\n if (disposed) return []\n return getBindingDescriptors(inst as ComponentInstance)\n },\n swapUpdate(newUpdate, newOnEffect) {\n if (disposed) return\n // Drain pending messages with the OLD update first — anything\n // already in the queue was constructed under the old contract,\n // and re-routing it through a new reducer mid-flight could mix\n // half of one transition with half of another (e.g. a payload\n // shape the new update no longer accepts).\n flushInstance(inst)\n // Mutate the def in place so subsequent `inst.def.update`\n // reads — including the per-message read in `flushInstance`'s\n // generic loop — pick up the new function. We deliberately\n // don't replace `inst.def` itself: existing closures, the\n // `__update` fast path, and `__handlers` all stay valid; only\n // the user-visible reducer function changes.\n ;(inst.def as { update: typeof newUpdate }).update = newUpdate\n if (newOnEffect !== undefined) {\n ;(inst.def as { onEffect?: typeof newOnEffect }).onEffect = newOnEffect\n }\n },\n runReducer(msg) {\n if (disposed) return null\n // Direct invocation against current state. No subscribe, no\n // flush, no effect handler. The reducer's contract per TEA is\n // a pure function — calling it twice with the same args is a\n // no-op other than allocations. Returning the raw tuple\n // shape lets the agent inspect both halves without interpreting.\n const [state, effects] = (\n inst.def.update as (s: unknown, m: unknown) => [unknown, unknown[]]\n )(inst.state, msg)\n return { state, effects: effects as unknown[] }\n },\n setOnBindingError(hook) {\n if (disposed) return\n inst._onBindingError = hook ?? undefined\n },\n }\n}\n\nexport function hydrateApp<S, M, E, D = void>(\n container: HTMLElement,\n def: ComponentDef<S, M, E, D>,\n serverState: S,\n options?: MountOptions,\n): AppHandle {\n // Run the original init once to capture its effects. The state it\n // returns is discarded — we use `serverState` (what the server\n // rendered with) instead. The effects are preserved and dispatched\n // after the DOM is in place, so components that rely on \"load data\n // or wire subscriptions on mount\" behave consistently between fresh\n // mount and SSR+hydrate. If the original init has already-loaded\n // data for the hydration case, gate the effect emission inside init\n // itself (e.g. based on a `loaded` flag in state).\n const [, originalEffects] = (def.init as (data: unknown) => [S, E[]])(undefined)\n\n const hydrateDef: ComponentDef<S, M, E> = {\n ...def,\n init: () => [serverState, originalEffects],\n }\n\n const inst = createComponentInstance(\n hydrateDef,\n undefined,\n options?.parentLifetime ?? null,\n options?.env,\n )\n\n // Dev-only: auto-install devtools if enabled via '@llui/dom/devtools'\n // import. The other three mount paths (mountApp / mountAtAnchor /\n // hydrateAtAnchor) all call this; without it, the hydrated layout\n // never appears in `window.__lluiComponents`, never sets\n // `window.__lluiDebug`, and is invisible to MCP / agent client /\n // devtools console — so a vike SSR app's outermost layout silently\n // drops out of every observability surface.\n if (devToolsInstall) devToolsInstall(inst)\n\n // Build the component DOM and swap atomically with server HTML.\n // Server HTML remains visible until JS finishes — no flash.\n // onMount callbacks are collected in a queue and flushed synchronously\n // after the swap, matching mountApp's ordering.\n const { queue: onMountQueue, prev: prevMountQueue } = pushMountQueue()\n setFlatBindings(inst.allBindings)\n setRenderContext({\n ...inst,\n container,\n send: inst.send as (msg: unknown) => void,\n instance: inst as ComponentInstance,\n })\n const nodes = hydrateDef.view(createView<S, M>(inst.send))\n clearRenderContext()\n setFlatBindings(null)\n popMountQueue(prevMountQueue)\n\n // Atomic swap — replaces server HTML with client DOM in one operation\n container.replaceChildren(...nodes)\n\n // Flush onMount callbacks synchronously now that the DOM is in place.\n flushMountQueue(onMountQueue)\n\n // Hydration: skip init's effects by default. The SSR pass already ran\n // them on the server; re-running on the client typically produces\n // duplicate work (double fetches, double subscriptions). Opt back in\n // via `MountOptions.runInitEffectsOnHydrate: true` for projects that\n // need the post-swap dispatch (typically when `init()` is gated by\n // a `loaded` flag and returns `[]` on the server).\n if (options?.runInitEffectsOnHydrate) {\n dispatchInitialEffects(inst)\n } else {\n warnDroppedInitEffects(inst, 'hydrateApp')\n }\n\n registerInstance(inst)\n // HMR registration — same as mountApp / mountAtAnchor /\n // hydrateAtAnchor. Without it, replaceComponent(name, newDef)\n // silently no-ops on the hydrated layout layer because the HMR\n // registry has no entry for it.\n if (hmrModule && hydrateDef.name) {\n hmrModule.registerForHmr(hydrateDef.name, inst, container)\n }\n return buildAppHandle(inst, hydrateDef.name ?? null, () => {\n container.textContent = ''\n })\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mount.js","sourceRoot":"","sources":["../src/mount.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,UAAU,EAAE,MAAM,cAAc,CAAA;AACtD,OAAO,EAAE,uBAAuB,EAAE,aAAa,EAA0B,MAAM,kBAAkB,CAAA;AACjG,OAAO,EAAE,eAAe,EAAE,MAAM,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EAAE,UAAU,CAAC,IAAI,IAAI,IAAI,EAAE,GAAG,EAAE;QACxD,SAAS,CAAC,WAAW,GAAG,EAAE,CAAA;IAC5B,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import type { ComponentDef, AppHandle, Lifetime } from './types.js'\nimport { type DomEnv, browserEnv } from './dom-env.js'\nimport { createComponentInstance, flushInstance, type ComponentInstance } from './update-loop.js'\nimport { disposeLifetime } from './lifetime.js'\nimport { setRenderContext, clearRenderContext } from './render-context.js'\nimport { setFlatBindings } from './binding.js'\nimport { getBindingDescriptors } from './binding-descriptors.js'\nimport { registerInstance, unregisterInstance } from './runtime.js'\nimport { createView } from './view-helpers.js'\nimport { pushMountQueue, popMountQueue, flushMountQueue } from './primitives/on-mount.js'\n\n// ── Sentinel-region helpers (used by anchor-based mount primitives) ─────\n\n/**\n * Remove every sibling from `anchor.nextSibling` up to but not including\n * `stopBefore`. Used by anchor-based mount primitives and their HMR\n * swap path to clear the owned DOM region between the pair.\n */\nfunction _removeBetween(anchor: Comment, stopBefore: Comment): void {\n const parent = anchor.parentNode\n if (parent === null) return\n while (anchor.nextSibling !== null && anchor.nextSibling !== stopBefore) {\n parent.removeChild(anchor.nextSibling)\n }\n}\n\n/**\n * Walk forward from `anchor.nextSibling` looking for an existing\n * `<!-- llui-mount-end -->` sentinel. Used by mount/hydrate at anchor\n * to reuse a server-emitted (or stale) sentinel rather than synthesizing\n * a duplicate. Returns null if no matching comment is found before the\n * end of the parent's children.\n */\nfunction _findEndSentinel(anchor: Comment): Comment | null {\n let node: Node | null = anchor.nextSibling\n while (node !== null) {\n if (node.nodeType === 8 && (node as Comment).nodeValue === 'llui-mount-end') {\n return node as Comment\n }\n node = node.nextSibling\n }\n return null\n}\n\n// Vite injects import.meta.env.DEV — declare the shape for TypeScript\ndeclare global {\n interface ImportMeta {\n env?: { DEV?: boolean }\n }\n}\n\n// ── HMR (dev only) ──────────────────────────────────────────────\n// Set by enableHmr() from '@llui/dom/hmr' — never imported in production.\n\nlet hmrModule: typeof import('./hmr') | null = null\n\n/**\n * @internal Called by enableHmr in the hmr module. Tests use this\n * (paired with `_getHmrModule`) to snapshot/restore prior state across\n * suite boundaries — pass `null` to clear.\n */\nexport function _setHmrModule(m: typeof import('./hmr') | null): void {\n hmrModule = m\n}\n\n/** @internal Read the currently-installed HMR module (or null). */\nexport function _getHmrModule(): typeof import('./hmr') | null {\n return hmrModule\n}\n\n// ── DevTools auto-install (dev only) ────────────────────────────\n// Set by enableDevTools() from '@llui/dom/devtools' — never imported in production.\n\nlet devToolsInstall: ((inst: object) => void) | null = null\n\n/** @internal Called by enableDevTools in the devtools module */\nexport function _setDevToolsInstall(fn: ((inst: object) => void) | null): void {\n devToolsInstall = fn\n}\n\n/** @internal Read the currently-installed devtools-install hook (or null). */\nexport function _getDevToolsInstall(): ((inst: object) => void) | null {\n return devToolsInstall\n}\n\nexport interface MountOptions {\n devTools?: boolean\n /**\n * Parent scope for the mounted component's rootLifetime. When provided,\n * the rootLifetime is created as a child of this scope — context lookups\n * from within the component walk up through the parent's scope tree,\n * and disposing the parent scope cascades into this instance's scope.\n * Used by `@llui/vike`'s persistent-layout machinery to mount a page\n * as a true scope-tree child of its enclosing layout, so layout-\n * provided contexts flow naturally into pages via `useContext`.\n *\n * When omitted (the default), the rootLifetime is detached — same as\n * every `mountApp` call before persistent layouts existed.\n */\n parentLifetime?: Lifetime\n /**\n * DOM env override. Defaults to `browserEnv()` — wraps the browser\n * globals. Specify only when mounting into a non-browser DOM (e.g.\n * a jsdom instance held by a test harness, or isolated DOM per\n * shadow root).\n */\n env?: DomEnv\n /**\n * **`hydrateApp` / `hydrateAtAnchor` only.** When `true`, fire the\n * effects that `init()` returned during hydration the same way\n * `mountApp` does on a fresh mount. Defaults to `false` because the\n * SSR render already ran `init()` on the server, and re-running its\n * effects on the client typically produces duplicate work — an\n * `httpGet` issued from `init()` would fetch on the server *and* on\n * hydration; a subscription would attach twice; etc.\n *\n * Opt in only when:\n * - `init()` returns no effects, OR\n * - all returned effects are idempotent / client-only (e.g.\n * wiring a `window` event listener, opening a `WebSocket`), AND\n * - the SSR path didn't run them (typically when `init()` checks a\n * `loaded` flag in state and returns `[]` on the server).\n *\n * Pre-0.0.31 behavior was to always run init effects on hydrate;\n * the option preserves it on demand for projects that depended on\n * it. The default-off direction matches the safer expectation that\n * \"hydration should be cheap and side-effect-free.\"\n */\n runInitEffectsOnHydrate?: boolean\n}\n\nexport function mountApp<S, M, E>(\n container: HTMLElement,\n def: ComponentDef<S, M, E>,\n data?: undefined,\n options?: MountOptions,\n): AppHandle\nexport function mountApp<S, M, E, D>(\n container: HTMLElement,\n def: ComponentDef<S, M, E, D>,\n data: D,\n options?: MountOptions,\n): AppHandle\nexport function mountApp<S, M, E, D>(\n container: HTMLElement,\n def: ComponentDef<S, M, E, D>,\n data?: D,\n options?: MountOptions,\n): AppHandle {\n // HMR: if this exact container already hosts a mount of this\n // component (module re-execution during hot update re-runs the same\n // mountApp call), swap the definition in place instead of creating a\n // second instance. Match on container: when the same component name\n // is mounted into N distinct containers (e.g. a page's onMount\n // iterating placeholders), each call must produce its own fresh\n // mount — swapping the existing entry would re-render into the\n // wrong container and leave the new one empty.\n //\n // HMR swap bypasses parentLifetime — HMR re-mounts the outermost app\n // handle, which in a layout setup means the layout re-mounts at the\n // root and the rest of the chain is re-established via the normal\n // mount path.\n if (hmrModule && def.name && !options?.parentLifetime) {\n const swapped = hmrModule.replaceComponentForContainer(def.name, def, container)\n if (swapped) return swapped\n }\n\n const inst = createComponentInstance(def, data, options?.parentLifetime ?? null, options?.env)\n\n // Dev-only: auto-install devtools if enabled via '@llui/dom/devtools' import\n if (devToolsInstall) devToolsInstall(inst)\n\n // Dev-only: warn if initial state contains non-serializable values.\n // Silent bug-bomb: Date/Map/Set/class instances break SSR, hydration, replay tools.\n if (import.meta.env?.DEV) {\n const offender = findNonSerializable(inst.state)\n if (offender) {\n console.warn(\n `[LLui] <${def.name}> initial state contains a non-serializable value at \"${offender.path}\":`,\n offender.value,\n '\\nState must be plain JSON (no Date/Map/Set/class instances/functions).' +\n '\\nThis will break SSR hydration, state replay, and devtools snapshots.' +\n '\\nhint: Convert to a serializable representation (e.g., Date → ISO string, Map → Record).',\n )\n }\n }\n\n // Run view() within a render context so primitives can register bindings.\n // Also collect onMount callbacks in a queue we'll flush synchronously\n // after node insertion — prevents the race where a user event fires\n // between mount and the queueMicrotask callback running.\n const { queue: onMountQueue, prev: prevMountQueue } = pushMountQueue()\n setFlatBindings(inst.allBindings)\n setRenderContext({\n ...inst,\n container,\n send: inst.send as (msg: unknown) => void,\n instance: inst as ComponentInstance,\n })\n const nodes = def.view(createView<S, M>(inst.send))\n clearRenderContext()\n setFlatBindings(null)\n popMountQueue(prevMountQueue)\n\n // Batch-insert via DocumentFragment — one layout-invalidating operation\n // instead of N individual appendChild calls on a live container element.\n if (nodes.length > 1) {\n const frag = inst.dom.createDocumentFragment()\n for (const node of nodes) frag.appendChild(node)\n container.appendChild(frag)\n } else if (nodes.length === 1) {\n container.appendChild(nodes[0]!)\n }\n\n // Flush onMount callbacks SYNCHRONOUSLY now that the DOM is in place.\n // Any listeners they attach are ready before this function returns,\n // so a synchronous dispatchEvent in the caller's next line fires\n // against a fully-wired tree.\n flushMountQueue(onMountQueue)\n\n registerInstance(inst)\n if (hmrModule && def.name) {\n hmrModule.registerForHmr(def.name, inst, container)\n }\n dispatchInitialEffects(inst)\n return buildAppHandle(inst, def.name ?? null, () => {\n container.textContent = ''\n })\n}\n\n// Walks an object graph looking for non-JSON-serializable values. Returns the\n// first offender found (depth-first), or null if everything is fine. Stops at\n// depth 6 to bound runtime cost for large states.\nfunction findNonSerializable(\n v: unknown,\n path = 'state',\n depth = 0,\n seen = new WeakSet<object>(),\n): { path: string; value: unknown } | null {\n if (depth > 6) return null\n if (v === null || v === undefined) return null\n const t = typeof v\n if (t === 'string' || t === 'number' || t === 'boolean') return null\n if (t === 'function') return { path, value: v }\n if (t === 'symbol' || t === 'bigint') return { path, value: v }\n if (t !== 'object') return null\n const obj = v as object\n if (seen.has(obj)) return null\n seen.add(obj)\n if (obj instanceof Date) return { path: `${path} (Date)`, value: v }\n if (obj instanceof Map) return { path: `${path} (Map)`, value: v }\n if (obj instanceof Set) return { path: `${path} (Set)`, value: v }\n if (obj instanceof RegExp) return { path: `${path} (RegExp)`, value: v }\n if (obj instanceof Promise) return { path: `${path} (Promise)`, value: v }\n // Plain objects/arrays have Object.prototype / Array.prototype. Class instances\n // have a different prototype.\n const proto = Object.getPrototypeOf(obj)\n if (proto !== null && proto !== Object.prototype && proto !== Array.prototype) {\n return { path: `${path} (${proto?.constructor?.name ?? 'class instance'})`, value: v }\n }\n if (Array.isArray(v)) {\n for (let i = 0; i < v.length; i++) {\n const r = findNonSerializable(v[i], `${path}[${i}]`, depth + 1, seen)\n if (r) return r\n }\n return null\n }\n for (const k of Object.keys(obj)) {\n const r = findNonSerializable(\n (obj as Record<string, unknown>)[k],\n `${path}.${k}`,\n depth + 1,\n seen,\n )\n if (r) return r\n }\n return null\n}\n\n/**\n * Mount a component relative to a comment anchor rather than inside a\n * container element. Inserts a synthesized end sentinel (`<!-- llui-mount-end -->`)\n * immediately after the anchor and places the component's nodes between\n * the pair. The anchor must already be attached to a live DOM tree.\n *\n * Unlike `mountApp`, the caller's anchor node is preserved across the\n * handle's lifetime — only the content between the pair (and the end\n * sentinel itself) is disposed. Used by `@llui/vike` persistent layouts\n * to mount chain layers without a wrapper element.\n *\n * If a pre-existing `<!-- llui-mount-end -->` is found after the anchor\n * (e.g. stale from an undisposed prior mount), the content between the\n * anchor and that sentinel is swept and the sentinel is reused. Dev mode\n * warns in that case.\n */\nexport function mountAtAnchor<S, M, E>(\n anchor: Comment,\n def: ComponentDef<S, M, E>,\n data?: undefined,\n options?: MountOptions,\n): AppHandle\nexport function mountAtAnchor<S, M, E, D>(\n anchor: Comment,\n def: ComponentDef<S, M, E, D>,\n data: D,\n options?: MountOptions,\n): AppHandle\nexport function mountAtAnchor<S, M, E, D>(\n anchor: Comment,\n def: ComponentDef<S, M, E, D>,\n data?: D,\n options?: MountOptions,\n): AppHandle {\n if (anchor.parentNode === null) {\n throw new Error(\n `[LLui] mountAtAnchor: anchor comment must be attached to a live DOM tree before mount`,\n )\n }\n\n // HMR fast path: a second call into the same anchor (typical of\n // module re-execution that re-runs the user's mountAtAnchor call —\n // e.g. a vike persistent layout layer) hot-swaps in place. Matches\n // on anchor identity so independent mounts at different anchors of\n // the same-named component still each produce their own instance.\n // Without this, the existing end sentinel below would be reused but\n // the prior instance would be fully orphaned (lifetime not disposed,\n // HMR entry not unregistered, activeInstances entry not removed).\n if (hmrModule && def.name && !options?.parentLifetime) {\n const swapped = hmrModule.replaceComponentForAnchor(def.name, def, anchor)\n if (swapped) return swapped\n }\n\n // Locate or synthesize the end sentinel.\n const existingEnd = _findEndSentinel(anchor)\n let endSentinel: Comment\n if (existingEnd !== null) {\n if (import.meta.env?.DEV) {\n console.warn(\n `[LLui] mountAtAnchor: anchor has a pre-existing end sentinel. ` +\n `A prior mount was not disposed — sweeping stale siblings and reusing the sentinel.`,\n )\n }\n _removeBetween(anchor, existingEnd)\n endSentinel = existingEnd\n } else {\n // Use the caller-provided env if any — end-sentinel creation happens\n // before `inst` exists, so we pick the env directly from options.\n // (browserEnv() fallback matches what createComponentInstance will\n // use below when options.env is undefined.)\n endSentinel = (options?.env ?? browserEnv()).createComment('llui-mount-end')\n anchor.parentNode.insertBefore(endSentinel, anchor.nextSibling)\n }\n\n const inst = createComponentInstance(def, data, options?.parentLifetime ?? null, options?.env)\n\n if (devToolsInstall) devToolsInstall(inst)\n\n if (import.meta.env?.DEV) {\n const offender = findNonSerializable(inst.state)\n if (offender) {\n console.warn(\n `[LLui] <${def.name}> initial state contains a non-serializable value at \"${offender.path}\":`,\n offender.value,\n '\\nState must be plain JSON (no Date/Map/Set/class instances/functions).' +\n '\\nThis will break SSR hydration, state replay, and devtools snapshots.' +\n '\\nhint: Convert to a serializable representation (e.g., Date → ISO string, Map → Record).',\n )\n }\n }\n\n const { queue: onMountQueue, prev: prevMountQueue } = pushMountQueue()\n setFlatBindings(inst.allBindings)\n setRenderContext({\n ...inst,\n container: anchor.parentElement ?? undefined,\n send: inst.send as (msg: unknown) => void,\n instance: inst as ComponentInstance,\n })\n const nodes = def.view(createView<S, M>(inst.send))\n clearRenderContext()\n setFlatBindings(null)\n popMountQueue(prevMountQueue)\n\n // Batch-insert via DocumentFragment — one layout pass instead of N.\n if (nodes.length > 1) {\n const frag = inst.dom.createDocumentFragment()\n for (const node of nodes) frag.appendChild(node)\n anchor.parentNode.insertBefore(frag, endSentinel)\n } else if (nodes.length === 1) {\n anchor.parentNode.insertBefore(nodes[0]!, endSentinel)\n }\n\n flushMountQueue(onMountQueue)\n\n registerInstance(inst)\n if (hmrModule && def.name) {\n hmrModule.registerForAnchor(def.name, inst, anchor, endSentinel)\n }\n dispatchInitialEffects(inst)\n return buildAppHandle(inst, def.name ?? null, () => {\n _removeBetween(anchor, endSentinel)\n endSentinel.parentNode?.removeChild(endSentinel)\n })\n}\n\n/**\n * Hydrate a component relative to a comment anchor rather than inside a\n * container element. Analogous to `hydrateApp` — uses `serverState` as\n * the initial state (not `init()`'s output) while preserving `init()`'s\n * effects for post-mount dispatch.\n *\n * The DOM-handling path is identical to `mountAtAnchor`: reuses a\n * pre-existing end sentinel when present, synthesizes one otherwise.\n * Atomic-swaps the owned region whether or not server content is there\n * to replace. No error for a missing end sentinel — the vike chain's\n * outer `hydrateApp`'s `replaceChildren` wipes inner layers' sentinels,\n * so inner-layer `hydrateAtAnchor` calls routinely find nothing to\n * reuse, and that's normal.\n */\nexport function hydrateAtAnchor<S, M, E, D = void>(\n anchor: Comment,\n def: ComponentDef<S, M, E, D>,\n serverState: S,\n options?: MountOptions,\n): AppHandle {\n if (anchor.parentNode === null) {\n throw new Error(\n `[LLui] hydrateAtAnchor: anchor comment must be attached to a live DOM tree before hydrate`,\n )\n }\n\n // HMR fast path: a second hydrateAtAnchor on the same anchor\n // (typical of HMR module re-execution) hot-swaps in place. Matches\n // mountAtAnchor's behavior. Without this, the second call leaks the\n // first instance and stacks a second HMR entry under the same name.\n if (hmrModule && def.name && !options?.parentLifetime) {\n const swapped = hmrModule.replaceComponentForAnchor(def.name, def, anchor)\n if (swapped) return swapped\n }\n\n const existingEnd = _findEndSentinel(anchor)\n let endSentinel: Comment\n if (existingEnd !== null) {\n _removeBetween(anchor, existingEnd)\n endSentinel = existingEnd\n } else {\n endSentinel = (options?.env ?? browserEnv()).createComment('llui-mount-end')\n anchor.parentNode.insertBefore(endSentinel, anchor.nextSibling)\n }\n\n // Run original init() to capture effects, then override state with server's.\n const [, originalEffects] = (def.init as (data: unknown) => [S, E[]])(undefined)\n const hydrateDef: ComponentDef<S, M, E> = {\n ...def,\n init: () => [serverState, originalEffects],\n }\n\n const inst = createComponentInstance(\n hydrateDef,\n undefined,\n options?.parentLifetime ?? null,\n options?.env,\n )\n\n if (devToolsInstall) devToolsInstall(inst)\n\n const { queue: onMountQueue, prev: prevMountQueue } = pushMountQueue()\n setFlatBindings(inst.allBindings)\n setRenderContext({\n ...inst,\n container: anchor.parentElement ?? undefined,\n send: inst.send as (msg: unknown) => void,\n instance: inst as ComponentInstance,\n })\n const nodes = hydrateDef.view(createView<S, M>(inst.send))\n clearRenderContext()\n setFlatBindings(null)\n popMountQueue(prevMountQueue)\n\n if (nodes.length > 1) {\n const frag = inst.dom.createDocumentFragment()\n for (const node of nodes) frag.appendChild(node)\n anchor.parentNode.insertBefore(frag, endSentinel)\n } else if (nodes.length === 1) {\n anchor.parentNode.insertBefore(nodes[0]!, endSentinel)\n }\n\n flushMountQueue(onMountQueue)\n\n registerInstance(inst)\n if (hmrModule && def.name) {\n hmrModule.registerForAnchor(def.name, inst, anchor, endSentinel)\n }\n // Hydration: skip init's effects by default. The SSR pass already ran\n // them on the server; re-running on the client typically produces\n // duplicate work (double fetches, double subscriptions). Opt back in\n // via `MountOptions.runInitEffectsOnHydrate: true`.\n if (options?.runInitEffectsOnHydrate) {\n dispatchInitialEffects(inst)\n } else {\n warnDroppedInitEffects(inst, 'hydrateAtAnchor')\n }\n return buildAppHandle(inst, def.name ?? null, () => {\n _removeBetween(anchor, endSentinel)\n endSentinel.parentNode?.removeChild(endSentinel)\n })\n}\n\nfunction dispatchInitialEffects<S, M, E>(\n inst: ReturnType<typeof createComponentInstance<S, M, E>>,\n): void {\n if (inst.initialEffects.length === 0 || !inst.def.onEffect) return\n for (const effect of inst.initialEffects) {\n inst.def.onEffect({ effect, send: inst.send, signal: inst.signal })\n }\n inst.initialEffects = []\n}\n\n/**\n * Dev-only warning when a hydrate path silently drops a non-empty\n * `initialEffects` array. The default-skip behavior is deliberate (the\n * server already ran them), but if `init()` produces effects that\n * weren't run on the server — typically client-only init pipelines —\n * silent drop is a footgun. Surface the count and the opt-in.\n */\nfunction warnDroppedInitEffects<S, M, E>(\n inst: ReturnType<typeof createComponentInstance<S, M, E>>,\n via: 'hydrateApp' | 'hydrateAtAnchor',\n): void {\n if (!import.meta.env?.DEV) return\n if (inst.initialEffects.length === 0) return\n const name = inst.def.name ?? '<anonymous>'\n console.warn(\n `[LLui] ${via}: skipped ${inst.initialEffects.length} init effect(s) for \"${name}\". ` +\n `Hydration drops init effects by default since the server already ran them. ` +\n `If these effects only fire on the client, pass \\`runInitEffectsOnHydrate: true\\` to opt in.`,\n )\n}\n\n/**\n * Build the `AppHandle` returned by every mount/hydrate path. Captures\n * the `_onCommit` listener registry, the `disposed` flag, and the\n * standard `flush` / `send` / `getState` / `subscribe` shape — all\n * code that was previously duplicated four times across `mountApp`,\n * `mountAtAnchor`, `hydrateApp`, and `hydrateAtAnchor`.\n *\n * Variation lives in the two parameters:\n * - `hmrName` — the def's name used to call `hmrModule.unregisterForHmr`\n * on dispose. Pass `null` to skip HMR unregistration (no current\n * mount path needs that, but it keeps the helper honest).\n * - `domCleanup` — final teardown step that detaches mounted nodes.\n * Container-rooted paths set `container.textContent = ''`;\n * anchor-rooted paths call `_removeBetween(anchor, endSentinel)`\n * and detach the end sentinel. Runs LAST in the dispose chain to\n * match the historical ordering exactly (lifetime is disposed\n * before nodes are detached, so binding teardown sees attached\n * DOM until the very end).\n *\n * The mount-path-parity test in `mount-path-parity.test.ts` enforces\n * that each public entry point produces structurally identical\n * AppHandle behavior — this helper is the realisation of that\n * promise.\n */\nfunction buildAppHandle<S, M, E>(\n inst: ReturnType<typeof createComponentInstance<S, M, E>>,\n hmrName: string | null,\n domCleanup: () => void,\n): AppHandle {\n let disposed = false\n const listeners = new Set<(s: unknown) => void>()\n\n inst._onCommit = (state: unknown) => {\n for (const l of Array.from(listeners)) {\n try {\n l(state)\n } catch (err) {\n console.error('[llui] listener threw:', err)\n }\n }\n }\n\n return {\n dispose() {\n if (disposed) return\n disposed = true\n listeners.clear()\n inst._onCommit = undefined\n if (hmrModule && hmrName) hmrModule.unregisterForHmr(hmrName, inst)\n inst.abortController.abort()\n unregisterInstance(inst)\n // Tag the root scope so the disposer log reports app-level\n // teardown distinct from in-tree component-unmount events.\n inst.rootLifetime.disposalCause = 'app-unmount'\n disposeLifetime(inst.rootLifetime)\n domCleanup()\n },\n flush() {\n if (disposed) return\n flushInstance(inst)\n },\n send(msg: unknown) {\n if (disposed) return\n ;(inst.send as (m: unknown) => void)(msg)\n },\n getState() {\n if (disposed) {\n throw new Error(\n '[LLui] AppHandle.getState() called after dispose — handle is dead. ' +\n 'Detach your event listener / cancel your timer when the handle ' +\n 'is disposed to avoid stale reads.',\n )\n }\n return inst.state\n },\n subscribe(listener: (state: unknown) => void) {\n if (disposed) return () => {}\n listeners.add(listener)\n return () => listeners.delete(listener)\n },\n getBindingDescriptors() {\n if (disposed) return []\n return getBindingDescriptors(inst as ComponentInstance)\n },\n swapUpdate(newUpdate, newOnEffect) {\n if (disposed) return\n // Drain pending messages with the OLD update first — anything\n // already in the queue was constructed under the old contract,\n // and re-routing it through a new reducer mid-flight could mix\n // half of one transition with half of another (e.g. a payload\n // shape the new update no longer accepts).\n flushInstance(inst)\n // Mutate the def in place so subsequent `inst.def.update`\n // reads — including the per-message read in `flushInstance`'s\n // generic loop — pick up the new function. We deliberately\n // don't replace `inst.def` itself: existing closures, the\n // `__update` fast path, and `__handlers` all stay valid; only\n // the user-visible reducer function changes.\n ;(inst.def as { update: typeof newUpdate }).update = newUpdate\n if (newOnEffect !== undefined) {\n ;(inst.def as { onEffect?: typeof newOnEffect }).onEffect = newOnEffect\n }\n },\n runReducer(msg) {\n if (disposed) return null\n // Direct invocation against current state. No subscribe, no\n // flush, no effect handler. The reducer's contract per TEA is\n // a pure function — calling it twice with the same args is a\n // no-op other than allocations. Returning the raw tuple\n // shape lets the agent inspect both halves without interpreting.\n const [state, effects] = (\n inst.def.update as (s: unknown, m: unknown) => [unknown, unknown[]]\n )(inst.state, msg)\n return { state, effects: effects as unknown[] }\n },\n setOnBindingError(hook) {\n if (disposed) return\n inst._onBindingError = hook ?? undefined\n },\n }\n}\n\nexport function hydrateApp<S, M, E, D = void>(\n container: HTMLElement,\n def: ComponentDef<S, M, E, D>,\n serverState: S,\n options?: MountOptions,\n): AppHandle {\n // HMR fast path: a second hydrateApp into the same container\n // (typical of HMR module re-execution) hot-swaps in place. Without\n // this, the second call leaks the first instance — its lifetime is\n // never disposed, its HMR entry stays in the registry, its bindings\n // keep running on detached DOM. State preservation follows the same\n // semantics as mountApp's fast path: the live instance keeps its\n // current state and the new def's `serverState` argument is\n // intentionally ignored on the swap (HMR preserves user state).\n if (hmrModule && def.name && !options?.parentLifetime) {\n const swapped = hmrModule.replaceComponentForContainer(def.name, def, container)\n if (swapped) return swapped\n }\n\n // Run the original init once to capture its effects. The state it\n // returns is discarded — we use `serverState` (what the server\n // rendered with) instead. The effects are preserved and dispatched\n // after the DOM is in place, so components that rely on \"load data\n // or wire subscriptions on mount\" behave consistently between fresh\n // mount and SSR+hydrate. If the original init has already-loaded\n // data for the hydration case, gate the effect emission inside init\n // itself (e.g. based on a `loaded` flag in state).\n const [, originalEffects] = (def.init as (data: unknown) => [S, E[]])(undefined)\n\n const hydrateDef: ComponentDef<S, M, E> = {\n ...def,\n init: () => [serverState, originalEffects],\n }\n\n const inst = createComponentInstance(\n hydrateDef,\n undefined,\n options?.parentLifetime ?? null,\n options?.env,\n )\n\n // Dev-only: auto-install devtools if enabled via '@llui/dom/devtools'\n // import. The other three mount paths (mountApp / mountAtAnchor /\n // hydrateAtAnchor) all call this; without it, the hydrated layout\n // never appears in `window.__lluiComponents`, never sets\n // `window.__lluiDebug`, and is invisible to MCP / agent client /\n // devtools console — so a vike SSR app's outermost layout silently\n // drops out of every observability surface.\n if (devToolsInstall) devToolsInstall(inst)\n\n // Build the component DOM and swap atomically with server HTML.\n // Server HTML remains visible until JS finishes — no flash.\n // onMount callbacks are collected in a queue and flushed synchronously\n // after the swap, matching mountApp's ordering.\n const { queue: onMountQueue, prev: prevMountQueue } = pushMountQueue()\n setFlatBindings(inst.allBindings)\n setRenderContext({\n ...inst,\n container,\n send: inst.send as (msg: unknown) => void,\n instance: inst as ComponentInstance,\n })\n const nodes = hydrateDef.view(createView<S, M>(inst.send))\n clearRenderContext()\n setFlatBindings(null)\n popMountQueue(prevMountQueue)\n\n // Atomic swap — replaces server HTML with client DOM in one operation\n container.replaceChildren(...nodes)\n\n // Flush onMount callbacks synchronously now that the DOM is in place.\n flushMountQueue(onMountQueue)\n\n // Hydration: skip init's effects by default. The SSR pass already ran\n // them on the server; re-running on the client typically produces\n // duplicate work (double fetches, double subscriptions). Opt back in\n // via `MountOptions.runInitEffectsOnHydrate: true` for projects that\n // need the post-swap dispatch (typically when `init()` is gated by\n // a `loaded` flag and returns `[]` on the server).\n if (options?.runInitEffectsOnHydrate) {\n dispatchInitialEffects(inst)\n } else {\n warnDroppedInitEffects(inst, 'hydrateApp')\n }\n\n registerInstance(inst)\n // HMR registration — same as mountApp / mountAtAnchor /\n // hydrateAtAnchor. Without it, replaceComponent(name, newDef)\n // silently no-ops on the hydrated layout layer because the HMR\n // registry has no entry for it.\n if (hmrModule && hydrateDef.name) {\n hmrModule.registerForHmr(hydrateDef.name, inst, container)\n }\n return buildAppHandle(inst, hydrateDef.name ?? null, () => {\n container.textContent = ''\n })\n}\n"]}
|
package/dist/primitives/each.js
CHANGED
|
@@ -39,9 +39,9 @@ function callKey(opts, item) {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
// Reusable render context for buildEntry — avoids object allocation per entry.
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
//
|
|
42
|
+
// Every field is overwritten from the surrounding context per reconcile call
|
|
43
|
+
// (see buildEntry), so the initial shape's null/empty values are never observed
|
|
44
|
+
// in practice.
|
|
45
45
|
const buildCtx = {
|
|
46
46
|
rootLifetime: null,
|
|
47
47
|
state: null,
|
|
@@ -424,13 +424,22 @@ function buildEntry(item, index, opts, parentLifetime, ctx, state) {
|
|
|
424
424
|
return itemProxy;
|
|
425
425
|
};
|
|
426
426
|
const indexAccessor = () => entry.index;
|
|
427
|
-
// Reuse a single context object to avoid allocation per entry
|
|
427
|
+
// Reuse a single context object to avoid allocation per entry. Every
|
|
428
|
+
// non-rootLifetime/non-state field is copied from the surrounding
|
|
429
|
+
// context — including `send` and `container`, which were dropped by
|
|
430
|
+
// earlier versions. Missing `send` silently broke `child({ onMsg })`
|
|
431
|
+
// bubble-up from inside an each() row (child.ts reads `parentCtx.send`,
|
|
432
|
+
// got `undefined`, and skipped the bubble). Missing `container` made
|
|
433
|
+
// `onMount(cb)` fall back to `document.body` instead of the parent
|
|
434
|
+
// component's container.
|
|
428
435
|
buildCtx.rootLifetime = scope;
|
|
429
436
|
buildCtx.state = currentState;
|
|
430
437
|
buildCtx.allBindings = ctx.allBindings;
|
|
431
438
|
buildCtx.structuralBlocks = ctx.structuralBlocks;
|
|
432
439
|
buildCtx.dom = ctx.dom;
|
|
433
440
|
buildCtx.instance = ctx.instance;
|
|
441
|
+
buildCtx.send = ctx.send;
|
|
442
|
+
buildCtx.container = ctx.container;
|
|
434
443
|
const prevFlatBindings = getFlatBindings();
|
|
435
444
|
setFlatBindings(ctx.allBindings);
|
|
436
445
|
setRenderContext(buildCtx);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"each.js","sourceRoot":"","sources":["../../src/primitives/each.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,YAAY,GAEb,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,WAAW,EACX,sBAAsB,GACvB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAE7C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAE/C,6FAA6F;AAC7F,kFAAkF;AAClF,IAAI,oBAAoB,GAA6B,IAAI,CAAA;AACzD,IAAI,qBAAqB,GAAiD,IAAI,CAAA;AAE9E,uEAAuE;AACvE,MAAM,UAAU,eAAe,CAAC,EAAc;IAC5C,IAAI,oBAAoB;QAAE,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACzD,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,gBAAgB,CAAC,EAAkC;IACjE,IAAI,qBAAqB;QAAE,qBAAqB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AAC3D,CAAC;AAED,6EAA6E;AAC7E,4EAA4E;AAC5E,yEAAyE;AACzE,SAAS,SAAS,CAAO,IAA8B,EAAE,KAAQ;IAC/D,aAAa,CAAC,cAAc,CAAC,CAAA;IAC7B,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAC1B,CAAC;YAAS,CAAC;QACT,YAAY,EAAE,CAAA;IAChB,CAAC;AACH,CAAC;AACD,SAAS,OAAO,CAAI,IAAwC,EAAE,IAAO;IACnE,aAAa,CAAC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,CAAC,UAAU,CAAC,CAAC,CAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;QACxC,CAAC;IACH,CAAC;IACD,0EAA0E;IAC1E,IAAI,WAAW,GAAG,CAAC,CAAC,CAAA;IACpB,KAAK,MAAM,KAAK,IAAI,UAAU,EAAE,CAAC;QAC/B,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACzC,IAAI,MAAM,KAAK,SAAS;YAAE,SAAQ,CAAC,kBAAkB;QACrD,IAAI,MAAM,GAAG,WAAW;YAAE,OAAO,KAAK,CAAA;QACtC,WAAW,GAAG,MAAM,CAAA;IACtB,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import type { EachOptions, ItemAccessor, Lifetime } from '../types.js'\nimport {\n getRenderContext,\n setRenderContext,\n clearRenderContext,\n enterAccessor,\n exitAccessor,\n type RenderContext,\n} from '../render-context.js'\nimport {\n createLifetime,\n disposeLifetime,\n disposeLifetimesBulk,\n addDisposer,\n removeOrphanedChildren,\n} from '../lifetime.js'\nimport { getFlatBindings, setFlatBindings } from '../binding.js'\nimport { FULL_MASK } from '../update-loop.js'\nimport type { StructuralBlock } from '../structural.js'\nimport { createView } from '../view-helpers.js'\n\n// Clear callbacks — registered by selector.bind() during render, called by reconcileClear().\n// Eliminates per-row disposers (1000 Set.delete calls → 1 registry.clear() call).\nlet activeClearCallbacks: Array<() => void> | null = null\nlet activeRemoveCallbacks: Array<(key: string | number) => void> | null = null\n\n/** Register a callback to run when the current each() block clears. */\nexport function registerOnClear(cb: () => void): void {\n if (activeClearCallbacks) activeClearCallbacks.push(cb)\n}\n\n/** Register a callback to run when a single row is removed by key. */\nexport function registerOnRemove(cb: (key: string | number) => void): void {\n if (activeRemoveCallbacks) activeRemoveCallbacks.push(cb)\n}\n\n// Wrap accessor invocations so `sample()` calls inside them throw a targeted\n// error. The wrappers also localise the contract: every items/key call goes\n// through these, so a future change (e.g. instrumentation) has one site.\nfunction callItems<S, T>(opts: { items: (s: S) => T[] }, state: S): T[] {\n enterAccessor('each().items')\n try {\n return opts.items(state)\n } finally {\n exitAccessor()\n }\n}\nfunction callKey<T>(opts: { key: (t: T) => string | number }, item: T): string | number {\n enterAccessor('each().key')\n try {\n return opts.key(item)\n } finally {\n exitAccessor()\n }\n}\n\n// Reusable render context for buildEntry — avoids object allocation per entry.\n// All fields except `rootLifetime`, `state`, `allBindings`, `structuralBlocks`, `dom`\n// are copied from the surrounding render context per reconcile call, so the\n// initial shape's null/empty values are never observed in practice.\nconst buildCtx: RenderContext = {\n rootLifetime: null as unknown as Lifetime,\n state: null,\n allBindings: [],\n structuralBlocks: [],\n dom: null as unknown as import('../dom-env.js').DomEnv,\n}\n\n// Reusable render bag — mutated per entry instead of allocating new objects\nconst buildBag: Record<string, unknown> = {\n send: null,\n get item() {\n return (buildBag._getItemProxy as () => unknown)()\n },\n acc: null,\n index: null,\n _getItemProxy: null,\n}\n\ninterface Entry<T> {\n key: string | number\n item: T\n current: T\n index: number\n scope: Lifetime\n nodes: Node[]\n /** Per-item updaters — stored on entry directly to avoid scope overhead for leaf rows */\n updaters: Array<() => void>\n}\n\nexport function each<S, T, M = unknown>(opts: EachOptions<S, T, M>): Node[] {\n const ctx = getRenderContext('each')\n const parentLifetime = ctx.rootLifetime\n const blocks = ctx.structuralBlocks\n\n const anchor = ctx.dom.createComment('each')\n // End-of-territory sentinel. Bulk Range ops (reconcileClear, Fast path\n // 1, Fast path 5) used to setEndAfter the last entry's last node, but\n // when a nested structural primitive replaced its own entries between\n // the outer render snapshot and the next outer reconcile, that captured\n // node could be detached — Range#setEndAfter throws InvalidNodeTypeError\n // on a parent-less node. Anchoring the range with two stable comments\n // (owned by this each) makes the bulk-remove correct regardless of any\n // inner-each / show / branch mutation that happened in between.\n const endAnchor = ctx.dom.createComment('each-end')\n const entries: Entry<T>[] = []\n const clearCallbacks: Array<() => void> = []\n const removeCallbacks: Array<(key: string | number) => void> = []\n // Entries whose leave animation is still in progress. Their DOM nodes\n // remain in the parent until the leave Promise resolves.\n const leaving: Entry<T>[] = []\n\n const initialItems = callItems(opts, ctx.state as S)\n let lastItemsRef = initialItems\n\n // Dev-only diff tracking: if the owning component has an _eachDiffLog\n // (installed by devtools), we capture key sets before/after each\n // key-mutating reconcile call and emit an EachDiff entry. The siteId\n // is derived from this each() block's position in the flat block\n // array at registration time — stable for the lifetime of the block.\n const inst = ctx.instance\n const eachSiteId = inst?._eachDiffLog !== undefined ? `each#${blocks.length}` : ''\n const snapshotKeys = (): string[] | null => {\n if (inst?._eachDiffLog === undefined) return null\n const keys: string[] = []\n for (let i = 0; i < entries.length; i++) keys.push(String(entries[i]!.key))\n return keys\n }\n const emitDiff = (oldKeys: string[] | null): void => {\n if (oldKeys === null || inst?._eachDiffLog === undefined) return\n const newKeys: string[] = []\n for (let i = 0; i < entries.length; i++) newKeys.push(String(entries[i]!.key))\n const oldKeySet = new Set(oldKeys)\n const newKeySet = new Set(newKeys)\n const added: string[] = []\n const removed: string[] = []\n const moved: Array<{ key: string; from: number; to: number }> = []\n const reused: string[] = []\n for (const k of newKeys) if (!oldKeySet.has(k)) added.push(k)\n for (const k of oldKeys) if (!newKeySet.has(k)) removed.push(k)\n for (let i = 0; i < newKeys.length; i++) {\n const k = newKeys[i]!\n if (!oldKeySet.has(k)) continue\n const from = oldKeys.indexOf(k)\n if (from !== i) moved.push({ key: k, from, to: i })\n else reused.push(k)\n }\n inst._eachDiffLog.push({\n updateIndex: inst._updateCounter ?? 0,\n eachSiteId,\n added,\n removed,\n moved,\n reused,\n })\n }\n\n const block: StructuralBlock = {\n mask: (opts as { __mask?: number }).__mask ?? FULL_MASK,\n reconcile(state: unknown) {\n const parent = anchor.parentNode\n if (!parent) return\n\n const newItems = callItems(opts, state as S)\n\n // Fast path: same array reference → skip entirely.\n if (newItems === lastItemsRef) return\n lastItemsRef = newItems\n\n const oldKeys = snapshotKeys()\n const report = opts.onTransition ? { entering: [] as Node[], leaving: [] as Node[] } : null\n reconcileEntries(\n entries,\n newItems,\n opts,\n parentLifetime,\n parent,\n anchor,\n endAnchor,\n ctx,\n state,\n leaving,\n report,\n )\n if (opts.onTransition && report) {\n opts.onTransition({ entering: report.entering, leaving: report.leaving, parent })\n }\n emitDiff(oldKeys)\n },\n\n /** Same keys, only item data changed — skip mismatch/swap detection.\n * Compiler calls this when it knows the array structure is unchanged. */\n reconcileItems(state: unknown) {\n const newItems = callItems(opts, state as S)\n lastItemsRef = newItems\n const len = Math.min(entries.length, newItems.length)\n for (let i = 0; i < len; i++) {\n const entry = entries[i]!\n const newItem = newItems[i]!\n if (entry.item !== newItem) {\n updateEntry(entry, newItem, i)\n }\n }\n },\n\n /** Remove all items — skip items accessor, go straight to clear path. */\n reconcileClear() {\n lastItemsRef = [] as unknown as T[]\n const parent = anchor.parentNode\n if (!parent) return\n if (entries.length === 0) return\n\n const oldKeys = snapshotKeys()\n\n // Call registered clear callbacks (e.g., selector registry.clear())\n // BEFORE scope disposal — avoids 1000 individual Set.delete calls\n for (let i = 0; i < clearCallbacks.length; i++) clearCallbacks[i]!()\n\n // Bulk DOM removal — anchored on this each's own start/end sentinels\n // so a nested primitive that replaced its own captured nodes between\n // the outer snapshot and now can't make this throw.\n const range = ctx.dom.createRange()\n range.setStartAfter(anchor)\n range.setEndBefore(endAnchor)\n range.deleteContents()\n\n // Bulk scope disposal — disposers that were replaced by clearCallbacks\n // are now no-ops, making this much faster\n const scopes: Lifetime[] = []\n for (let i = 0; i < entries.length; i++) {\n const s = entries[i]!.scope\n s.disposalCause = 'each-remove'\n scopes.push(s)\n }\n disposeLifetimesBulk(scopes)\n removeOrphanedChildren(parentLifetime)\n entries.length = 0\n\n emitDiff(oldKeys)\n },\n\n /** Remove entries not present in the new items. Optimized for filter()\n * patterns where items are removed but order is preserved. Walks old\n * and new arrays in parallel — O(n) with no Map/Set allocation. */\n reconcileRemove(state: unknown) {\n const newItems = callItems(opts, state as S)\n lastItemsRef = newItems\n const parent = anchor.parentNode\n if (!parent) return\n\n const oldKeys = snapshotKeys()\n const oldLen = entries.length\n const newLen = newItems.length\n if (newLen >= oldLen) {\n // Not a removal — fallback (shouldn't happen if compiler detected correctly)\n reconcileEntries(\n entries,\n newItems,\n opts,\n parentLifetime,\n parent,\n anchor,\n endAnchor,\n ctx,\n state,\n leaving,\n null,\n )\n emitDiff(oldKeys)\n return\n }\n\n // Parallel walk: new items are a subsequence of old items (same order, some removed)\n let ni = 0\n let didRemove = false\n for (let oi = 0; oi < oldLen; oi++) {\n const entry = entries[oi]!\n if (ni < newLen && entry.key === callKey(opts, newItems[ni]!)) {\n // Entry survives — update if item ref changed\n if (entry.item !== newItems[ni]) {\n updateEntry(entry, newItems[ni]!, ni)\n }\n ni++\n } else {\n // Entry removed — notify selectors before scope disposal\n for (let ci = 0; ci < removeCallbacks.length; ci++) removeCallbacks[ci]!(entry.key)\n for (const node of entry.nodes) parent.removeChild(node)\n entry.scope.disposalCause = 'each-remove'\n disposeLifetime(entry.scope, true)\n entries[oi] = null!\n didRemove = true\n }\n }\n\n // Compact entries array\n if (didRemove) {\n let w = 0\n for (let r = 0; r < oldLen; r++) {\n if (entries[r]) entries[w++] = entries[r]!\n }\n entries.length = w\n removeOrphanedChildren(parentLifetime)\n }\n\n // Update indices for remaining entries\n for (let i = 0; i < entries.length; i++) {\n entries[i]!.index = i\n }\n\n emitDiff(oldKeys)\n },\n\n /** Update only entries at stride intervals — O(k) where k = n/stride.\n * The compiler passes the stride from the detected for-loop pattern. */\n reconcileChanged(state: unknown, stride: number) {\n const newItems = callItems(opts, state as S)\n lastItemsRef = newItems\n for (let i = 0; i < entries.length && i < newItems.length; i += stride) {\n const entry = entries[i]!\n const newItem = newItems[i]!\n if (entry.item !== newItem) {\n updateEntry(entry, newItem, i)\n }\n }\n },\n }\n\n // Register the block BEFORE building initial row entries so that this\n // each() block precedes any nested structural blocks its rows register.\n // Parents must come first in the flat blocks array — see branch.ts for\n // the full rationale (Phase 1 iteration safety when disposing nested).\n blocks.push(block)\n\n activeClearCallbacks = clearCallbacks\n activeRemoveCallbacks = removeCallbacks\n for (let i = 0; i < initialItems.length; i++) {\n const item = initialItems[i]!\n const entry = buildEntry(item, i, opts, parentLifetime, ctx)\n entries.push(entry)\n }\n activeClearCallbacks = null\n activeRemoveCallbacks = null\n\n // Fire initial enter for mount-time items\n if (opts.enter) {\n for (const entry of entries) {\n if (entry.nodes.length > 0) opts.enter(entry.nodes)\n }\n }\n\n addDisposer(parentLifetime, () => {\n const idx = blocks.indexOf(block)\n if (idx !== -1) blocks.splice(idx, 1)\n // parentLifetime is being disposed — its children array is about to be\n // cleared by the recursive dispose pass, so skip per-entry parent\n // removal (avoids O(N²) indexOf+splice).\n //\n // Rows created AFTER the parent's initial render (each reconciled\n // with a new item list) are siblings of the anchor inside the\n // parent's DOM container, but aren't tracked by the parent's\n // snapshot (e.g. an outer branch's currentNodes). Walking entries\n // here and removing their DOM — guarded by parentNode — closes\n // the leak: cascade-removed subtrees no-op, live-parent cases get\n // the orphans cleaned up.\n for (const entry of entries) {\n for (const node of entry.nodes) {\n if (node.parentNode) node.parentNode.removeChild(node)\n }\n disposeLifetime(entry.scope, true)\n }\n entries.length = 0\n if (anchor.parentNode) anchor.parentNode.removeChild(anchor)\n if (endAnchor.parentNode) endAnchor.parentNode.removeChild(endAnchor)\n // Force-remove any mid-leave entries immediately\n for (const entry of leaving) {\n for (const node of entry.nodes) {\n if (node.parentNode) node.parentNode.removeChild(node)\n }\n disposeLifetime(entry.scope, true)\n }\n leaving.length = 0\n })\n\n const result: Node[] = [anchor]\n for (const entry of entries) {\n const nodes = entry.nodes\n for (let i = 0; i < nodes.length; i++) result.push(nodes[i]!)\n }\n result.push(endAnchor)\n return result\n}\n\n/**\n * Remove an entry's DOM + dispose its scope, running opts.leave first if\n * provided. When leave returns a Promise, the DOM removal is deferred until\n * resolution (entry is tracked in `leaving`).\n */\nfunction removeEntry<T>(\n entry: Entry<T>,\n opts: { leave?: (nodes: Node[]) => void | Promise<void> },\n leaving: Entry<T>[],\n): void {\n const removeNow = (): void => {\n for (const node of entry.nodes) {\n if (node.parentNode) node.parentNode.removeChild(node)\n }\n entry.scope.disposalCause = 'each-remove'\n disposeLifetime(entry.scope)\n const idx = leaving.indexOf(entry)\n if (idx !== -1) leaving.splice(idx, 1)\n }\n if (opts.leave && entry.nodes.length > 0) {\n const result = opts.leave(entry.nodes)\n if (result && typeof (result as Promise<void>).then === 'function') {\n leaving.push(entry)\n ;(result as Promise<void>).then(removeNow)\n return\n }\n }\n removeNow()\n}\n\nfunction fireEnter<T>(\n entry: Entry<T>,\n opts: { enter?: (nodes: Node[]) => void | Promise<void> },\n): void {\n if (opts.enter && entry.nodes.length > 0) {\n void opts.enter(entry.nodes)\n }\n}\n\nfunction buildEntry<S, T, M>(\n item: T,\n index: number,\n opts: EachOptions<S, T, M>,\n parentLifetime: Lifetime,\n ctx: ReturnType<typeof getRenderContext>,\n state?: unknown,\n): Entry<T> {\n const key = callKey(opts, item)\n // Use a lightweight scope — just needs itemUpdaters for per-item bindings.\n // Full scope features (disposers, bindings, children) are only needed when\n // the render callback uses structural primitives or selector.bind().\n const scope = createLifetime(parentLifetime)\n scope._kind = 'each'\n const currentState = (state ?? ctx.state) as S\n const send = ctx.send as (msg: M) => void\n\n // Create entry before render so itemAccessor closures can capture it\n const entry: Entry<T> = { key, item, current: item, index, scope, nodes: null!, updaters: [] }\n\n // Base callable: item(selector) for computed expressions\n const itemFn = <R>(selector: (t: T) => R): (() => R) => {\n const accessor = () => selector(entry.current)\n accessor.__perItem = true as const\n return accessor\n }\n\n // Proxy for item.field shorthand: LAZILY created. Compiled code uses\n // `acc(fn)` instead (the compiler rewrites item.x → acc(r => r.x)),\n // so the Proxy is never constructed in the common case. This saves\n // ~300ns × N Proxy allocations per create cycle.\n let itemProxy: ItemAccessor<T> | null = null\n const getItemProxy = (): ItemAccessor<T> => {\n if (itemProxy) return itemProxy\n let fieldCache: Map<string, () => unknown> | null = null\n itemProxy = new Proxy(itemFn as object, {\n get(target, prop) {\n if (typeof prop === 'symbol' || prop === 'then' || prop === 'prototype') {\n return Reflect.get(target, prop)\n }\n const key = prop as string\n if (fieldCache) {\n const cached = fieldCache.get(key)\n if (cached) return cached\n } else {\n fieldCache = new Map()\n }\n // `current` returns the whole item — essential for primitive T\n // (where the field map is useless) and for whole-record sampling.\n // Caller must call it like a method: `item.current()`.\n const accessor =\n key === 'current'\n ? () => entry.current\n : () => (entry.current as Record<string, unknown>)[key]\n ;(accessor as unknown as { __perItem: true }).__perItem = true\n fieldCache.set(key, accessor)\n return accessor\n },\n }) as ItemAccessor<T>\n return itemProxy\n }\n\n const indexAccessor = (): number => entry.index\n\n // Reuse a single context object to avoid allocation per entry\n buildCtx.rootLifetime = scope\n buildCtx.state = currentState\n buildCtx.allBindings = ctx.allBindings\n buildCtx.structuralBlocks = ctx.structuralBlocks\n buildCtx.dom = ctx.dom\n buildCtx.instance = ctx.instance\n const prevFlatBindings = getFlatBindings()\n setFlatBindings(ctx.allBindings)\n setRenderContext(buildCtx)\n\n // Reuse a single render bag object across entries — mutate `acc` and\n // `index` per entry to avoid per-entry object allocation.\n buildBag.send = send\n buildBag.acc = itemFn\n buildBag.index = indexAccessor\n buildBag._getItemProxy = getItemProxy\n buildBag.entry = entry\n // The View bag — lets each.render use `h.text`, `h.scope`, `h.sample`,\n // etc. without reaching for the top-level imports. Each entry gets a\n // fresh View so its `send` is bound to this row's dispatch path.\n buildBag.h = createView<S, M>(send)\n // Row factory: pass compiler-injected template + update function through to render\n const rfOpts = opts as unknown as Record<string, unknown>\n if (rfOpts.__tpl) buildBag.__tpl = rfOpts.__tpl\n if (rfOpts.__rowUpd) buildBag.__rowUpd = rfOpts.__rowUpd\n entry.nodes = opts.render(buildBag as Parameters<typeof opts.render>[0])\n\n // Move itemUpdaters from scope to entry for direct access during updateEntry.\n // This avoids scope.itemUpdaters lookup overhead on every item update.\n if (scope.itemUpdaters.length > 0) {\n entry.updaters = scope.itemUpdaters\n scope.itemUpdaters = []\n }\n\n clearRenderContext()\n setFlatBindings(prevFlatBindings)\n setRenderContext(ctx)\n\n return entry\n}\n\ninterface TransitionReport {\n entering: Node[]\n leaving: Node[]\n}\n\nfunction collectNodes(target: Node[], nodes: Node[]): void {\n for (const n of nodes) target.push(n)\n}\n\nfunction reconcileEntries<S, T>(\n entries: Entry<T>[],\n newItems: T[],\n opts: EachOptions<S, T>,\n parentLifetime: Lifetime,\n parent: Node,\n anchor: Node,\n endAnchor: Node,\n ctx: ReturnType<typeof getRenderContext>,\n state: unknown,\n leaving: Entry<T>[],\n report: TransitionReport | null,\n): void {\n const oldLen = entries.length\n const newLen = newItems.length\n const hasLeave = !!opts.leave\n\n // Fast path 1: clear all — bulk DOM removal.\n // When opts.leave is set, each item needs its own leave animation, so\n // fall through to per-item removal instead of Range.deleteContents().\n if (newLen === 0) {\n if (report) {\n for (const entry of entries) collectNodes(report.leaving, entry.nodes)\n }\n if (hasLeave) {\n const toRemove = entries.slice()\n entries.length = 0\n for (const entry of toRemove) removeEntry(entry, opts, leaving)\n return\n }\n // Remove all DOM nodes in one operation using Range. Anchored on\n // start + end sentinels — see endAnchor comment in each() for why.\n if (entries.length > 0) {\n const range = ctx.dom.createRange()\n range.setStartAfter(anchor)\n range.setEndBefore(endAnchor)\n range.deleteContents()\n }\n // Bulk dispose all entry scopes — avoids per-scope function call overhead\n const scopes: Lifetime[] = []\n for (let i = 0; i < entries.length; i++) {\n const s = entries[i]!.scope\n s.disposalCause = 'each-remove'\n scopes.push(s)\n }\n disposeLifetimesBulk(scopes)\n removeOrphanedChildren(parentLifetime)\n entries.length = 0\n return\n }\n\n // Fast path 2: append-only — old keys are a prefix of new keys\n if (newLen > oldLen && isAppendOnly(entries, newItems, opts)) {\n for (let i = 0; i < oldLen; i++) {\n updateEntry(entries[i]!, newItems[i]!, i)\n }\n // Find insertion point: after last existing entry's last node, or after anchor\n const lastEntry = oldLen > 0 ? entries[oldLen - 1]! : null\n const ref = lastEntry\n ? lastEntry.nodes[lastEntry.nodes.length - 1]!.nextSibling\n : anchor.nextSibling\n const frag = ctx.dom.createDocumentFragment()\n const newlyAdded: Entry<T>[] = []\n for (let i = oldLen; i < newLen; i++) {\n const entry = buildEntry(newItems[i]!, i, opts, parentLifetime, ctx, state)\n entries.push(entry)\n newlyAdded.push(entry)\n for (const node of entry.nodes) frag.appendChild(node)\n }\n parent.insertBefore(frag, ref)\n if (report) {\n for (const entry of newlyAdded) collectNodes(report.entering, entry.nodes)\n }\n for (const entry of newlyAdded) fireEnter(entry, opts)\n return\n }\n\n // Fast path 3: same length — single pass handles both same-keys update\n // and two-element swap detection. Avoids a second O(n) pass.\n if (newLen === oldLen) {\n let mismatch1 = -1\n let mismatch2 = -1\n let mismatchCount = 0\n\n for (let i = 0; i < newLen; i++) {\n const entry = entries[i]!\n const newItem = newItems[i]!\n if (entry.item === newItem) continue\n const newKey = callKey(opts, newItem)\n if (entry.key === newKey) {\n updateEntry(entry, newItem, i)\n continue\n }\n // Key mismatch — track for swap detection\n mismatchCount++\n if (mismatchCount === 1) mismatch1 = i\n else if (mismatchCount === 2) mismatch2 = i\n else break // 3+ mismatches → fall through to general path\n }\n\n // All keys matched (with possible item updates) → done\n if (mismatchCount === 0) return\n\n // Exactly 2 key mismatches — check if it's a swap\n if (mismatchCount === 2) {\n const e1 = entries[mismatch1]!\n const e2 = entries[mismatch2]!\n if (\n e1.key === callKey(opts, newItems[mismatch2]!) &&\n e2.key === callKey(opts, newItems[mismatch1]!)\n ) {\n // DOM swap\n const refI = e1.nodes[0]!\n const refAfterJ = e2.nodes[e2.nodes.length - 1]!.nextSibling\n for (const node of e2.nodes) parent.insertBefore(node, refI)\n for (const node of e1.nodes) parent.insertBefore(node, refAfterJ)\n entries[mismatch1] = e2\n entries[mismatch2] = e1\n updateEntry(e2, newItems[mismatch1]!, mismatch1)\n updateEntry(e1, newItems[mismatch2]!, mismatch2)\n return\n }\n }\n // Fall through to general path for 3+ mismatches or non-swap\n }\n\n // Fast path 5: full replace — no shared keys between old and new.\n // Skipped when opts.leave is set so departing items can animate individually.\n if (!hasLeave && oldLen > 0 && callKey(opts, newItems[0]!) !== entries[0]!.key) {\n const oldKeys = new Set<string | number>()\n for (const entry of entries) oldKeys.add(entry.key)\n let anyShared = false\n for (let i = 0; i < newLen; i++) {\n if (oldKeys.has(callKey(opts, newItems[i]!))) {\n anyShared = true\n break\n }\n }\n if (!anyShared) {\n if (report) {\n for (const entry of entries) collectNodes(report.leaving, entry.nodes)\n }\n // Bulk DOM removal using Range — anchored on this each's stable\n // sentinels so a stale lastEntry node from a nested-primitive\n // mutation can't trip setEndAfter.\n const range = ctx.dom.createRange()\n range.setStartAfter(anchor)\n range.setEndBefore(endAnchor)\n range.deleteContents()\n // Bulk dispose all old scopes\n const oldLifetimes: Lifetime[] = []\n for (let i = 0; i < entries.length; i++) {\n const s = entries[i]!.scope\n s.disposalCause = 'each-remove'\n oldLifetimes.push(s)\n }\n disposeLifetimesBulk(oldLifetimes)\n removeOrphanedChildren(parentLifetime)\n entries.length = 0\n // Build all new entries into a fragment\n const frag = ctx.dom.createDocumentFragment()\n const newlyAdded: Entry<T>[] = []\n for (let i = 0; i < newLen; i++) {\n const entry = buildEntry(newItems[i]!, i, opts, parentLifetime, ctx, state)\n entries.push(entry)\n newlyAdded.push(entry)\n for (const node of entry.nodes) frag.appendChild(node)\n }\n parent.insertBefore(frag, anchor.nextSibling)\n if (report) {\n for (const entry of newlyAdded) collectNodes(report.entering, entry.nodes)\n }\n for (const entry of newlyAdded) fireEnter(entry, opts)\n return\n }\n }\n\n // General path: keyed reconciliation\n const oldByKey = new Map<string | number, Entry<T>>()\n for (const entry of entries) {\n oldByKey.set(entry.key, entry)\n }\n\n const newEntries: Entry<T>[] = []\n const usedKeys = new Set<string | number>()\n const newlyAdded: Entry<T>[] = []\n\n for (let i = 0; i < newLen; i++) {\n const item = newItems[i]!\n const key = callKey(opts, item)\n usedKeys.add(key)\n\n const existing = oldByKey.get(key)\n if (existing) {\n updateEntry(existing, item, i)\n newEntries.push(existing)\n } else {\n const entry = buildEntry(item, i, opts, parentLifetime, ctx, state)\n newEntries.push(entry)\n newlyAdded.push(entry)\n }\n }\n\n // Remove entries not in the new list. Use bulk-detach pattern so\n // disposing K removals costs O(K+P) rather than O(K*P) where P is\n // parentLifetime.children.length (avoids K * indexOf+splice).\n let didBulkDetach = false\n for (const entry of entries) {\n if (!usedKeys.has(entry.key)) {\n if (report) collectNodes(report.leaving, entry.nodes)\n if (hasLeave) {\n removeEntry(entry, opts, leaving)\n } else {\n // Defensive guard: a nested primitive (inner each / show / branch)\n // may have replaced its own captured nodes between the outer\n // render snapshot and now. Those replaced nodes are still in\n // entry.nodes but no longer children of `parent`. Skip them —\n // the inner-primitive's addDisposer cascade (run by the scope\n // disposal below) cleans up the orphan replacement nodes that\n // ARE attached. Without this guard, removeChild throws\n // NotFoundError on the stale ones.\n for (const node of entry.nodes) {\n if (node.parentNode === parent) parent.removeChild(node)\n }\n entry.scope.disposalCause = 'each-remove'\n disposeLifetime(entry.scope, true)\n didBulkDetach = true\n }\n }\n }\n if (didBulkDetach) removeOrphanedChildren(parentLifetime)\n\n // Reorder DOM\n const hasSurvivors = newEntries.some((e) => oldByKey.has(e.key))\n\n if (!hasSurvivors || !survivorsInOrder(entries, newEntries, usedKeys)) {\n // Full fragment rebuild — one reflow\n const frag = ctx.dom.createDocumentFragment()\n for (const entry of newEntries) {\n for (const node of entry.nodes) frag.appendChild(node)\n }\n parent.insertBefore(frag, anchor.nextSibling)\n } else {\n // Survivors in order — batch-insert new entries between survivors\n let frag: DocumentFragment | null = null\n let insertRef: ChildNode | null = anchor.nextSibling\n for (const entry of newEntries) {\n if (oldByKey.has(entry.key)) {\n // Flush any pending fragment before this survivor\n if (frag) {\n parent.insertBefore(frag, insertRef)\n frag = null\n }\n // Skip past survivor's nodes\n const lastNode = entry.nodes[entry.nodes.length - 1]\n insertRef = lastNode ? lastNode.nextSibling : insertRef\n } else {\n // Batch new entries into a fragment\n if (!frag) frag = ctx.dom.createDocumentFragment()\n for (const node of entry.nodes) frag.appendChild(node)\n }\n }\n if (frag) parent.insertBefore(frag, insertRef)\n }\n\n entries.length = newEntries.length\n for (let i = 0; i < newEntries.length; i++) entries[i] = newEntries[i]!\n\n if (report) {\n for (const entry of newlyAdded) collectNodes(report.entering, entry.nodes)\n }\n\n // Fire enter for newly-added entries (after DOM insertion)\n if (opts.enter) {\n for (const entry of newlyAdded) fireEnter(entry, opts)\n }\n}\n\nfunction updateEntry<T>(entry: Entry<T>, item: T, index: number): void {\n const changed = !Object.is(entry.item, item)\n entry.item = item\n entry.current = item\n entry.index = index\n // eachItemStable removed — unused\n // Directly run per-item updaters when item changed — bypasses Phase 2\n if (changed) {\n // Row factory fast path: shared update function, zero closures\n const rowUpd = (entry as unknown as Record<string, unknown>).__rowUpdate as\n | ((e: Entry<T>) => void)\n | undefined\n if (rowUpd) {\n rowUpd(entry)\n } else {\n // Closure-based fallback\n const updaters = entry.updaters.length > 0 ? entry.updaters : entry.scope.itemUpdaters\n for (let i = 0; i < updaters.length; i++) {\n updaters[i]!()\n }\n }\n }\n}\n\nfunction isAppendOnly<S, T>(entries: Entry<T>[], newItems: T[], opts: EachOptions<S, T>): boolean {\n for (let i = 0; i < entries.length; i++) {\n if (entries[i]!.key !== callKey(opts, newItems[i]!)) return false\n }\n return true\n}\n\nfunction survivorsInOrder<T>(\n oldEntries: Entry<T>[],\n newEntries: Entry<T>[],\n usedKeys: Set<string | number>,\n): boolean {\n // Build old-index map for survivors\n const oldIndexMap = new Map<string | number, number>()\n for (let i = 0; i < oldEntries.length; i++) {\n if (usedKeys.has(oldEntries[i]!.key)) {\n oldIndexMap.set(oldEntries[i]!.key, i)\n }\n }\n // Check that survivors appear in increasing old-index order in newEntries\n let maxOldIndex = -1\n for (const entry of newEntries) {\n const oldIdx = oldIndexMap.get(entry.key)\n if (oldIdx === undefined) continue // new entry, skip\n if (oldIdx < maxOldIndex) return false\n maxOldIndex = oldIdx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EAAE,CAAC,EAAE,EAAE,CAAC;QAC3C,IAAI,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAE,CAAC,GAAG,CAAC,EAAE,CAAC;YACrC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;QACxC,CAAC;IACH,CAAC;IACD,0EAA0E;IAC1E,IAAI,WAAW,GAAG,CAAC,CAAC,CAAA;IACpB,KAAK,MAAM,KAAK,IAAI,UAAU,EAAE,CAAC;QAC/B,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACzC,IAAI,MAAM,KAAK,SAAS;YAAE,SAAQ,CAAC,kBAAkB;QACrD,IAAI,MAAM,GAAG,WAAW;YAAE,OAAO,KAAK,CAAA;QACtC,WAAW,GAAG,MAAM,CAAA;IACtB,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import type { EachOptions, ItemAccessor, Lifetime } from '../types.js'\nimport {\n getRenderContext,\n setRenderContext,\n clearRenderContext,\n enterAccessor,\n exitAccessor,\n type RenderContext,\n} from '../render-context.js'\nimport {\n createLifetime,\n disposeLifetime,\n disposeLifetimesBulk,\n addDisposer,\n removeOrphanedChildren,\n} from '../lifetime.js'\nimport { getFlatBindings, setFlatBindings } from '../binding.js'\nimport { FULL_MASK } from '../update-loop.js'\nimport type { StructuralBlock } from '../structural.js'\nimport { createView } from '../view-helpers.js'\n\n// Clear callbacks — registered by selector.bind() during render, called by reconcileClear().\n// Eliminates per-row disposers (1000 Set.delete calls → 1 registry.clear() call).\nlet activeClearCallbacks: Array<() => void> | null = null\nlet activeRemoveCallbacks: Array<(key: string | number) => void> | null = null\n\n/** Register a callback to run when the current each() block clears. */\nexport function registerOnClear(cb: () => void): void {\n if (activeClearCallbacks) activeClearCallbacks.push(cb)\n}\n\n/** Register a callback to run when a single row is removed by key. */\nexport function registerOnRemove(cb: (key: string | number) => void): void {\n if (activeRemoveCallbacks) activeRemoveCallbacks.push(cb)\n}\n\n// Wrap accessor invocations so `sample()` calls inside them throw a targeted\n// error. The wrappers also localise the contract: every items/key call goes\n// through these, so a future change (e.g. instrumentation) has one site.\nfunction callItems<S, T>(opts: { items: (s: S) => T[] }, state: S): T[] {\n enterAccessor('each().items')\n try {\n return opts.items(state)\n } finally {\n exitAccessor()\n }\n}\nfunction callKey<T>(opts: { key: (t: T) => string | number }, item: T): string | number {\n enterAccessor('each().key')\n try {\n return opts.key(item)\n } finally {\n exitAccessor()\n }\n}\n\n// Reusable render context for buildEntry — avoids object allocation per entry.\n// Every field is overwritten from the surrounding context per reconcile call\n// (see buildEntry), so the initial shape's null/empty values are never observed\n// in practice.\nconst buildCtx: RenderContext = {\n rootLifetime: null as unknown as Lifetime,\n state: null,\n allBindings: [],\n structuralBlocks: [],\n dom: null as unknown as import('../dom-env.js').DomEnv,\n}\n\n// Reusable render bag — mutated per entry instead of allocating new objects\nconst buildBag: Record<string, unknown> = {\n send: null,\n get item() {\n return (buildBag._getItemProxy as () => unknown)()\n },\n acc: null,\n index: null,\n _getItemProxy: null,\n}\n\ninterface Entry<T> {\n key: string | number\n item: T\n current: T\n index: number\n scope: Lifetime\n nodes: Node[]\n /** Per-item updaters — stored on entry directly to avoid scope overhead for leaf rows */\n updaters: Array<() => void>\n}\n\nexport function each<S, T, M = unknown>(opts: EachOptions<S, T, M>): Node[] {\n const ctx = getRenderContext('each')\n const parentLifetime = ctx.rootLifetime\n const blocks = ctx.structuralBlocks\n\n const anchor = ctx.dom.createComment('each')\n // End-of-territory sentinel. Bulk Range ops (reconcileClear, Fast path\n // 1, Fast path 5) used to setEndAfter the last entry's last node, but\n // when a nested structural primitive replaced its own entries between\n // the outer render snapshot and the next outer reconcile, that captured\n // node could be detached — Range#setEndAfter throws InvalidNodeTypeError\n // on a parent-less node. Anchoring the range with two stable comments\n // (owned by this each) makes the bulk-remove correct regardless of any\n // inner-each / show / branch mutation that happened in between.\n const endAnchor = ctx.dom.createComment('each-end')\n const entries: Entry<T>[] = []\n const clearCallbacks: Array<() => void> = []\n const removeCallbacks: Array<(key: string | number) => void> = []\n // Entries whose leave animation is still in progress. Their DOM nodes\n // remain in the parent until the leave Promise resolves.\n const leaving: Entry<T>[] = []\n\n const initialItems = callItems(opts, ctx.state as S)\n let lastItemsRef = initialItems\n\n // Dev-only diff tracking: if the owning component has an _eachDiffLog\n // (installed by devtools), we capture key sets before/after each\n // key-mutating reconcile call and emit an EachDiff entry. The siteId\n // is derived from this each() block's position in the flat block\n // array at registration time — stable for the lifetime of the block.\n const inst = ctx.instance\n const eachSiteId = inst?._eachDiffLog !== undefined ? `each#${blocks.length}` : ''\n const snapshotKeys = (): string[] | null => {\n if (inst?._eachDiffLog === undefined) return null\n const keys: string[] = []\n for (let i = 0; i < entries.length; i++) keys.push(String(entries[i]!.key))\n return keys\n }\n const emitDiff = (oldKeys: string[] | null): void => {\n if (oldKeys === null || inst?._eachDiffLog === undefined) return\n const newKeys: string[] = []\n for (let i = 0; i < entries.length; i++) newKeys.push(String(entries[i]!.key))\n const oldKeySet = new Set(oldKeys)\n const newKeySet = new Set(newKeys)\n const added: string[] = []\n const removed: string[] = []\n const moved: Array<{ key: string; from: number; to: number }> = []\n const reused: string[] = []\n for (const k of newKeys) if (!oldKeySet.has(k)) added.push(k)\n for (const k of oldKeys) if (!newKeySet.has(k)) removed.push(k)\n for (let i = 0; i < newKeys.length; i++) {\n const k = newKeys[i]!\n if (!oldKeySet.has(k)) continue\n const from = oldKeys.indexOf(k)\n if (from !== i) moved.push({ key: k, from, to: i })\n else reused.push(k)\n }\n inst._eachDiffLog.push({\n updateIndex: inst._updateCounter ?? 0,\n eachSiteId,\n added,\n removed,\n moved,\n reused,\n })\n }\n\n const block: StructuralBlock = {\n mask: (opts as { __mask?: number }).__mask ?? FULL_MASK,\n reconcile(state: unknown) {\n const parent = anchor.parentNode\n if (!parent) return\n\n const newItems = callItems(opts, state as S)\n\n // Fast path: same array reference → skip entirely.\n if (newItems === lastItemsRef) return\n lastItemsRef = newItems\n\n const oldKeys = snapshotKeys()\n const report = opts.onTransition ? { entering: [] as Node[], leaving: [] as Node[] } : null\n reconcileEntries(\n entries,\n newItems,\n opts,\n parentLifetime,\n parent,\n anchor,\n endAnchor,\n ctx,\n state,\n leaving,\n report,\n )\n if (opts.onTransition && report) {\n opts.onTransition({ entering: report.entering, leaving: report.leaving, parent })\n }\n emitDiff(oldKeys)\n },\n\n /** Same keys, only item data changed — skip mismatch/swap detection.\n * Compiler calls this when it knows the array structure is unchanged. */\n reconcileItems(state: unknown) {\n const newItems = callItems(opts, state as S)\n lastItemsRef = newItems\n const len = Math.min(entries.length, newItems.length)\n for (let i = 0; i < len; i++) {\n const entry = entries[i]!\n const newItem = newItems[i]!\n if (entry.item !== newItem) {\n updateEntry(entry, newItem, i)\n }\n }\n },\n\n /** Remove all items — skip items accessor, go straight to clear path. */\n reconcileClear() {\n lastItemsRef = [] as unknown as T[]\n const parent = anchor.parentNode\n if (!parent) return\n if (entries.length === 0) return\n\n const oldKeys = snapshotKeys()\n\n // Call registered clear callbacks (e.g., selector registry.clear())\n // BEFORE scope disposal — avoids 1000 individual Set.delete calls\n for (let i = 0; i < clearCallbacks.length; i++) clearCallbacks[i]!()\n\n // Bulk DOM removal — anchored on this each's own start/end sentinels\n // so a nested primitive that replaced its own captured nodes between\n // the outer snapshot and now can't make this throw.\n const range = ctx.dom.createRange()\n range.setStartAfter(anchor)\n range.setEndBefore(endAnchor)\n range.deleteContents()\n\n // Bulk scope disposal — disposers that were replaced by clearCallbacks\n // are now no-ops, making this much faster\n const scopes: Lifetime[] = []\n for (let i = 0; i < entries.length; i++) {\n const s = entries[i]!.scope\n s.disposalCause = 'each-remove'\n scopes.push(s)\n }\n disposeLifetimesBulk(scopes)\n removeOrphanedChildren(parentLifetime)\n entries.length = 0\n\n emitDiff(oldKeys)\n },\n\n /** Remove entries not present in the new items. Optimized for filter()\n * patterns where items are removed but order is preserved. Walks old\n * and new arrays in parallel — O(n) with no Map/Set allocation. */\n reconcileRemove(state: unknown) {\n const newItems = callItems(opts, state as S)\n lastItemsRef = newItems\n const parent = anchor.parentNode\n if (!parent) return\n\n const oldKeys = snapshotKeys()\n const oldLen = entries.length\n const newLen = newItems.length\n if (newLen >= oldLen) {\n // Not a removal — fallback (shouldn't happen if compiler detected correctly)\n reconcileEntries(\n entries,\n newItems,\n opts,\n parentLifetime,\n parent,\n anchor,\n endAnchor,\n ctx,\n state,\n leaving,\n null,\n )\n emitDiff(oldKeys)\n return\n }\n\n // Parallel walk: new items are a subsequence of old items (same order, some removed)\n let ni = 0\n let didRemove = false\n for (let oi = 0; oi < oldLen; oi++) {\n const entry = entries[oi]!\n if (ni < newLen && entry.key === callKey(opts, newItems[ni]!)) {\n // Entry survives — update if item ref changed\n if (entry.item !== newItems[ni]) {\n updateEntry(entry, newItems[ni]!, ni)\n }\n ni++\n } else {\n // Entry removed — notify selectors before scope disposal\n for (let ci = 0; ci < removeCallbacks.length; ci++) removeCallbacks[ci]!(entry.key)\n for (const node of entry.nodes) parent.removeChild(node)\n entry.scope.disposalCause = 'each-remove'\n disposeLifetime(entry.scope, true)\n entries[oi] = null!\n didRemove = true\n }\n }\n\n // Compact entries array\n if (didRemove) {\n let w = 0\n for (let r = 0; r < oldLen; r++) {\n if (entries[r]) entries[w++] = entries[r]!\n }\n entries.length = w\n removeOrphanedChildren(parentLifetime)\n }\n\n // Update indices for remaining entries\n for (let i = 0; i < entries.length; i++) {\n entries[i]!.index = i\n }\n\n emitDiff(oldKeys)\n },\n\n /** Update only entries at stride intervals — O(k) where k = n/stride.\n * The compiler passes the stride from the detected for-loop pattern. */\n reconcileChanged(state: unknown, stride: number) {\n const newItems = callItems(opts, state as S)\n lastItemsRef = newItems\n for (let i = 0; i < entries.length && i < newItems.length; i += stride) {\n const entry = entries[i]!\n const newItem = newItems[i]!\n if (entry.item !== newItem) {\n updateEntry(entry, newItem, i)\n }\n }\n },\n }\n\n // Register the block BEFORE building initial row entries so that this\n // each() block precedes any nested structural blocks its rows register.\n // Parents must come first in the flat blocks array — see branch.ts for\n // the full rationale (Phase 1 iteration safety when disposing nested).\n blocks.push(block)\n\n activeClearCallbacks = clearCallbacks\n activeRemoveCallbacks = removeCallbacks\n for (let i = 0; i < initialItems.length; i++) {\n const item = initialItems[i]!\n const entry = buildEntry(item, i, opts, parentLifetime, ctx)\n entries.push(entry)\n }\n activeClearCallbacks = null\n activeRemoveCallbacks = null\n\n // Fire initial enter for mount-time items\n if (opts.enter) {\n for (const entry of entries) {\n if (entry.nodes.length > 0) opts.enter(entry.nodes)\n }\n }\n\n addDisposer(parentLifetime, () => {\n const idx = blocks.indexOf(block)\n if (idx !== -1) blocks.splice(idx, 1)\n // parentLifetime is being disposed — its children array is about to be\n // cleared by the recursive dispose pass, so skip per-entry parent\n // removal (avoids O(N²) indexOf+splice).\n //\n // Rows created AFTER the parent's initial render (each reconciled\n // with a new item list) are siblings of the anchor inside the\n // parent's DOM container, but aren't tracked by the parent's\n // snapshot (e.g. an outer branch's currentNodes). Walking entries\n // here and removing their DOM — guarded by parentNode — closes\n // the leak: cascade-removed subtrees no-op, live-parent cases get\n // the orphans cleaned up.\n for (const entry of entries) {\n for (const node of entry.nodes) {\n if (node.parentNode) node.parentNode.removeChild(node)\n }\n disposeLifetime(entry.scope, true)\n }\n entries.length = 0\n if (anchor.parentNode) anchor.parentNode.removeChild(anchor)\n if (endAnchor.parentNode) endAnchor.parentNode.removeChild(endAnchor)\n // Force-remove any mid-leave entries immediately\n for (const entry of leaving) {\n for (const node of entry.nodes) {\n if (node.parentNode) node.parentNode.removeChild(node)\n }\n disposeLifetime(entry.scope, true)\n }\n leaving.length = 0\n })\n\n const result: Node[] = [anchor]\n for (const entry of entries) {\n const nodes = entry.nodes\n for (let i = 0; i < nodes.length; i++) result.push(nodes[i]!)\n }\n result.push(endAnchor)\n return result\n}\n\n/**\n * Remove an entry's DOM + dispose its scope, running opts.leave first if\n * provided. When leave returns a Promise, the DOM removal is deferred until\n * resolution (entry is tracked in `leaving`).\n */\nfunction removeEntry<T>(\n entry: Entry<T>,\n opts: { leave?: (nodes: Node[]) => void | Promise<void> },\n leaving: Entry<T>[],\n): void {\n const removeNow = (): void => {\n for (const node of entry.nodes) {\n if (node.parentNode) node.parentNode.removeChild(node)\n }\n entry.scope.disposalCause = 'each-remove'\n disposeLifetime(entry.scope)\n const idx = leaving.indexOf(entry)\n if (idx !== -1) leaving.splice(idx, 1)\n }\n if (opts.leave && entry.nodes.length > 0) {\n const result = opts.leave(entry.nodes)\n if (result && typeof (result as Promise<void>).then === 'function') {\n leaving.push(entry)\n ;(result as Promise<void>).then(removeNow)\n return\n }\n }\n removeNow()\n}\n\nfunction fireEnter<T>(\n entry: Entry<T>,\n opts: { enter?: (nodes: Node[]) => void | Promise<void> },\n): void {\n if (opts.enter && entry.nodes.length > 0) {\n void opts.enter(entry.nodes)\n }\n}\n\nfunction buildEntry<S, T, M>(\n item: T,\n index: number,\n opts: EachOptions<S, T, M>,\n parentLifetime: Lifetime,\n ctx: ReturnType<typeof getRenderContext>,\n state?: unknown,\n): Entry<T> {\n const key = callKey(opts, item)\n // Use a lightweight scope — just needs itemUpdaters for per-item bindings.\n // Full scope features (disposers, bindings, children) are only needed when\n // the render callback uses structural primitives or selector.bind().\n const scope = createLifetime(parentLifetime)\n scope._kind = 'each'\n const currentState = (state ?? ctx.state) as S\n const send = ctx.send as (msg: M) => void\n\n // Create entry before render so itemAccessor closures can capture it\n const entry: Entry<T> = { key, item, current: item, index, scope, nodes: null!, updaters: [] }\n\n // Base callable: item(selector) for computed expressions\n const itemFn = <R>(selector: (t: T) => R): (() => R) => {\n const accessor = () => selector(entry.current)\n accessor.__perItem = true as const\n return accessor\n }\n\n // Proxy for item.field shorthand: LAZILY created. Compiled code uses\n // `acc(fn)` instead (the compiler rewrites item.x → acc(r => r.x)),\n // so the Proxy is never constructed in the common case. This saves\n // ~300ns × N Proxy allocations per create cycle.\n let itemProxy: ItemAccessor<T> | null = null\n const getItemProxy = (): ItemAccessor<T> => {\n if (itemProxy) return itemProxy\n let fieldCache: Map<string, () => unknown> | null = null\n itemProxy = new Proxy(itemFn as object, {\n get(target, prop) {\n if (typeof prop === 'symbol' || prop === 'then' || prop === 'prototype') {\n return Reflect.get(target, prop)\n }\n const key = prop as string\n if (fieldCache) {\n const cached = fieldCache.get(key)\n if (cached) return cached\n } else {\n fieldCache = new Map()\n }\n // `current` returns the whole item — essential for primitive T\n // (where the field map is useless) and for whole-record sampling.\n // Caller must call it like a method: `item.current()`.\n const accessor =\n key === 'current'\n ? () => entry.current\n : () => (entry.current as Record<string, unknown>)[key]\n ;(accessor as unknown as { __perItem: true }).__perItem = true\n fieldCache.set(key, accessor)\n return accessor\n },\n }) as ItemAccessor<T>\n return itemProxy\n }\n\n const indexAccessor = (): number => entry.index\n\n // Reuse a single context object to avoid allocation per entry. Every\n // non-rootLifetime/non-state field is copied from the surrounding\n // context — including `send` and `container`, which were dropped by\n // earlier versions. Missing `send` silently broke `child({ onMsg })`\n // bubble-up from inside an each() row (child.ts reads `parentCtx.send`,\n // got `undefined`, and skipped the bubble). Missing `container` made\n // `onMount(cb)` fall back to `document.body` instead of the parent\n // component's container.\n buildCtx.rootLifetime = scope\n buildCtx.state = currentState\n buildCtx.allBindings = ctx.allBindings\n buildCtx.structuralBlocks = ctx.structuralBlocks\n buildCtx.dom = ctx.dom\n buildCtx.instance = ctx.instance\n buildCtx.send = ctx.send\n buildCtx.container = ctx.container\n const prevFlatBindings = getFlatBindings()\n setFlatBindings(ctx.allBindings)\n setRenderContext(buildCtx)\n\n // Reuse a single render bag object across entries — mutate `acc` and\n // `index` per entry to avoid per-entry object allocation.\n buildBag.send = send\n buildBag.acc = itemFn\n buildBag.index = indexAccessor\n buildBag._getItemProxy = getItemProxy\n buildBag.entry = entry\n // The View bag — lets each.render use `h.text`, `h.scope`, `h.sample`,\n // etc. without reaching for the top-level imports. Each entry gets a\n // fresh View so its `send` is bound to this row's dispatch path.\n buildBag.h = createView<S, M>(send)\n // Row factory: pass compiler-injected template + update function through to render\n const rfOpts = opts as unknown as Record<string, unknown>\n if (rfOpts.__tpl) buildBag.__tpl = rfOpts.__tpl\n if (rfOpts.__rowUpd) buildBag.__rowUpd = rfOpts.__rowUpd\n entry.nodes = opts.render(buildBag as Parameters<typeof opts.render>[0])\n\n // Move itemUpdaters from scope to entry for direct access during updateEntry.\n // This avoids scope.itemUpdaters lookup overhead on every item update.\n if (scope.itemUpdaters.length > 0) {\n entry.updaters = scope.itemUpdaters\n scope.itemUpdaters = []\n }\n\n clearRenderContext()\n setFlatBindings(prevFlatBindings)\n setRenderContext(ctx)\n\n return entry\n}\n\ninterface TransitionReport {\n entering: Node[]\n leaving: Node[]\n}\n\nfunction collectNodes(target: Node[], nodes: Node[]): void {\n for (const n of nodes) target.push(n)\n}\n\nfunction reconcileEntries<S, T>(\n entries: Entry<T>[],\n newItems: T[],\n opts: EachOptions<S, T>,\n parentLifetime: Lifetime,\n parent: Node,\n anchor: Node,\n endAnchor: Node,\n ctx: ReturnType<typeof getRenderContext>,\n state: unknown,\n leaving: Entry<T>[],\n report: TransitionReport | null,\n): void {\n const oldLen = entries.length\n const newLen = newItems.length\n const hasLeave = !!opts.leave\n\n // Fast path 1: clear all — bulk DOM removal.\n // When opts.leave is set, each item needs its own leave animation, so\n // fall through to per-item removal instead of Range.deleteContents().\n if (newLen === 0) {\n if (report) {\n for (const entry of entries) collectNodes(report.leaving, entry.nodes)\n }\n if (hasLeave) {\n const toRemove = entries.slice()\n entries.length = 0\n for (const entry of toRemove) removeEntry(entry, opts, leaving)\n return\n }\n // Remove all DOM nodes in one operation using Range. Anchored on\n // start + end sentinels — see endAnchor comment in each() for why.\n if (entries.length > 0) {\n const range = ctx.dom.createRange()\n range.setStartAfter(anchor)\n range.setEndBefore(endAnchor)\n range.deleteContents()\n }\n // Bulk dispose all entry scopes — avoids per-scope function call overhead\n const scopes: Lifetime[] = []\n for (let i = 0; i < entries.length; i++) {\n const s = entries[i]!.scope\n s.disposalCause = 'each-remove'\n scopes.push(s)\n }\n disposeLifetimesBulk(scopes)\n removeOrphanedChildren(parentLifetime)\n entries.length = 0\n return\n }\n\n // Fast path 2: append-only — old keys are a prefix of new keys\n if (newLen > oldLen && isAppendOnly(entries, newItems, opts)) {\n for (let i = 0; i < oldLen; i++) {\n updateEntry(entries[i]!, newItems[i]!, i)\n }\n // Find insertion point: after last existing entry's last node, or after anchor\n const lastEntry = oldLen > 0 ? entries[oldLen - 1]! : null\n const ref = lastEntry\n ? lastEntry.nodes[lastEntry.nodes.length - 1]!.nextSibling\n : anchor.nextSibling\n const frag = ctx.dom.createDocumentFragment()\n const newlyAdded: Entry<T>[] = []\n for (let i = oldLen; i < newLen; i++) {\n const entry = buildEntry(newItems[i]!, i, opts, parentLifetime, ctx, state)\n entries.push(entry)\n newlyAdded.push(entry)\n for (const node of entry.nodes) frag.appendChild(node)\n }\n parent.insertBefore(frag, ref)\n if (report) {\n for (const entry of newlyAdded) collectNodes(report.entering, entry.nodes)\n }\n for (const entry of newlyAdded) fireEnter(entry, opts)\n return\n }\n\n // Fast path 3: same length — single pass handles both same-keys update\n // and two-element swap detection. Avoids a second O(n) pass.\n if (newLen === oldLen) {\n let mismatch1 = -1\n let mismatch2 = -1\n let mismatchCount = 0\n\n for (let i = 0; i < newLen; i++) {\n const entry = entries[i]!\n const newItem = newItems[i]!\n if (entry.item === newItem) continue\n const newKey = callKey(opts, newItem)\n if (entry.key === newKey) {\n updateEntry(entry, newItem, i)\n continue\n }\n // Key mismatch — track for swap detection\n mismatchCount++\n if (mismatchCount === 1) mismatch1 = i\n else if (mismatchCount === 2) mismatch2 = i\n else break // 3+ mismatches → fall through to general path\n }\n\n // All keys matched (with possible item updates) → done\n if (mismatchCount === 0) return\n\n // Exactly 2 key mismatches — check if it's a swap\n if (mismatchCount === 2) {\n const e1 = entries[mismatch1]!\n const e2 = entries[mismatch2]!\n if (\n e1.key === callKey(opts, newItems[mismatch2]!) &&\n e2.key === callKey(opts, newItems[mismatch1]!)\n ) {\n // DOM swap\n const refI = e1.nodes[0]!\n const refAfterJ = e2.nodes[e2.nodes.length - 1]!.nextSibling\n for (const node of e2.nodes) parent.insertBefore(node, refI)\n for (const node of e1.nodes) parent.insertBefore(node, refAfterJ)\n entries[mismatch1] = e2\n entries[mismatch2] = e1\n updateEntry(e2, newItems[mismatch1]!, mismatch1)\n updateEntry(e1, newItems[mismatch2]!, mismatch2)\n return\n }\n }\n // Fall through to general path for 3+ mismatches or non-swap\n }\n\n // Fast path 5: full replace — no shared keys between old and new.\n // Skipped when opts.leave is set so departing items can animate individually.\n if (!hasLeave && oldLen > 0 && callKey(opts, newItems[0]!) !== entries[0]!.key) {\n const oldKeys = new Set<string | number>()\n for (const entry of entries) oldKeys.add(entry.key)\n let anyShared = false\n for (let i = 0; i < newLen; i++) {\n if (oldKeys.has(callKey(opts, newItems[i]!))) {\n anyShared = true\n break\n }\n }\n if (!anyShared) {\n if (report) {\n for (const entry of entries) collectNodes(report.leaving, entry.nodes)\n }\n // Bulk DOM removal using Range — anchored on this each's stable\n // sentinels so a stale lastEntry node from a nested-primitive\n // mutation can't trip setEndAfter.\n const range = ctx.dom.createRange()\n range.setStartAfter(anchor)\n range.setEndBefore(endAnchor)\n range.deleteContents()\n // Bulk dispose all old scopes\n const oldLifetimes: Lifetime[] = []\n for (let i = 0; i < entries.length; i++) {\n const s = entries[i]!.scope\n s.disposalCause = 'each-remove'\n oldLifetimes.push(s)\n }\n disposeLifetimesBulk(oldLifetimes)\n removeOrphanedChildren(parentLifetime)\n entries.length = 0\n // Build all new entries into a fragment\n const frag = ctx.dom.createDocumentFragment()\n const newlyAdded: Entry<T>[] = []\n for (let i = 0; i < newLen; i++) {\n const entry = buildEntry(newItems[i]!, i, opts, parentLifetime, ctx, state)\n entries.push(entry)\n newlyAdded.push(entry)\n for (const node of entry.nodes) frag.appendChild(node)\n }\n parent.insertBefore(frag, anchor.nextSibling)\n if (report) {\n for (const entry of newlyAdded) collectNodes(report.entering, entry.nodes)\n }\n for (const entry of newlyAdded) fireEnter(entry, opts)\n return\n }\n }\n\n // General path: keyed reconciliation\n const oldByKey = new Map<string | number, Entry<T>>()\n for (const entry of entries) {\n oldByKey.set(entry.key, entry)\n }\n\n const newEntries: Entry<T>[] = []\n const usedKeys = new Set<string | number>()\n const newlyAdded: Entry<T>[] = []\n\n for (let i = 0; i < newLen; i++) {\n const item = newItems[i]!\n const key = callKey(opts, item)\n usedKeys.add(key)\n\n const existing = oldByKey.get(key)\n if (existing) {\n updateEntry(existing, item, i)\n newEntries.push(existing)\n } else {\n const entry = buildEntry(item, i, opts, parentLifetime, ctx, state)\n newEntries.push(entry)\n newlyAdded.push(entry)\n }\n }\n\n // Remove entries not in the new list. Use bulk-detach pattern so\n // disposing K removals costs O(K+P) rather than O(K*P) where P is\n // parentLifetime.children.length (avoids K * indexOf+splice).\n let didBulkDetach = false\n for (const entry of entries) {\n if (!usedKeys.has(entry.key)) {\n if (report) collectNodes(report.leaving, entry.nodes)\n if (hasLeave) {\n removeEntry(entry, opts, leaving)\n } else {\n // Defensive guard: a nested primitive (inner each / show / branch)\n // may have replaced its own captured nodes between the outer\n // render snapshot and now. Those replaced nodes are still in\n // entry.nodes but no longer children of `parent`. Skip them —\n // the inner-primitive's addDisposer cascade (run by the scope\n // disposal below) cleans up the orphan replacement nodes that\n // ARE attached. Without this guard, removeChild throws\n // NotFoundError on the stale ones.\n for (const node of entry.nodes) {\n if (node.parentNode === parent) parent.removeChild(node)\n }\n entry.scope.disposalCause = 'each-remove'\n disposeLifetime(entry.scope, true)\n didBulkDetach = true\n }\n }\n }\n if (didBulkDetach) removeOrphanedChildren(parentLifetime)\n\n // Reorder DOM\n const hasSurvivors = newEntries.some((e) => oldByKey.has(e.key))\n\n if (!hasSurvivors || !survivorsInOrder(entries, newEntries, usedKeys)) {\n // Full fragment rebuild — one reflow\n const frag = ctx.dom.createDocumentFragment()\n for (const entry of newEntries) {\n for (const node of entry.nodes) frag.appendChild(node)\n }\n parent.insertBefore(frag, anchor.nextSibling)\n } else {\n // Survivors in order — batch-insert new entries between survivors\n let frag: DocumentFragment | null = null\n let insertRef: ChildNode | null = anchor.nextSibling\n for (const entry of newEntries) {\n if (oldByKey.has(entry.key)) {\n // Flush any pending fragment before this survivor\n if (frag) {\n parent.insertBefore(frag, insertRef)\n frag = null\n }\n // Skip past survivor's nodes\n const lastNode = entry.nodes[entry.nodes.length - 1]\n insertRef = lastNode ? lastNode.nextSibling : insertRef\n } else {\n // Batch new entries into a fragment\n if (!frag) frag = ctx.dom.createDocumentFragment()\n for (const node of entry.nodes) frag.appendChild(node)\n }\n }\n if (frag) parent.insertBefore(frag, insertRef)\n }\n\n entries.length = newEntries.length\n for (let i = 0; i < newEntries.length; i++) entries[i] = newEntries[i]!\n\n if (report) {\n for (const entry of newlyAdded) collectNodes(report.entering, entry.nodes)\n }\n\n // Fire enter for newly-added entries (after DOM insertion)\n if (opts.enter) {\n for (const entry of newlyAdded) fireEnter(entry, opts)\n }\n}\n\nfunction updateEntry<T>(entry: Entry<T>, item: T, index: number): void {\n const changed = !Object.is(entry.item, item)\n entry.item = item\n entry.current = item\n entry.index = index\n // eachItemStable removed — unused\n // Directly run per-item updaters when item changed — bypasses Phase 2\n if (changed) {\n // Row factory fast path: shared update function, zero closures\n const rowUpd = (entry as unknown as Record<string, unknown>).__rowUpdate as\n | ((e: Entry<T>) => void)\n | undefined\n if (rowUpd) {\n rowUpd(entry)\n } else {\n // Closure-based fallback\n const updaters = entry.updaters.length > 0 ? entry.updaters : entry.scope.itemUpdaters\n for (let i = 0; i < updaters.length; i++) {\n updaters[i]!()\n }\n }\n }\n}\n\nfunction isAppendOnly<S, T>(entries: Entry<T>[], newItems: T[], opts: EachOptions<S, T>): boolean {\n for (let i = 0; i < entries.length; i++) {\n if (entries[i]!.key !== callKey(opts, newItems[i]!)) return false\n }\n return true\n}\n\nfunction survivorsInOrder<T>(\n oldEntries: Entry<T>[],\n newEntries: Entry<T>[],\n usedKeys: Set<string | number>,\n): boolean {\n // Build old-index map for survivors\n const oldIndexMap = new Map<string | number, number>()\n for (let i = 0; i < oldEntries.length; i++) {\n if (usedKeys.has(oldEntries[i]!.key)) {\n oldIndexMap.set(oldEntries[i]!.key, i)\n }\n }\n // Check that survivors appear in increasing old-index order in newEntries\n let maxOldIndex = -1\n for (const entry of newEntries) {\n const oldIdx = oldIndexMap.get(entry.key)\n if (oldIdx === undefined) continue // new entry, skip\n if (oldIdx < maxOldIndex) return false\n maxOldIndex = oldIdx\n }\n return true\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-each.d.ts","sourceRoot":"","sources":["../../src/primitives/virtual-each.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAY,IAAI,EAAE,MAAM,aAAa,CAAA;AAc/D,MAAM,WAAW,kBAAkB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO;IACnD,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAA;IACpB,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,CAAA;IACjC,qFAAqF;IACrF,UAAU,EAAE,MAAM,CAAA;IAClB,6CAA6C;IAC7C,eAAe,EAAE,MAAM,CAAA;IACvB,sFAAsF;IACtF,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,CAAC,IAAI,EAAE;QACb,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;QACb,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,CAAA;QACrB,GAAG,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,MAAM,CAAC,CAAA;QAC1C,KAAK,EAAE,MAAM,MAAM,CAAA;K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B,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,CA6NxF"}
|
|
@@ -124,12 +124,19 @@ export function virtualEach(opts) {
|
|
|
124
124
|
return itemProxy;
|
|
125
125
|
};
|
|
126
126
|
const indexAccessor = () => entry.index;
|
|
127
|
+
// Every non-rootLifetime/non-state field is copied from the
|
|
128
|
+
// surrounding context — including `send` and `container`. See the
|
|
129
|
+
// matching note in `each.ts`: missing `send` broke
|
|
130
|
+
// `child({ onMsg })` bubble-up from inside virtual-each rows;
|
|
131
|
+
// missing `container` would point `onMount` at `document.body`.
|
|
127
132
|
buildCtx.rootLifetime = scope;
|
|
128
133
|
buildCtx.state = state;
|
|
129
134
|
buildCtx.allBindings = ctx.allBindings;
|
|
130
135
|
buildCtx.structuralBlocks = ctx.structuralBlocks;
|
|
131
136
|
buildCtx.dom = ctx.dom;
|
|
132
137
|
buildCtx.instance = ctx.instance;
|
|
138
|
+
buildCtx.send = ctx.send;
|
|
139
|
+
buildCtx.container = ctx.container;
|
|
133
140
|
const prevFlat = getFlatBindings();
|
|
134
141
|
setFlatBindings(ctx.allBindings);
|
|
135
142
|
setRenderContext(buildCtx);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-each.js","sourceRoot":"","sources":["../../src/primitives/virtual-each.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,YAAY,GAEb,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC7E,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AA8B7C,MAAM,QAAQ,GAAkB;IAC9B,YAAY,EAAE,IAA2B;IACzC,KAAK,EAAE,IAAI;IACX,WAAW,EAAE,EAAE;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AC,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;YACnC,CAAC;QACH,CAAC;IACH,CAAC,CAAA;IAED,4EAA4E;IAC5E,MAAM,QAAQ,GAAG,GAAS,EAAE;QAC1B,SAAS,GAAG,MAAM,CAAC,SAAS,CAAA;QAC5B,SAAS,CAAC,GAAG,CAAC,KAAU,CAAC,CAAA;IAC3B,CAAC,CAAA;IACD,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;IAE9D,qEAAqE;IACrE,sEAAsE;IACtE,6CAA6C;IAC7C,MAAM,KAAK,GAAoB;QAC7B,IAAI,EAAE,SAAS;QACf,SAAS,CAAC,KAAc;YACtB,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAU,CAAC,CAAA;YACtC,IAAI,QAAQ,KAAK,SAAS;gBAAE,OAAM;YAClC,SAAS,CAAC,KAAU,CAAC,CAAA;QACvB,CAAC;KACF,CAAA;IACD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAElB,iBAAiB;IACjB,SAAS,CAAC,GAAG,CAAC,KAAU,CAAC,CAAA;IAEzB,6BAA6B;IAC7B,WAAW,CAAC,cAAc,EAAE,GAAG,EAAE;QAC/B,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;QAC9C,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YACrC,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAC9B,CAAC;QACD,OAAO,CAAC,KAAK,EAAE,CAAA;IACjB,CAAC,CAAC,CAAA;IAEF,OAAO,CAAC,MAAM,CAAC,CAAA;AACjB,CAAC","sourcesContent":["import type { ItemAccessor, Lifetime, Send } from '../types.js'\nimport {\n getRenderContext,\n setRenderContext,\n clearRenderContext,\n enterAccessor,\n exitAccessor,\n type RenderContext,\n} from '../render-context.js'\nimport { createLifetime, disposeLifetime, addDisposer } from '../lifetime.js'\nimport { getFlatBindings, setFlatBindings } from '../binding.js'\nimport { FULL_MASK } from '../update-loop.js'\nimport type { StructuralBlock } from '../structural.js'\n\nexport interface VirtualEachOptions<S, T, M = unknown> {\n items: (s: S) => T[]\n key: (item: T) => string | number\n /** Fixed pixel height per item. Required — dynamic heights are not supported yet. */\n itemHeight: number\n /** Scrollable container height in pixels. */\n containerHeight: number\n /** Extra rows to render above/below the viewport for smooth scrolling. Default: 3. */\n overscan?: number\n /** Optional class for the scroll container. */\n class?: string\n render: (opts: {\n send: Send<M>\n item: ItemAccessor<T>\n acc: <R>(selector: (t: T) => R) => () => R\n index: () => number\n }) => Node[]\n}\n\ninterface VirtualEntry<T> {\n key: string | number\n current: T\n index: number\n scope: Lifetime\n wrapper: HTMLElement\n}\n\nconst buildCtx: RenderContext = {\n rootLifetime: null as unknown as Lifetime,\n state: null,\n allBindings: [],\n structuralBlocks: [],\n dom: null as unknown as import('../dom-env.js').DomEnv,\n}\n\n/**\n * Virtualized list — renders only the rows visible in the scroll viewport.\n * Use for lists with 1k+ items where a regular `each()` would be too slow.\n *\n * Current limitations:\n * - Fixed row height (`itemHeight`) — dynamic heights not supported\n * - No transitions / animations\n * - No cross-container reuse (items outside view are fully disposed)\n *\n * ```ts\n * view: ({ text }) => [\n * ...virtualEach({\n * items: (s) => s.rows,\n * key: (r) => r.id,\n * itemHeight: 40,\n * containerHeight: 600,\n * render: ({ item }) => [\n * div({ class: 'row' }, [text(item.label)]),\n * ],\n * }),\n * ]\n * ```\n */\nexport function virtualEach<S, T, M = unknown>(opts: VirtualEachOptions<S, T, M>): Node[] {\n const ctx = getRenderContext('virtualEach')\n const parentLifetime = ctx.rootLifetime\n const blocks = ctx.structuralBlocks\n const send = ctx.send as (msg: M) => void\n\n const overscan = opts.overscan ?? 3\n\n // Scroll container\n const scroll = ctx.dom.createElement('div') as HTMLDivElement\n scroll.style.overflow = 'auto'\n scroll.style.position = 'relative'\n scroll.style.height = `${opts.containerHeight}px`\n scroll.dataset.virtualContainer = ''\n if (opts.class) scroll.className = opts.class\n\n // Inner spacer sized to full content height\n const spacer = ctx.dom.createElement('div') as HTMLDivElement\n spacer.style.position = 'relative'\n spacer.style.width = '100%'\n spacer.dataset.virtualSpacer = ''\n scroll.appendChild(spacer)\n\n // Map of key → entry\n const entries = new Map<string | number, VirtualEntry<T>>()\n let lastItems: T[] = []\n let scrollTop = 0\n\n const computeRange = (length: number): [number, number] => {\n if (length === 0) return [0, 0]\n const start = Math.max(0, Math.floor(scrollTop / opts.itemHeight) - overscan)\n const end = Math.min(\n length,\n Math.ceil((scrollTop + opts.containerHeight) / opts.itemHeight) + overscan,\n )\n return [start, end]\n }\n\n // Wrap accessor invocations to make sample()/h.sample() inside throw a\n // targeted error. Mirrors the wrappers in each.ts.\n const callItems = (state: S): T[] => {\n enterAccessor('virtualEach().items')\n try {\n return opts.items(state)\n } finally {\n exitAccessor()\n }\n }\n const callKey = (item: T): string | number => {\n enterAccessor('virtualEach().key')\n try {\n return opts.key(item)\n } finally {\n exitAccessor()\n }\n }\n\n const buildEntry = (item: T, index: number, state: S): VirtualEntry<T> => {\n const key = callKey(item)\n const scope = createLifetime(parentLifetime)\n\n const wrapper = ctx.dom.createElement('div') as HTMLDivElement\n wrapper.style.position = 'absolute'\n wrapper.style.top = `${index * opts.itemHeight}px`\n wrapper.style.left = '0'\n wrapper.style.right = '0'\n wrapper.style.height = `${opts.itemHeight}px`\n wrapper.dataset.virtualItem = ''\n wrapper.dataset.virtualKey = String(key)\n\n const entry: VirtualEntry<T> = { key, current: item, index, scope, wrapper }\n\n // Item accessor: item(selector) and item.field\n const itemFn = <R>(selector: (t: T) => R): (() => R) => {\n const accessor = (): R => selector(entry.current)\n ;(accessor as unknown as { __perItem: true }).__perItem = true\n return accessor\n }\n\n let itemProxy: ItemAccessor<T> | null = null\n const getItemProxy = (): ItemAccessor<T> => {\n if (itemProxy) return itemProxy\n const fieldCache = new Map<string, () => unknown>()\n itemProxy = new Proxy(itemFn as object, {\n get(target, prop) {\n if (typeof prop === 'symbol' || prop === 'then' || prop === 'prototype') {\n return Reflect.get(target, prop)\n }\n const k = prop as string\n const cached = fieldCache.get(k)\n if (cached) return cached\n const accessor = (): unknown => (entry.current as Record<string, unknown>)[k]\n ;(accessor as unknown as { __perItem: true }).__perItem = true\n fieldCache.set(k, accessor)\n return accessor\n },\n }) as ItemAccessor<T>\n return itemProxy\n }\n\n const indexAccessor = (): number => entry.index\n\n buildCtx.rootLifetime = scope\n buildCtx.state = state\n buildCtx.allBindings = ctx.allBindings\n buildCtx.structuralBlocks = ctx.structuralBlocks\n buildCtx.dom = ctx.dom\n buildCtx.instance = ctx.instance\n const prevFlat = getFlatBindings()\n setFlatBindings(ctx.allBindings)\n setRenderContext(buildCtx)\n\n const nodes = opts.render({\n send,\n item: getItemProxy(),\n acc: itemFn,\n index: indexAccessor,\n })\n\n clearRenderContext()\n setFlatBindings(prevFlat)\n setRenderContext(ctx)\n\n for (const node of nodes) wrapper.appendChild(node)\n return entry\n }\n\n const reconcile = (state: S): void => {\n const items = callItems(state)\n lastItems = items\n\n // Update spacer total height\n spacer.style.height = `${items.length * opts.itemHeight}px`\n\n if (items.length === 0) {\n // Dispose all entries\n for (const entry of entries.values()) {\n entry.scope.disposalCause = 'each-remove'\n disposeLifetime(entry.scope)\n if (entry.wrapper.parentNode) entry.wrapper.parentNode.removeChild(entry.wrapper)\n }\n entries.clear()\n return\n }\n\n const [start, end] = computeRange(items.length)\n\n // Build a map of key → {item, index} for the visible range\n const visibleKeys = new Map<string | number, { item: T; index: number }>()\n for (let i = start; i < end; i++) {\n const item = items[i]!\n visibleKeys.set(callKey(item), { item, index: i })\n }\n\n // Dispose entries no longer visible\n for (const [key, entry] of entries) {\n if (!visibleKeys.has(key)) {\n entry.scope.disposalCause = 'each-remove'\n disposeLifetime(entry.scope)\n if (entry.wrapper.parentNode) entry.wrapper.parentNode.removeChild(entry.wrapper)\n entries.delete(key)\n }\n }\n\n // Create new entries + update existing\n for (const [key, { item, index }] of visibleKeys) {\n const existing = entries.get(key)\n if (existing) {\n existing.current = item\n if (existing.index !== index) {\n existing.index = index\n existing.wrapper.style.top = `${index * opts.itemHeight}px`\n }\n } else {\n const entry = buildEntry(item, index, state)\n entries.set(key, entry)\n spacer.appendChild(entry.wrapper)\n }\n }\n }\n\n // Scroll handler — reconcile visible range without touching component state\n const onScroll = (): void => {\n scrollTop = scroll.scrollTop\n reconcile(ctx.state as S)\n }\n scroll.addEventListener('scroll', onScroll, { passive: true })\n\n // Register as a structural block BEFORE initial render so this block\n // precedes any nested blocks its rows register. See branch.ts for the\n // full rationale (Phase 1 iteration safety).\n const block: StructuralBlock = {\n mask: FULL_MASK,\n reconcile(state: unknown) {\n const newItems = callItems(state as S)\n if (newItems === lastItems) return\n reconcile(state as S)\n },\n }\n blocks.push(block)\n\n // Initial render\n reconcile(ctx.state as S)\n\n // Cleanup on parent disposal\n addDisposer(parentLifetime, () => {\n scroll.removeEventListener('scroll', onScroll)\n for (const entry of entries.values()) {\n disposeLifetime(entry.scope)\n }\n entries.clear()\n })\n\n return [scroll]\n}\n"]}
|
|
1
|
+
{"version":3,"file":"virtual-each.js","sourceRoot":"","sources":["../../src/primitives/virtual-each.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,YAAY,GAEb,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC7E,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AA8B7C,MAAM,QAAQ,GAAkB;IAC9B,YAAY,EAAE,IAA2B;IACzC,KAAK,EAAE,IAAI;IACX,WAAW,EAAE,EAAE;IACf,gBAAgB,EAAE,EAAE;IACpB,GAAG,EAA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jB,CAAC","sourcesContent":["import type { ItemAccessor, Lifetime, Send } from '../types.js'\nimport {\n getRenderContext,\n setRenderContext,\n clearRenderContext,\n enterAccessor,\n exitAccessor,\n type RenderContext,\n} from '../render-context.js'\nimport { createLifetime, disposeLifetime, addDisposer } from '../lifetime.js'\nimport { getFlatBindings, setFlatBindings } from '../binding.js'\nimport { FULL_MASK } from '../update-loop.js'\nimport type { StructuralBlock } from '../structural.js'\n\nexport interface VirtualEachOptions<S, T, M = unknown> {\n items: (s: S) => T[]\n key: (item: T) => string | number\n /** Fixed pixel height per item. Required — dynamic heights are not supported yet. */\n itemHeight: number\n /** Scrollable container height in pixels. */\n containerHeight: number\n /** Extra rows to render above/below the viewport for smooth scrolling. Default: 3. */\n overscan?: number\n /** Optional class for the scroll container. */\n class?: string\n render: (opts: {\n send: Send<M>\n item: ItemAccessor<T>\n acc: <R>(selector: (t: T) => R) => () => R\n index: () => number\n }) => Node[]\n}\n\ninterface VirtualEntry<T> {\n key: string | number\n current: T\n index: number\n scope: Lifetime\n wrapper: HTMLElement\n}\n\nconst buildCtx: RenderContext = {\n rootLifetime: null as unknown as Lifetime,\n state: null,\n allBindings: [],\n structuralBlocks: [],\n dom: null as unknown as import('../dom-env.js').DomEnv,\n}\n\n/**\n * Virtualized list — renders only the rows visible in the scroll viewport.\n * Use for lists with 1k+ items where a regular `each()` would be too slow.\n *\n * Current limitations:\n * - Fixed row height (`itemHeight`) — dynamic heights not supported\n * - No transitions / animations\n * - No cross-container reuse (items outside view are fully disposed)\n *\n * ```ts\n * view: ({ text }) => [\n * ...virtualEach({\n * items: (s) => s.rows,\n * key: (r) => r.id,\n * itemHeight: 40,\n * containerHeight: 600,\n * render: ({ item }) => [\n * div({ class: 'row' }, [text(item.label)]),\n * ],\n * }),\n * ]\n * ```\n */\nexport function virtualEach<S, T, M = unknown>(opts: VirtualEachOptions<S, T, M>): Node[] {\n const ctx = getRenderContext('virtualEach')\n const parentLifetime = ctx.rootLifetime\n const blocks = ctx.structuralBlocks\n const send = ctx.send as (msg: M) => void\n\n const overscan = opts.overscan ?? 3\n\n // Scroll container\n const scroll = ctx.dom.createElement('div') as HTMLDivElement\n scroll.style.overflow = 'auto'\n scroll.style.position = 'relative'\n scroll.style.height = `${opts.containerHeight}px`\n scroll.dataset.virtualContainer = ''\n if (opts.class) scroll.className = opts.class\n\n // Inner spacer sized to full content height\n const spacer = ctx.dom.createElement('div') as HTMLDivElement\n spacer.style.position = 'relative'\n spacer.style.width = '100%'\n spacer.dataset.virtualSpacer = ''\n scroll.appendChild(spacer)\n\n // Map of key → entry\n const entries = new Map<string | number, VirtualEntry<T>>()\n let lastItems: T[] = []\n let scrollTop = 0\n\n const computeRange = (length: number): [number, number] => {\n if (length === 0) return [0, 0]\n const start = Math.max(0, Math.floor(scrollTop / opts.itemHeight) - overscan)\n const end = Math.min(\n length,\n Math.ceil((scrollTop + opts.containerHeight) / opts.itemHeight) + overscan,\n )\n return [start, end]\n }\n\n // Wrap accessor invocations to make sample()/h.sample() inside throw a\n // targeted error. Mirrors the wrappers in each.ts.\n const callItems = (state: S): T[] => {\n enterAccessor('virtualEach().items')\n try {\n return opts.items(state)\n } finally {\n exitAccessor()\n }\n }\n const callKey = (item: T): string | number => {\n enterAccessor('virtualEach().key')\n try {\n return opts.key(item)\n } finally {\n exitAccessor()\n }\n }\n\n const buildEntry = (item: T, index: number, state: S): VirtualEntry<T> => {\n const key = callKey(item)\n const scope = createLifetime(parentLifetime)\n\n const wrapper = ctx.dom.createElement('div') as HTMLDivElement\n wrapper.style.position = 'absolute'\n wrapper.style.top = `${index * opts.itemHeight}px`\n wrapper.style.left = '0'\n wrapper.style.right = '0'\n wrapper.style.height = `${opts.itemHeight}px`\n wrapper.dataset.virtualItem = ''\n wrapper.dataset.virtualKey = String(key)\n\n const entry: VirtualEntry<T> = { key, current: item, index, scope, wrapper }\n\n // Item accessor: item(selector) and item.field\n const itemFn = <R>(selector: (t: T) => R): (() => R) => {\n const accessor = (): R => selector(entry.current)\n ;(accessor as unknown as { __perItem: true }).__perItem = true\n return accessor\n }\n\n let itemProxy: ItemAccessor<T> | null = null\n const getItemProxy = (): ItemAccessor<T> => {\n if (itemProxy) return itemProxy\n const fieldCache = new Map<string, () => unknown>()\n itemProxy = new Proxy(itemFn as object, {\n get(target, prop) {\n if (typeof prop === 'symbol' || prop === 'then' || prop === 'prototype') {\n return Reflect.get(target, prop)\n }\n const k = prop as string\n const cached = fieldCache.get(k)\n if (cached) return cached\n const accessor = (): unknown => (entry.current as Record<string, unknown>)[k]\n ;(accessor as unknown as { __perItem: true }).__perItem = true\n fieldCache.set(k, accessor)\n return accessor\n },\n }) as ItemAccessor<T>\n return itemProxy\n }\n\n const indexAccessor = (): number => entry.index\n\n // Every non-rootLifetime/non-state field is copied from the\n // surrounding context — including `send` and `container`. See the\n // matching note in `each.ts`: missing `send` broke\n // `child({ onMsg })` bubble-up from inside virtual-each rows;\n // missing `container` would point `onMount` at `document.body`.\n buildCtx.rootLifetime = scope\n buildCtx.state = state\n buildCtx.allBindings = ctx.allBindings\n buildCtx.structuralBlocks = ctx.structuralBlocks\n buildCtx.dom = ctx.dom\n buildCtx.instance = ctx.instance\n buildCtx.send = ctx.send\n buildCtx.container = ctx.container\n const prevFlat = getFlatBindings()\n setFlatBindings(ctx.allBindings)\n setRenderContext(buildCtx)\n\n const nodes = opts.render({\n send,\n item: getItemProxy(),\n acc: itemFn,\n index: indexAccessor,\n })\n\n clearRenderContext()\n setFlatBindings(prevFlat)\n setRenderContext(ctx)\n\n for (const node of nodes) wrapper.appendChild(node)\n return entry\n }\n\n const reconcile = (state: S): void => {\n const items = callItems(state)\n lastItems = items\n\n // Update spacer total height\n spacer.style.height = `${items.length * opts.itemHeight}px`\n\n if (items.length === 0) {\n // Dispose all entries\n for (const entry of entries.values()) {\n entry.scope.disposalCause = 'each-remove'\n disposeLifetime(entry.scope)\n if (entry.wrapper.parentNode) entry.wrapper.parentNode.removeChild(entry.wrapper)\n }\n entries.clear()\n return\n }\n\n const [start, end] = computeRange(items.length)\n\n // Build a map of key → {item, index} for the visible range\n const visibleKeys = new Map<string | number, { item: T; index: number }>()\n for (let i = start; i < end; i++) {\n const item = items[i]!\n visibleKeys.set(callKey(item), { item, index: i })\n }\n\n // Dispose entries no longer visible\n for (const [key, entry] of entries) {\n if (!visibleKeys.has(key)) {\n entry.scope.disposalCause = 'each-remove'\n disposeLifetime(entry.scope)\n if (entry.wrapper.parentNode) entry.wrapper.parentNode.removeChild(entry.wrapper)\n entries.delete(key)\n }\n }\n\n // Create new entries + update existing\n for (const [key, { item, index }] of visibleKeys) {\n const existing = entries.get(key)\n if (existing) {\n existing.current = item\n if (existing.index !== index) {\n existing.index = index\n existing.wrapper.style.top = `${index * opts.itemHeight}px`\n }\n } else {\n const entry = buildEntry(item, index, state)\n entries.set(key, entry)\n spacer.appendChild(entry.wrapper)\n }\n }\n }\n\n // Scroll handler — reconcile visible range without touching component state\n const onScroll = (): void => {\n scrollTop = scroll.scrollTop\n reconcile(ctx.state as S)\n }\n scroll.addEventListener('scroll', onScroll, { passive: true })\n\n // Register as a structural block BEFORE initial render so this block\n // precedes any nested blocks its rows register. See branch.ts for the\n // full rationale (Phase 1 iteration safety).\n const block: StructuralBlock = {\n mask: FULL_MASK,\n reconcile(state: unknown) {\n const newItems = callItems(state as S)\n if (newItems === lastItems) return\n reconcile(state as S)\n },\n }\n blocks.push(block)\n\n // Initial render\n reconcile(ctx.state as S)\n\n // Cleanup on parent disposal\n addDisposer(parentLifetime, () => {\n scroll.removeEventListener('scroll', onScroll)\n for (const entry of entries.values()) {\n disposeLifetime(entry.scope)\n }\n entries.clear()\n })\n\n return [scroll]\n}\n"]}
|