@sigx/server-renderer 0.1.5 → 0.1.6
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/client/hydrate.d.ts +6 -1
- package/dist/client/hydrate.d.ts.map +1 -1
- package/dist/client/index.d.ts +3 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +2 -661
- package/dist/client/plugin.d.ts +52 -0
- package/dist/client/plugin.d.ts.map +1 -0
- package/dist/client/registry.d.ts +9 -1
- package/dist/client/registry.d.ts.map +1 -1
- package/dist/client/types.d.ts +1 -21
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client-DiLwBAD-.js +541 -0
- package/dist/client-DiLwBAD-.js.map +1 -0
- package/dist/client-directives.d.ts +1 -1
- package/dist/index.d.ts +7 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1172
- package/dist/server/index.js +1 -573
- package/dist/server/stream.d.ts +34 -6
- package/dist/server/stream.d.ts.map +1 -1
- package/dist/server-BCOJt2Bi.js +459 -0
- package/dist/server-BCOJt2Bi.js.map +1 -0
- package/dist/shared/utils.d.ts +9 -0
- package/dist/shared/utils.d.ts.map +1 -0
- package/package.json +7 -8
- package/dist/client/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/server/index.js.map +0 -1
package/dist/client/hydrate.d.ts
CHANGED
|
@@ -4,14 +4,19 @@
|
|
|
4
4
|
* Hydration attaches the app to existing server-rendered DOM,
|
|
5
5
|
* then delegates all updates to the runtime-dom renderer.
|
|
6
6
|
*/
|
|
7
|
+
import { AppContext } from 'sigx';
|
|
7
8
|
export type { HydrationOptions } from './types.js';
|
|
8
9
|
/**
|
|
9
10
|
* Hydrate a server-rendered app.
|
|
10
11
|
*
|
|
11
12
|
* This walks the existing DOM to attach event handlers, runs component
|
|
12
13
|
* setup functions to establish reactivity, then uses runtime-dom for updates.
|
|
14
|
+
*
|
|
15
|
+
* @param element - The root element/VNode to hydrate
|
|
16
|
+
* @param container - The DOM container with SSR content
|
|
17
|
+
* @param appContext - The app context for DI (provides, etc.)
|
|
13
18
|
*/
|
|
14
|
-
export declare function hydrate(element: any, container: Element): void;
|
|
19
|
+
export declare function hydrate(element: any, container: Element, appContext?: AppContext): void;
|
|
15
20
|
/**
|
|
16
21
|
* Hydrate islands based on their strategies (selective hydration)
|
|
17
22
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydrate.d.ts","sourceRoot":"","sources":["../../src/client/hydrate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"hydrate.d.ts","sourceRoot":"","sources":["../../src/client/hydrate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAuBH,UAAU,EAEb,MAAM,MAAM,CAAC;AAKd,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AA0FnD;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,UAAU,GAAG,IAAI,CAYvF;AA+gBD;;GAEG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAkBrC"}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* Client-side hydration with selective/islands hydration support.
|
|
5
5
|
*/
|
|
6
6
|
import '../client-directives.js';
|
|
7
|
-
export {
|
|
7
|
+
export { ssrClientPlugin, type HydrateFn } from './plugin.js';
|
|
8
|
+
export { hydrateIslands } from './hydrate.js';
|
|
8
9
|
export { HydrationRegistry, registerComponent } from './registry.js';
|
|
9
|
-
export type { HydrationOptions } from './
|
|
10
|
+
export type { HydrationOptions } from './types.js';
|
|
10
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,yBAAyB,CAAC;AAGjC,OAAO,EAAE,eAAe,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAG9D,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG9C,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGrE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/client/index.js
CHANGED
|
@@ -1,661 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { patchProp, render } from "@sigx/runtime-dom";
|
|
4
|
-
|
|
5
|
-
//#region src/client/registry.ts
|
|
6
|
-
/**
|
|
7
|
-
* Registry mapping component names to component factories
|
|
8
|
-
*/
|
|
9
|
-
const componentRegistry = /* @__PURE__ */ new Map();
|
|
10
|
-
/**
|
|
11
|
-
* Register a component for island hydration.
|
|
12
|
-
* Components must be registered before hydrateIslands() is called.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* import { registerComponent } from '@sigx/server-renderer/client';
|
|
17
|
-
* import { Counter } from './components/Counter';
|
|
18
|
-
*
|
|
19
|
-
* registerComponent('Counter', Counter);
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
function registerComponent(name, component) {
|
|
23
|
-
componentRegistry.set(name, component);
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Get a registered component by name
|
|
27
|
-
*/
|
|
28
|
-
function getComponent(name) {
|
|
29
|
-
return componentRegistry.get(name);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Check if a value is a component factory
|
|
33
|
-
*/
|
|
34
|
-
function isComponent$1(value) {
|
|
35
|
-
return typeof value === "function" && "__setup" in value;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Hydration Registry class for more advanced use cases
|
|
39
|
-
*/
|
|
40
|
-
var HydrationRegistry = class {
|
|
41
|
-
components = /* @__PURE__ */ new Map();
|
|
42
|
-
register(name, component) {
|
|
43
|
-
this.components.set(name, component);
|
|
44
|
-
return this;
|
|
45
|
-
}
|
|
46
|
-
registerAll(components) {
|
|
47
|
-
for (const [name, component] of Object.entries(components)) if (isComponent$1(component)) this.register(name, component);
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
get(name) {
|
|
51
|
-
return this.components.get(name);
|
|
52
|
-
}
|
|
53
|
-
has(name) {
|
|
54
|
-
return this.components.has(name);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
//#endregion
|
|
59
|
-
//#region src/client/hydrate.ts
|
|
60
|
-
/**
|
|
61
|
-
* Client-side hydration for SSR'd content
|
|
62
|
-
*
|
|
63
|
-
* Hydration attaches the app to existing server-rendered DOM,
|
|
64
|
-
* then delegates all updates to the runtime-dom renderer.
|
|
65
|
-
*/
|
|
66
|
-
let _pendingServerState = null;
|
|
67
|
-
/**
|
|
68
|
-
* Set server state that should be used for the next component mount.
|
|
69
|
-
* Used internally when mounting async components after streaming.
|
|
70
|
-
*/
|
|
71
|
-
function setPendingServerState(state) {
|
|
72
|
-
_pendingServerState = state;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Register the SSR context extension for all components.
|
|
76
|
-
* This provides the `ssr` object with a no-op `load()` for client-side rendering.
|
|
77
|
-
* Also handles server state restoration for async streamed components.
|
|
78
|
-
*/
|
|
79
|
-
registerContextExtension((ctx) => {
|
|
80
|
-
const serverState = _pendingServerState;
|
|
81
|
-
if (serverState) {
|
|
82
|
-
ctx._serverState = serverState;
|
|
83
|
-
_pendingServerState = null;
|
|
84
|
-
ctx.signal = createRestoringSignal(serverState);
|
|
85
|
-
ctx.ssr = {
|
|
86
|
-
load: (_fn) => {},
|
|
87
|
-
isServer: false,
|
|
88
|
-
isHydrating: true
|
|
89
|
-
};
|
|
90
|
-
} else if (ctx._serverState) ctx.ssr = {
|
|
91
|
-
load: (_fn) => {},
|
|
92
|
-
isServer: false,
|
|
93
|
-
isHydrating: true
|
|
94
|
-
};
|
|
95
|
-
else ctx.ssr = {
|
|
96
|
-
load: (fn) => {
|
|
97
|
-
fn().catch((err) => console.error("[SSR] load error:", err));
|
|
98
|
-
},
|
|
99
|
-
isServer: false,
|
|
100
|
-
isHydrating: false
|
|
101
|
-
};
|
|
102
|
-
});
|
|
103
|
-
/**
|
|
104
|
-
* Creates a signal function that restores state from server-captured values.
|
|
105
|
-
* Used during hydration of async components to avoid re-fetching data.
|
|
106
|
-
*/
|
|
107
|
-
function createRestoringSignal(serverState) {
|
|
108
|
-
let signalIndex = 0;
|
|
109
|
-
return function restoringSignal(initial, name) {
|
|
110
|
-
const key = name ?? `$${signalIndex++}`;
|
|
111
|
-
if (key in serverState) {
|
|
112
|
-
console.log(`[Hydrate] Restoring signal "${key}" from server state:`, serverState[key]);
|
|
113
|
-
return signal(serverState[key]);
|
|
114
|
-
}
|
|
115
|
-
return signal(initial);
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Hydrate a server-rendered app.
|
|
120
|
-
*
|
|
121
|
-
* This walks the existing DOM to attach event handlers, runs component
|
|
122
|
-
* setup functions to establish reactivity, then uses runtime-dom for updates.
|
|
123
|
-
*/
|
|
124
|
-
function hydrate(element, container) {
|
|
125
|
-
const vnode = normalizeElement(element);
|
|
126
|
-
if (!vnode) return;
|
|
127
|
-
hydrateNode(vnode, container.firstChild, container);
|
|
128
|
-
container._vnode = vnode;
|
|
129
|
-
}
|
|
130
|
-
let _cachedIslandData = null;
|
|
131
|
-
/**
|
|
132
|
-
* Invalidate the island data cache (called when async components stream in)
|
|
133
|
-
*/
|
|
134
|
-
function invalidateIslandCache() {
|
|
135
|
-
_cachedIslandData = null;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Get island data from the __SIGX_ISLANDS__ script tag
|
|
139
|
-
*/
|
|
140
|
-
function getIslandData() {
|
|
141
|
-
if (_cachedIslandData !== null) return _cachedIslandData;
|
|
142
|
-
const dataScript = document.getElementById("__SIGX_ISLANDS__");
|
|
143
|
-
if (!dataScript) {
|
|
144
|
-
_cachedIslandData = {};
|
|
145
|
-
return _cachedIslandData;
|
|
146
|
-
}
|
|
147
|
-
try {
|
|
148
|
-
_cachedIslandData = JSON.parse(dataScript.textContent || "{}");
|
|
149
|
-
} catch {
|
|
150
|
-
console.error("Failed to parse island data");
|
|
151
|
-
_cachedIslandData = {};
|
|
152
|
-
}
|
|
153
|
-
return _cachedIslandData;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Get server state for a specific island/component by ID
|
|
157
|
-
*/
|
|
158
|
-
function getIslandServerState(componentId) {
|
|
159
|
-
return getIslandData()[String(componentId)]?.state;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Normalize any element to VNode
|
|
163
|
-
*/
|
|
164
|
-
function normalizeElement(element) {
|
|
165
|
-
if (element == null || element === true || element === false) return null;
|
|
166
|
-
if (typeof element === "string" || typeof element === "number") return {
|
|
167
|
-
type: Text,
|
|
168
|
-
props: {},
|
|
169
|
-
key: null,
|
|
170
|
-
children: [],
|
|
171
|
-
dom: null,
|
|
172
|
-
text: element
|
|
173
|
-
};
|
|
174
|
-
return element;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Check if type is a component
|
|
178
|
-
*/
|
|
179
|
-
function isComponent(type) {
|
|
180
|
-
return typeof type === "function" && "__setup" in type;
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Get hydration strategy from vnode props
|
|
184
|
-
*/
|
|
185
|
-
function getHydrationStrategy(props) {
|
|
186
|
-
if (props["client:load"] !== void 0) return { strategy: "load" };
|
|
187
|
-
if (props["client:idle"] !== void 0) return { strategy: "idle" };
|
|
188
|
-
if (props["client:visible"] !== void 0) return { strategy: "visible" };
|
|
189
|
-
if (props["client:only"] !== void 0) return { strategy: "only" };
|
|
190
|
-
if (props["client:media"] !== void 0) return {
|
|
191
|
-
strategy: "media",
|
|
192
|
-
media: props["client:media"]
|
|
193
|
-
};
|
|
194
|
-
return null;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Hydrate a VNode against existing DOM
|
|
198
|
-
* This only attaches event handlers and refs - no DOM creation
|
|
199
|
-
*/
|
|
200
|
-
function hydrateNode(vnode, dom, parent) {
|
|
201
|
-
if (!vnode) return dom;
|
|
202
|
-
while (dom && dom.nodeType === Node.COMMENT_NODE) {
|
|
203
|
-
const commentText = dom.data;
|
|
204
|
-
if (commentText.startsWith("$c:") || commentText.startsWith("/$c:") || commentText.startsWith("$island:")) break;
|
|
205
|
-
dom = dom.nextSibling;
|
|
206
|
-
}
|
|
207
|
-
if (vnode.type === Text) {
|
|
208
|
-
if (dom && dom.nodeType === Node.TEXT_NODE) {
|
|
209
|
-
vnode.dom = dom;
|
|
210
|
-
return dom.nextSibling;
|
|
211
|
-
}
|
|
212
|
-
return dom;
|
|
213
|
-
}
|
|
214
|
-
if (vnode.type === Fragment) {
|
|
215
|
-
let current = dom;
|
|
216
|
-
for (const child of vnode.children) current = hydrateNode(child, current, parent);
|
|
217
|
-
return current;
|
|
218
|
-
}
|
|
219
|
-
if (isComponent(vnode.type)) {
|
|
220
|
-
const strategy = vnode.props ? getHydrationStrategy(vnode.props) : null;
|
|
221
|
-
if (strategy) return scheduleComponentHydration(vnode, dom, parent, strategy);
|
|
222
|
-
return hydrateComponent(vnode, dom, parent);
|
|
223
|
-
}
|
|
224
|
-
if (typeof vnode.type === "string") {
|
|
225
|
-
if (!dom || dom.nodeType !== Node.ELEMENT_NODE) {
|
|
226
|
-
console.warn("[Hydrate] Expected element but got:", dom);
|
|
227
|
-
return dom;
|
|
228
|
-
}
|
|
229
|
-
const el = dom;
|
|
230
|
-
vnode.dom = el;
|
|
231
|
-
if (vnode.props) for (const key in vnode.props) {
|
|
232
|
-
if (key === "children" || key === "key") continue;
|
|
233
|
-
if (key.startsWith("client:")) continue;
|
|
234
|
-
patchProp(el, key, null, vnode.props[key]);
|
|
235
|
-
}
|
|
236
|
-
let childDom = el.firstChild;
|
|
237
|
-
for (const child of vnode.children) childDom = hydrateNode(child, childDom, el);
|
|
238
|
-
if (vnode.type === "select" && vnode.props) fixSelectValue(el, vnode.props);
|
|
239
|
-
return el.nextSibling;
|
|
240
|
-
}
|
|
241
|
-
return dom;
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Schedule component hydration based on strategy.
|
|
245
|
-
* Returns the next DOM node after this component's content.
|
|
246
|
-
*/
|
|
247
|
-
function scheduleComponentHydration(vnode, dom, parent, strategy) {
|
|
248
|
-
const { startNode, endNode } = findComponentBoundaries(dom);
|
|
249
|
-
const doHydrate = () => {
|
|
250
|
-
hydrateComponent(vnode, startNode, parent);
|
|
251
|
-
};
|
|
252
|
-
switch (strategy.strategy) {
|
|
253
|
-
case "load":
|
|
254
|
-
console.log("[Hydrate] client:load - hydrating immediately");
|
|
255
|
-
doHydrate();
|
|
256
|
-
break;
|
|
257
|
-
case "idle":
|
|
258
|
-
console.log("[Hydrate] client:idle - scheduling for idle time");
|
|
259
|
-
if ("requestIdleCallback" in window) requestIdleCallback(() => {
|
|
260
|
-
console.log("[Hydrate] client:idle - idle callback fired");
|
|
261
|
-
doHydrate();
|
|
262
|
-
});
|
|
263
|
-
else setTimeout(() => {
|
|
264
|
-
console.log("[Hydrate] client:idle - timeout fallback fired");
|
|
265
|
-
doHydrate();
|
|
266
|
-
}, 200);
|
|
267
|
-
break;
|
|
268
|
-
case "visible":
|
|
269
|
-
console.log("[Hydrate] client:visible - observing visibility");
|
|
270
|
-
observeComponentVisibility(startNode, endNode, doHydrate);
|
|
271
|
-
break;
|
|
272
|
-
case "media":
|
|
273
|
-
if (strategy.media) {
|
|
274
|
-
const mql = window.matchMedia(strategy.media);
|
|
275
|
-
if (mql.matches) doHydrate();
|
|
276
|
-
else {
|
|
277
|
-
const handler = (e) => {
|
|
278
|
-
if (e.matches) {
|
|
279
|
-
mql.removeEventListener("change", handler);
|
|
280
|
-
doHydrate();
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
mql.addEventListener("change", handler);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
break;
|
|
287
|
-
case "only":
|
|
288
|
-
doHydrate();
|
|
289
|
-
break;
|
|
290
|
-
}
|
|
291
|
-
return endNode ? endNode.nextSibling : dom;
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Find component start/end markers in DOM
|
|
295
|
-
*/
|
|
296
|
-
function findComponentBoundaries(dom) {
|
|
297
|
-
let startNode = dom;
|
|
298
|
-
let endNode = null;
|
|
299
|
-
if (dom && dom.nodeType === Node.COMMENT_NODE) {
|
|
300
|
-
const text = dom.data;
|
|
301
|
-
if (text.startsWith("$c:")) {
|
|
302
|
-
const id = text.slice(3);
|
|
303
|
-
startNode = dom;
|
|
304
|
-
let current = dom.nextSibling;
|
|
305
|
-
while (current) {
|
|
306
|
-
if (current.nodeType === Node.COMMENT_NODE) {
|
|
307
|
-
if (current.data === `/$c:${id}`) {
|
|
308
|
-
endNode = current;
|
|
309
|
-
break;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
current = current.nextSibling;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
return {
|
|
317
|
-
startNode,
|
|
318
|
-
endNode
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
|
-
* Observe when a component's DOM becomes visible
|
|
323
|
-
*/
|
|
324
|
-
function observeComponentVisibility(startNode, endNode, callback) {
|
|
325
|
-
let targetElement = null;
|
|
326
|
-
let current = startNode?.nextSibling || null;
|
|
327
|
-
while (current && current !== endNode) {
|
|
328
|
-
if (current.nodeType === Node.ELEMENT_NODE) {
|
|
329
|
-
targetElement = current;
|
|
330
|
-
break;
|
|
331
|
-
}
|
|
332
|
-
current = current.nextSibling;
|
|
333
|
-
}
|
|
334
|
-
if (!targetElement) {
|
|
335
|
-
callback();
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
const observer = new IntersectionObserver((entries) => {
|
|
339
|
-
for (const entry of entries) if (entry.isIntersecting) {
|
|
340
|
-
observer.disconnect();
|
|
341
|
-
callback();
|
|
342
|
-
break;
|
|
343
|
-
}
|
|
344
|
-
}, { rootMargin: "50px" });
|
|
345
|
-
observer.observe(targetElement);
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* Hydrate a component - run setup and create reactive effect
|
|
349
|
-
* @param vnode - The VNode to hydrate
|
|
350
|
-
* @param dom - The DOM node to start from
|
|
351
|
-
* @param parent - The parent node
|
|
352
|
-
* @param serverState - Optional state captured from server for async components
|
|
353
|
-
*/
|
|
354
|
-
function hydrateComponent(vnode, dom, parent, serverState) {
|
|
355
|
-
const componentFactory = vnode.type;
|
|
356
|
-
const setup = componentFactory.__setup;
|
|
357
|
-
const componentName = componentFactory.__name || "Anonymous";
|
|
358
|
-
if (componentName && componentName !== "Anonymous") registerComponent(componentName, componentFactory);
|
|
359
|
-
let anchor = null;
|
|
360
|
-
let componentId = null;
|
|
361
|
-
if (dom && dom.nodeType === Node.COMMENT_NODE) {
|
|
362
|
-
const commentText = dom.data;
|
|
363
|
-
if (commentText.startsWith("$c:")) {
|
|
364
|
-
anchor = dom;
|
|
365
|
-
componentId = parseInt(commentText.slice(3), 10);
|
|
366
|
-
dom = dom.nextSibling;
|
|
367
|
-
while (dom && dom.nodeType === Node.COMMENT_NODE) if (dom.data.startsWith("$island:")) dom = dom.nextSibling;
|
|
368
|
-
else break;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
if (!serverState && componentId !== null) serverState = getIslandServerState(componentId);
|
|
372
|
-
const internalVNode = vnode;
|
|
373
|
-
const { children, slots: slotsFromProps, ...propsData } = filterClientDirectives(vnode.props || {});
|
|
374
|
-
const reactiveProps = signal(propsData);
|
|
375
|
-
internalVNode._componentProps = reactiveProps;
|
|
376
|
-
const slots = createSlots(children, slotsFromProps);
|
|
377
|
-
internalVNode._slots = slots;
|
|
378
|
-
const mountHooks = [];
|
|
379
|
-
const cleanupHooks = [];
|
|
380
|
-
const parentInstance = getCurrentInstance();
|
|
381
|
-
const signalFn = serverState ? createRestoringSignal(serverState) : signal;
|
|
382
|
-
const hasServerState = !!serverState;
|
|
383
|
-
const ssrHelper = {
|
|
384
|
-
load(_fn) {
|
|
385
|
-
if (hasServerState) console.log(`[Hydrate] Skipping ssr.load() - using restored server state`);
|
|
386
|
-
},
|
|
387
|
-
isServer: false,
|
|
388
|
-
isHydrating: hasServerState
|
|
389
|
-
};
|
|
390
|
-
const componentCtx = {
|
|
391
|
-
el: parent,
|
|
392
|
-
signal: signalFn,
|
|
393
|
-
props: createPropsAccessor(reactiveProps),
|
|
394
|
-
slots,
|
|
395
|
-
emit: (event, ...args) => {
|
|
396
|
-
const handler = reactiveProps[`on${event[0].toUpperCase() + event.slice(1)}`];
|
|
397
|
-
if (handler && typeof handler === "function") handler(...args);
|
|
398
|
-
},
|
|
399
|
-
parent: parentInstance,
|
|
400
|
-
onMount: (fn) => {
|
|
401
|
-
mountHooks.push(fn);
|
|
402
|
-
},
|
|
403
|
-
onCleanup: (fn) => {
|
|
404
|
-
cleanupHooks.push(fn);
|
|
405
|
-
},
|
|
406
|
-
expose: () => {},
|
|
407
|
-
renderFn: null,
|
|
408
|
-
update: () => {},
|
|
409
|
-
ssr: ssrHelper,
|
|
410
|
-
_serverState: serverState
|
|
411
|
-
};
|
|
412
|
-
const prev = setCurrentInstance(componentCtx);
|
|
413
|
-
let renderFn;
|
|
414
|
-
try {
|
|
415
|
-
renderFn = setup(componentCtx);
|
|
416
|
-
} catch (err) {
|
|
417
|
-
console.error(`Error hydrating component ${componentName}:`, err);
|
|
418
|
-
} finally {
|
|
419
|
-
setCurrentInstance(prev);
|
|
420
|
-
}
|
|
421
|
-
const startDom = anchor || dom;
|
|
422
|
-
let endDom = dom;
|
|
423
|
-
if (renderFn) {
|
|
424
|
-
componentCtx.renderFn = renderFn;
|
|
425
|
-
let isFirstRender = true;
|
|
426
|
-
const componentEffect = effect(() => {
|
|
427
|
-
const prevInstance = setCurrentInstance(componentCtx);
|
|
428
|
-
try {
|
|
429
|
-
const subTreeResult = componentCtx.renderFn();
|
|
430
|
-
if (subTreeResult == null) return;
|
|
431
|
-
const subTree = normalizeSubTree(subTreeResult);
|
|
432
|
-
const prevSubTree = internalVNode._subTree;
|
|
433
|
-
if (isFirstRender) {
|
|
434
|
-
isFirstRender = false;
|
|
435
|
-
endDom = hydrateNode(subTree, dom, parent);
|
|
436
|
-
internalVNode._subTree = subTree;
|
|
437
|
-
} else {
|
|
438
|
-
if (prevSubTree && prevSubTree.dom) {
|
|
439
|
-
const container = prevSubTree.dom.parentNode;
|
|
440
|
-
if (container) {
|
|
441
|
-
container._vnode = prevSubTree;
|
|
442
|
-
render(subTree, container);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
internalVNode._subTree = subTree;
|
|
446
|
-
}
|
|
447
|
-
} finally {
|
|
448
|
-
setCurrentInstance(prevInstance);
|
|
449
|
-
}
|
|
450
|
-
});
|
|
451
|
-
internalVNode._effect = componentEffect;
|
|
452
|
-
componentCtx.update = () => componentEffect();
|
|
453
|
-
}
|
|
454
|
-
vnode.dom = anchor || startDom;
|
|
455
|
-
const mountCtx = { el: parent };
|
|
456
|
-
mountHooks.forEach((hook) => hook(mountCtx));
|
|
457
|
-
vnode.cleanup = () => {
|
|
458
|
-
cleanupHooks.forEach((hook) => hook(mountCtx));
|
|
459
|
-
};
|
|
460
|
-
let result = endDom;
|
|
461
|
-
while (result && result.nodeType === Node.COMMENT_NODE) {
|
|
462
|
-
if (result.data.startsWith("/$c:")) {
|
|
463
|
-
result = result.nextSibling;
|
|
464
|
-
break;
|
|
465
|
-
}
|
|
466
|
-
result = result.nextSibling;
|
|
467
|
-
}
|
|
468
|
-
return result;
|
|
469
|
-
}
|
|
470
|
-
function filterClientDirectives(props) {
|
|
471
|
-
const filtered = {};
|
|
472
|
-
for (const key in props) if (!key.startsWith("client:")) filtered[key] = props[key];
|
|
473
|
-
return filtered;
|
|
474
|
-
}
|
|
475
|
-
/**
|
|
476
|
-
* Fix select element value after hydrating children.
|
|
477
|
-
* This is needed because <select>.value only works after <option> children exist in DOM.
|
|
478
|
-
*/
|
|
479
|
-
function fixSelectValue(dom, props) {
|
|
480
|
-
if (dom.tagName === "SELECT" && "value" in props) {
|
|
481
|
-
const val = props.value;
|
|
482
|
-
if (dom.multiple) {
|
|
483
|
-
const options = dom.options;
|
|
484
|
-
const valArray = Array.isArray(val) ? val : [val];
|
|
485
|
-
for (let i = 0; i < options.length; i++) options[i].selected = valArray.includes(options[i].value);
|
|
486
|
-
} else dom.value = String(val);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
/**
|
|
490
|
-
* Hydrate islands based on their strategies (selective hydration)
|
|
491
|
-
*/
|
|
492
|
-
function hydrateIslands() {
|
|
493
|
-
const dataScript = document.getElementById("__SIGX_ISLANDS__");
|
|
494
|
-
if (!dataScript) return;
|
|
495
|
-
let islandData;
|
|
496
|
-
try {
|
|
497
|
-
islandData = JSON.parse(dataScript.textContent || "{}");
|
|
498
|
-
} catch {
|
|
499
|
-
console.error("Failed to parse island data");
|
|
500
|
-
return;
|
|
501
|
-
}
|
|
502
|
-
for (const [idStr, info] of Object.entries(islandData)) scheduleHydration(parseInt(idStr, 10), info);
|
|
503
|
-
}
|
|
504
|
-
/**
|
|
505
|
-
* Schedule hydration based on strategy
|
|
506
|
-
*/
|
|
507
|
-
function scheduleHydration(id, info) {
|
|
508
|
-
const marker = findIslandMarker(id);
|
|
509
|
-
if (!marker) {
|
|
510
|
-
console.warn(`Island marker not found for id ${id}`);
|
|
511
|
-
return;
|
|
512
|
-
}
|
|
513
|
-
const component = info.componentId ? getComponent(info.componentId) : null;
|
|
514
|
-
if (!component && info.strategy !== "only") {
|
|
515
|
-
console.warn(`Component "${info.componentId}" not registered for hydration`);
|
|
516
|
-
return;
|
|
517
|
-
}
|
|
518
|
-
switch (info.strategy) {
|
|
519
|
-
case "load":
|
|
520
|
-
hydrateIsland(marker, component, info);
|
|
521
|
-
break;
|
|
522
|
-
case "idle":
|
|
523
|
-
if ("requestIdleCallback" in window) requestIdleCallback(() => hydrateIsland(marker, component, info));
|
|
524
|
-
else setTimeout(() => hydrateIsland(marker, component, info), 200);
|
|
525
|
-
break;
|
|
526
|
-
case "visible":
|
|
527
|
-
observeVisibility(marker, () => hydrateIsland(marker, component, info));
|
|
528
|
-
break;
|
|
529
|
-
case "media":
|
|
530
|
-
if (info.media) {
|
|
531
|
-
const mql = window.matchMedia(info.media);
|
|
532
|
-
if (mql.matches) hydrateIsland(marker, component, info);
|
|
533
|
-
else mql.addEventListener("change", function handler(e) {
|
|
534
|
-
if (e.matches) {
|
|
535
|
-
mql.removeEventListener("change", handler);
|
|
536
|
-
hydrateIsland(marker, component, info);
|
|
537
|
-
}
|
|
538
|
-
});
|
|
539
|
-
}
|
|
540
|
-
break;
|
|
541
|
-
case "only":
|
|
542
|
-
if (component) mountClientOnly(marker, component, info);
|
|
543
|
-
break;
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
function findIslandMarker(id) {
|
|
547
|
-
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_COMMENT, null);
|
|
548
|
-
let node;
|
|
549
|
-
while (node = walker.nextNode()) if (node.data === `$c:${id}`) return node;
|
|
550
|
-
return null;
|
|
551
|
-
}
|
|
552
|
-
function observeVisibility(marker, callback) {
|
|
553
|
-
let node = marker.nextSibling;
|
|
554
|
-
while (node && node.nodeType !== Node.ELEMENT_NODE) node = node.nextSibling;
|
|
555
|
-
if (!node) return;
|
|
556
|
-
const observer = new IntersectionObserver((entries) => {
|
|
557
|
-
for (const entry of entries) if (entry.isIntersecting) {
|
|
558
|
-
observer.disconnect();
|
|
559
|
-
callback();
|
|
560
|
-
break;
|
|
561
|
-
}
|
|
562
|
-
});
|
|
563
|
-
observer.observe(node);
|
|
564
|
-
}
|
|
565
|
-
function hydrateIsland(marker, component, info) {
|
|
566
|
-
let container = marker.nextSibling;
|
|
567
|
-
while (container && container.nodeType === Node.COMMENT_NODE) container = container.nextSibling;
|
|
568
|
-
if (!container || container.nodeType !== Node.ELEMENT_NODE) {
|
|
569
|
-
console.warn("No element found for island hydration");
|
|
570
|
-
return;
|
|
571
|
-
}
|
|
572
|
-
const props = info.props || {};
|
|
573
|
-
if (info.state) setPendingServerState(info.state);
|
|
574
|
-
const vnode = {
|
|
575
|
-
type: component,
|
|
576
|
-
props,
|
|
577
|
-
key: null,
|
|
578
|
-
children: [],
|
|
579
|
-
dom: null
|
|
580
|
-
};
|
|
581
|
-
const wrapper = document.createElement("div");
|
|
582
|
-
wrapper.style.display = "contents";
|
|
583
|
-
const parent = container.parentNode;
|
|
584
|
-
parent.insertBefore(wrapper, container);
|
|
585
|
-
parent.removeChild(container);
|
|
586
|
-
render(vnode, wrapper);
|
|
587
|
-
}
|
|
588
|
-
function mountClientOnly(marker, component, info) {
|
|
589
|
-
let placeholder = marker.nextSibling;
|
|
590
|
-
while (placeholder && placeholder.nodeType === Node.COMMENT_NODE) placeholder = placeholder.nextSibling;
|
|
591
|
-
if (!placeholder || !placeholder.hasAttribute?.("data-island")) return;
|
|
592
|
-
const props = info.props || {};
|
|
593
|
-
const container = placeholder;
|
|
594
|
-
container.innerHTML = "";
|
|
595
|
-
render({
|
|
596
|
-
type: component,
|
|
597
|
-
props,
|
|
598
|
-
key: null,
|
|
599
|
-
children: [],
|
|
600
|
-
dom: null
|
|
601
|
-
}, container);
|
|
602
|
-
}
|
|
603
|
-
/**
|
|
604
|
-
* Set up listener for async components streaming in.
|
|
605
|
-
* This is set up at module load time to catch events early.
|
|
606
|
-
*/
|
|
607
|
-
let _asyncListenerSetup = false;
|
|
608
|
-
function ensureAsyncHydrationListener() {
|
|
609
|
-
if (_asyncListenerSetup) return;
|
|
610
|
-
_asyncListenerSetup = true;
|
|
611
|
-
document.addEventListener("sigx:async-ready", (event) => {
|
|
612
|
-
const { id, state } = event.detail || {};
|
|
613
|
-
console.log(`[Hydrate] Async component ${id} ready, hydrating...`);
|
|
614
|
-
invalidateIslandCache();
|
|
615
|
-
const placeholder = document.querySelector(`[data-async-placeholder="${id}"]`);
|
|
616
|
-
if (!placeholder) {
|
|
617
|
-
console.warn(`[Hydrate] Could not find placeholder for async component ${id}`);
|
|
618
|
-
return;
|
|
619
|
-
}
|
|
620
|
-
const info = getIslandData()[String(id)];
|
|
621
|
-
if (!info) {
|
|
622
|
-
console.warn(`[Hydrate] No island data for async component ${id}`);
|
|
623
|
-
return;
|
|
624
|
-
}
|
|
625
|
-
hydrateAsyncComponent(placeholder, info);
|
|
626
|
-
});
|
|
627
|
-
}
|
|
628
|
-
if (typeof document !== "undefined") ensureAsyncHydrationListener();
|
|
629
|
-
/**
|
|
630
|
-
* Hydrate an async component that just streamed in.
|
|
631
|
-
* The DOM has already been replaced with server-rendered content by $SIGX_REPLACE.
|
|
632
|
-
* Since the streamed content doesn't include component markers, we mount fresh
|
|
633
|
-
* with the server state restored via the context extension.
|
|
634
|
-
*/
|
|
635
|
-
function hydrateAsyncComponent(container, info) {
|
|
636
|
-
if (!info.componentId) {
|
|
637
|
-
console.error(`[Hydrate] No componentId in island info`);
|
|
638
|
-
return;
|
|
639
|
-
}
|
|
640
|
-
const component = getComponent(info.componentId);
|
|
641
|
-
if (!component) {
|
|
642
|
-
console.error(`[Hydrate] Component "${info.componentId}" not registered`);
|
|
643
|
-
return;
|
|
644
|
-
}
|
|
645
|
-
const props = info.props || {};
|
|
646
|
-
const serverState = info.state;
|
|
647
|
-
container.innerHTML = "";
|
|
648
|
-
if (serverState) setPendingServerState(serverState);
|
|
649
|
-
render({
|
|
650
|
-
type: component,
|
|
651
|
-
props,
|
|
652
|
-
key: null,
|
|
653
|
-
children: [],
|
|
654
|
-
dom: null
|
|
655
|
-
}, container);
|
|
656
|
-
console.log(`[Hydrate] Async component "${info.componentId}" mounted with server state`);
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
//#endregion
|
|
660
|
-
export { HydrationRegistry, hydrate, hydrateIslands, registerComponent };
|
|
661
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import { i as registerComponent, n as hydrateIslands, r as HydrationRegistry, t as ssrClientPlugin } from "../client-DiLwBAD-.js";
|
|
2
|
+
export { HydrationRegistry, hydrateIslands, registerComponent, ssrClientPlugin };
|