solid-js 2.0.0-experimental.14 → 2.0.0-experimental.15
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/dev.cjs +429 -41
- package/dist/dev.js +427 -27
- package/dist/server.cjs +335 -43
- package/dist/server.js +336 -45
- package/dist/solid.cjs +415 -40
- package/dist/solid.js +413 -26
- package/package.json +2 -2
- package/types/client/component.d.ts +1 -1
- package/types/client/hydration.d.ts +34 -2
- package/types/server/component.d.ts +6 -2
- package/types/server/index.d.ts +2 -2
- package/types/server/shared.d.ts +22 -1
- package/types/server/signals.d.ts +8 -2
package/dist/dev.cjs
CHANGED
|
@@ -39,8 +39,15 @@ function devComponent(Comp, props) {
|
|
|
39
39
|
Object.assign(Comp, {
|
|
40
40
|
[$DEVCOMP]: true
|
|
41
41
|
});
|
|
42
|
-
|
|
42
|
+
signals.setStrictRead(`<${Comp.name || "Anonymous"}>`);
|
|
43
|
+
try {
|
|
44
|
+
return Comp(props);
|
|
45
|
+
} finally {
|
|
46
|
+
signals.setStrictRead(false);
|
|
47
|
+
}
|
|
43
48
|
});
|
|
49
|
+
}, {
|
|
50
|
+
transparent: true
|
|
44
51
|
});
|
|
45
52
|
}
|
|
46
53
|
function registerGraph(value) {
|
|
@@ -60,8 +67,44 @@ const sharedConfig = {
|
|
|
60
67
|
return signals.getNextChildId(o);
|
|
61
68
|
}
|
|
62
69
|
};
|
|
70
|
+
let _hydrationEndCallbacks = null;
|
|
71
|
+
let _pendingBoundaries = 0;
|
|
72
|
+
let _hydrationDone = false;
|
|
73
|
+
let _snapshotRootOwner = null;
|
|
74
|
+
function markTopLevelSnapshotScope() {
|
|
75
|
+
if (_snapshotRootOwner) return;
|
|
76
|
+
let owner = signals.getOwner();
|
|
77
|
+
if (!owner) return;
|
|
78
|
+
while (owner._parent) owner = owner._parent;
|
|
79
|
+
signals.markSnapshotScope(owner);
|
|
80
|
+
_snapshotRootOwner = owner;
|
|
81
|
+
}
|
|
82
|
+
function drainHydrationCallbacks() {
|
|
83
|
+
if (_hydrationDone) return;
|
|
84
|
+
_hydrationDone = true;
|
|
85
|
+
_doneValue = true;
|
|
86
|
+
signals.clearSnapshots();
|
|
87
|
+
signals.setSnapshotCapture(false);
|
|
88
|
+
signals.flush();
|
|
89
|
+
const cbs = _hydrationEndCallbacks;
|
|
90
|
+
_hydrationEndCallbacks = null;
|
|
91
|
+
if (cbs) for (const cb of cbs) cb();
|
|
92
|
+
setTimeout(() => {
|
|
93
|
+
if (globalThis._$HY) globalThis._$HY.done = true;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function checkHydrationComplete() {
|
|
97
|
+
if (_pendingBoundaries === 0) drainHydrationCallbacks();
|
|
98
|
+
}
|
|
99
|
+
let _hydratingValue = false;
|
|
100
|
+
let _doneValue = false;
|
|
63
101
|
let _createMemo;
|
|
64
102
|
let _createSignal;
|
|
103
|
+
let _createErrorBoundary;
|
|
104
|
+
let _createOptimistic;
|
|
105
|
+
let _createProjection;
|
|
106
|
+
let _createStore;
|
|
107
|
+
let _createOptimisticStore;
|
|
65
108
|
class MockPromise {
|
|
66
109
|
static all() {
|
|
67
110
|
return new MockPromise();
|
|
@@ -97,14 +140,110 @@ function subFetch(fn, prev) {
|
|
|
97
140
|
try {
|
|
98
141
|
window.fetch = () => new MockPromise();
|
|
99
142
|
Promise = MockPromise;
|
|
100
|
-
|
|
143
|
+
const result = fn(prev);
|
|
144
|
+
if (result && typeof result[Symbol.asyncIterator] === "function") {
|
|
145
|
+
result[Symbol.asyncIterator]().next();
|
|
146
|
+
}
|
|
147
|
+
return result;
|
|
101
148
|
} finally {
|
|
102
149
|
window.fetch = ogFetch;
|
|
103
150
|
Promise = ogPromise;
|
|
104
151
|
}
|
|
105
152
|
}
|
|
153
|
+
function consumeFirstSync(ai) {
|
|
154
|
+
const iter = ai[Symbol.asyncIterator]();
|
|
155
|
+
const r = iter.next();
|
|
156
|
+
const value = !(r instanceof Promise) && !r.done ? r.value : undefined;
|
|
157
|
+
return [value, iter];
|
|
158
|
+
}
|
|
159
|
+
function applyPatches(target, patches) {
|
|
160
|
+
for (const patch of patches) {
|
|
161
|
+
const path = patch[0];
|
|
162
|
+
let current = target;
|
|
163
|
+
for (let i = 0; i < path.length - 1; i++) current = current[path[i]];
|
|
164
|
+
const key = path[path.length - 1];
|
|
165
|
+
if (patch.length === 1) {
|
|
166
|
+
Array.isArray(current) ? current.splice(key, 1) : delete current[key];
|
|
167
|
+
} else if (patch.length === 3) {
|
|
168
|
+
current.splice(key, 0, patch[1]);
|
|
169
|
+
} else {
|
|
170
|
+
current[key] = patch[1];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function scheduleIteratorConsumption(iter, apply) {
|
|
175
|
+
const consume = () => {
|
|
176
|
+
while (true) {
|
|
177
|
+
const n = iter.next();
|
|
178
|
+
if (n instanceof Promise) {
|
|
179
|
+
n.then(r => {
|
|
180
|
+
if (r.done) return;
|
|
181
|
+
apply(r.value);
|
|
182
|
+
consume();
|
|
183
|
+
});
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (n.done) break;
|
|
187
|
+
apply(n.value);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
consume();
|
|
191
|
+
}
|
|
192
|
+
function isAsyncIterable(v) {
|
|
193
|
+
return v != null && typeof v[Symbol.asyncIterator] === "function";
|
|
194
|
+
}
|
|
195
|
+
function hydrateSignalFromAsyncIterable(coreFn, compute, value, options) {
|
|
196
|
+
const parent = signals.getOwner();
|
|
197
|
+
const expectedId = signals.peekNextChildId(parent);
|
|
198
|
+
if (!sharedConfig.has(expectedId)) return null;
|
|
199
|
+
const initP = sharedConfig.load(expectedId);
|
|
200
|
+
if (!isAsyncIterable(initP)) return null;
|
|
201
|
+
const [firstValue, iter] = consumeFirstSync(initP);
|
|
202
|
+
const [get, set] = signals.createSignal(firstValue);
|
|
203
|
+
const result = coreFn(() => get(), firstValue, options);
|
|
204
|
+
scheduleIteratorConsumption(iter, v => {
|
|
205
|
+
set(() => v);
|
|
206
|
+
signals.flush();
|
|
207
|
+
});
|
|
208
|
+
return result;
|
|
209
|
+
}
|
|
210
|
+
function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
|
|
211
|
+
const parent = signals.getOwner();
|
|
212
|
+
const expectedId = signals.peekNextChildId(parent);
|
|
213
|
+
if (!sharedConfig.has(expectedId)) return null;
|
|
214
|
+
const initP = sharedConfig.load(expectedId);
|
|
215
|
+
if (!isAsyncIterable(initP)) return null;
|
|
216
|
+
const [firstState, iter] = consumeFirstSync(initP);
|
|
217
|
+
const [store, setStore] = coreFn(() => {}, firstState ?? initialValue, options);
|
|
218
|
+
scheduleIteratorConsumption(iter, patches => {
|
|
219
|
+
setStore(d => {
|
|
220
|
+
applyPatches(d, patches);
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
return [store, setStore];
|
|
224
|
+
}
|
|
106
225
|
function hydratedCreateMemo(compute, value, options) {
|
|
107
226
|
if (!sharedConfig.hydrating) return signals.createMemo(compute, value, options);
|
|
227
|
+
markTopLevelSnapshotScope();
|
|
228
|
+
const ssrSource = options?.ssrSource;
|
|
229
|
+
if (ssrSource === "client") {
|
|
230
|
+
const [hydrated, setHydrated] = signals.createSignal(false);
|
|
231
|
+
const memo = signals.createMemo(prev => {
|
|
232
|
+
if (!hydrated()) return prev ?? value;
|
|
233
|
+
return compute(prev);
|
|
234
|
+
}, value, options);
|
|
235
|
+
setHydrated(true);
|
|
236
|
+
return memo;
|
|
237
|
+
}
|
|
238
|
+
if (ssrSource === "initial") {
|
|
239
|
+
return signals.createMemo(prev => {
|
|
240
|
+
if (!sharedConfig.hydrating) return compute(prev);
|
|
241
|
+
subFetch(compute, prev);
|
|
242
|
+
return prev ?? value;
|
|
243
|
+
}, value, options);
|
|
244
|
+
}
|
|
245
|
+
const aiResult = hydrateSignalFromAsyncIterable(signals.createMemo, compute, value, options);
|
|
246
|
+
if (aiResult !== null) return aiResult;
|
|
108
247
|
return signals.createMemo(prev => {
|
|
109
248
|
const o = signals.getOwner();
|
|
110
249
|
if (!sharedConfig.hydrating) return compute(prev);
|
|
@@ -116,6 +255,26 @@ function hydratedCreateMemo(compute, value, options) {
|
|
|
116
255
|
}
|
|
117
256
|
function hydratedCreateSignal(fn, second, third) {
|
|
118
257
|
if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createSignal(fn, second, third);
|
|
258
|
+
markTopLevelSnapshotScope();
|
|
259
|
+
const ssrSource = third?.ssrSource;
|
|
260
|
+
if (ssrSource === "client") {
|
|
261
|
+
const [hydrated, setHydrated] = signals.createSignal(false);
|
|
262
|
+
const sig = signals.createSignal(prev => {
|
|
263
|
+
if (!hydrated()) return prev ?? second;
|
|
264
|
+
return fn(prev);
|
|
265
|
+
}, second, third);
|
|
266
|
+
setHydrated(true);
|
|
267
|
+
return sig;
|
|
268
|
+
}
|
|
269
|
+
if (ssrSource === "initial") {
|
|
270
|
+
return signals.createSignal(prev => {
|
|
271
|
+
if (!sharedConfig.hydrating) return fn(prev);
|
|
272
|
+
subFetch(fn, prev);
|
|
273
|
+
return prev ?? second;
|
|
274
|
+
}, second, third);
|
|
275
|
+
}
|
|
276
|
+
const aiResult = hydrateSignalFromAsyncIterable(signals.createSignal, fn, second, third);
|
|
277
|
+
if (aiResult !== null) return aiResult;
|
|
119
278
|
return signals.createSignal(prev => {
|
|
120
279
|
if (!sharedConfig.hydrating) return fn(prev);
|
|
121
280
|
const o = signals.getOwner();
|
|
@@ -125,17 +284,215 @@ function hydratedCreateSignal(fn, second, third) {
|
|
|
125
284
|
return init != null ? (subFetch(fn, prev), init) : fn(prev);
|
|
126
285
|
}, second, third);
|
|
127
286
|
}
|
|
287
|
+
function hydratedCreateErrorBoundary(fn, fallback) {
|
|
288
|
+
if (!sharedConfig.hydrating) return signals.createErrorBoundary(fn, fallback);
|
|
289
|
+
markTopLevelSnapshotScope();
|
|
290
|
+
const parent = signals.getOwner();
|
|
291
|
+
const expectedId = signals.peekNextChildId(parent);
|
|
292
|
+
if (sharedConfig.has(expectedId)) {
|
|
293
|
+
const err = sharedConfig.load(expectedId);
|
|
294
|
+
if (err !== undefined) {
|
|
295
|
+
let hydrated = true;
|
|
296
|
+
return signals.createErrorBoundary(() => {
|
|
297
|
+
if (hydrated) {
|
|
298
|
+
hydrated = false;
|
|
299
|
+
throw err;
|
|
300
|
+
}
|
|
301
|
+
return fn();
|
|
302
|
+
}, fallback);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return signals.createErrorBoundary(fn, fallback);
|
|
306
|
+
}
|
|
307
|
+
function hydratedCreateOptimistic(fn, second, third) {
|
|
308
|
+
if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createOptimistic(fn, second, third);
|
|
309
|
+
markTopLevelSnapshotScope();
|
|
310
|
+
const ssrSource = third?.ssrSource;
|
|
311
|
+
if (ssrSource === "client") {
|
|
312
|
+
const [hydrated, setHydrated] = signals.createSignal(false);
|
|
313
|
+
const sig = signals.createOptimistic(prev => {
|
|
314
|
+
if (!hydrated()) return prev ?? second;
|
|
315
|
+
return fn(prev);
|
|
316
|
+
}, second, third);
|
|
317
|
+
setHydrated(true);
|
|
318
|
+
return sig;
|
|
319
|
+
}
|
|
320
|
+
if (ssrSource === "initial") {
|
|
321
|
+
return signals.createOptimistic(prev => {
|
|
322
|
+
if (!sharedConfig.hydrating) return fn(prev);
|
|
323
|
+
subFetch(fn, prev);
|
|
324
|
+
return prev ?? second;
|
|
325
|
+
}, second, third);
|
|
326
|
+
}
|
|
327
|
+
const aiResult = hydrateSignalFromAsyncIterable(signals.createOptimistic, fn, second, third);
|
|
328
|
+
if (aiResult !== null) return aiResult;
|
|
329
|
+
return signals.createOptimistic(prev => {
|
|
330
|
+
const o = signals.getOwner();
|
|
331
|
+
if (!sharedConfig.hydrating) return fn(prev);
|
|
332
|
+
let initP;
|
|
333
|
+
if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
|
|
334
|
+
const init = initP?.v ?? initP;
|
|
335
|
+
return init != null ? (subFetch(fn, prev), init) : fn(prev);
|
|
336
|
+
}, second, third);
|
|
337
|
+
}
|
|
338
|
+
function wrapStoreFn(fn, ssrSource) {
|
|
339
|
+
if (ssrSource === "initial") {
|
|
340
|
+
return draft => {
|
|
341
|
+
if (!sharedConfig.hydrating) return fn(draft);
|
|
342
|
+
subFetch(fn, draft);
|
|
343
|
+
return undefined;
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
return draft => {
|
|
347
|
+
const o = signals.getOwner();
|
|
348
|
+
if (!sharedConfig.hydrating) return fn(draft);
|
|
349
|
+
let initP;
|
|
350
|
+
if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
|
|
351
|
+
const init = initP?.v ?? initP;
|
|
352
|
+
return init != null ? (subFetch(fn, draft), init) : fn(draft);
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
function hydratedCreateStore(first, second, third) {
|
|
356
|
+
if (typeof first !== "function" || !sharedConfig.hydrating) return signals.createStore(first, second, third);
|
|
357
|
+
markTopLevelSnapshotScope();
|
|
358
|
+
const ssrSource = third?.ssrSource;
|
|
359
|
+
if (ssrSource === "client" || ssrSource === "initial") {
|
|
360
|
+
return signals.createStore(second ?? {}, undefined, third);
|
|
361
|
+
}
|
|
362
|
+
const aiResult = hydrateStoreFromAsyncIterable(signals.createStore, second ?? {}, third);
|
|
363
|
+
if (aiResult !== null) return aiResult;
|
|
364
|
+
return signals.createStore(wrapStoreFn(first, ssrSource), second, third);
|
|
365
|
+
}
|
|
366
|
+
function hydratedCreateOptimisticStore(first, second, third) {
|
|
367
|
+
if (typeof first !== "function" || !sharedConfig.hydrating) return signals.createOptimisticStore(first, second, third);
|
|
368
|
+
markTopLevelSnapshotScope();
|
|
369
|
+
const ssrSource = third?.ssrSource;
|
|
370
|
+
if (ssrSource === "client" || ssrSource === "initial") {
|
|
371
|
+
return signals.createOptimisticStore(second ?? {}, undefined, third);
|
|
372
|
+
}
|
|
373
|
+
const aiResult = hydrateStoreFromAsyncIterable(signals.createOptimisticStore, second ?? {}, third);
|
|
374
|
+
if (aiResult !== null) return aiResult;
|
|
375
|
+
return signals.createOptimisticStore(wrapStoreFn(first, ssrSource), second, third);
|
|
376
|
+
}
|
|
377
|
+
function hydratedCreateProjection(fn, initialValue, options) {
|
|
378
|
+
if (!sharedConfig.hydrating) return signals.createProjection(fn, initialValue, options);
|
|
379
|
+
markTopLevelSnapshotScope();
|
|
380
|
+
const ssrSource = options?.ssrSource;
|
|
381
|
+
if (ssrSource === "client" || ssrSource === "initial") {
|
|
382
|
+
return signals.createProjection(draft => draft, initialValue, options);
|
|
383
|
+
}
|
|
384
|
+
const aiResult = hydrateStoreFromAsyncIterable(signals.createStore, initialValue, options);
|
|
385
|
+
if (aiResult !== null) return aiResult[0];
|
|
386
|
+
return signals.createProjection(wrapStoreFn(fn, ssrSource), initialValue, options);
|
|
387
|
+
}
|
|
128
388
|
function enableHydration() {
|
|
129
389
|
_createMemo = hydratedCreateMemo;
|
|
130
390
|
_createSignal = hydratedCreateSignal;
|
|
391
|
+
_createErrorBoundary = hydratedCreateErrorBoundary;
|
|
392
|
+
_createOptimistic = hydratedCreateOptimistic;
|
|
393
|
+
_createProjection = hydratedCreateProjection;
|
|
394
|
+
_createStore = hydratedCreateStore;
|
|
395
|
+
_createOptimisticStore = hydratedCreateOptimisticStore;
|
|
396
|
+
_hydratingValue = sharedConfig.hydrating;
|
|
397
|
+
_doneValue = sharedConfig.done;
|
|
398
|
+
Object.defineProperty(sharedConfig, "hydrating", {
|
|
399
|
+
get() {
|
|
400
|
+
return _hydratingValue;
|
|
401
|
+
},
|
|
402
|
+
set(v) {
|
|
403
|
+
const was = _hydratingValue;
|
|
404
|
+
_hydratingValue = v;
|
|
405
|
+
if (!was && v) {
|
|
406
|
+
_hydrationDone = false;
|
|
407
|
+
_doneValue = false;
|
|
408
|
+
_pendingBoundaries = 0;
|
|
409
|
+
signals.setSnapshotCapture(true);
|
|
410
|
+
_snapshotRootOwner = null;
|
|
411
|
+
} else if (was && !v) {
|
|
412
|
+
if (_snapshotRootOwner) {
|
|
413
|
+
signals.releaseSnapshotScope(_snapshotRootOwner);
|
|
414
|
+
_snapshotRootOwner = null;
|
|
415
|
+
}
|
|
416
|
+
checkHydrationComplete();
|
|
417
|
+
}
|
|
418
|
+
},
|
|
419
|
+
configurable: true,
|
|
420
|
+
enumerable: true
|
|
421
|
+
});
|
|
422
|
+
Object.defineProperty(sharedConfig, "done", {
|
|
423
|
+
get() {
|
|
424
|
+
return _doneValue;
|
|
425
|
+
},
|
|
426
|
+
set(v) {
|
|
427
|
+
_doneValue = v;
|
|
428
|
+
if (v) drainHydrationCallbacks();
|
|
429
|
+
},
|
|
430
|
+
configurable: true,
|
|
431
|
+
enumerable: true
|
|
432
|
+
});
|
|
131
433
|
}
|
|
132
434
|
const createMemo = (...args) => (_createMemo || signals.createMemo)(...args);
|
|
133
435
|
const createSignal = (...args) => (_createSignal || signals.createSignal)(...args);
|
|
436
|
+
const createErrorBoundary = (...args) => (_createErrorBoundary || signals.createErrorBoundary)(...args);
|
|
437
|
+
const createOptimistic = (...args) => (_createOptimistic || signals.createOptimistic)(...args);
|
|
438
|
+
const createProjection = (...args) => (_createProjection || signals.createProjection)(...args);
|
|
439
|
+
const createStore = (...args) => (_createStore || signals.createStore)(...args);
|
|
440
|
+
const createOptimisticStore = (...args) => (_createOptimisticStore || signals.createOptimisticStore)(...args);
|
|
441
|
+
function loadModuleAssets(mapping) {
|
|
442
|
+
const hy = globalThis._$HY;
|
|
443
|
+
if (!hy) return;
|
|
444
|
+
if (!hy.modules) hy.modules = {};
|
|
445
|
+
if (!hy.loading) hy.loading = {};
|
|
446
|
+
const pending = [];
|
|
447
|
+
for (const moduleUrl in mapping) {
|
|
448
|
+
if (hy.modules[moduleUrl]) continue;
|
|
449
|
+
const entryUrl = mapping[moduleUrl];
|
|
450
|
+
if (!hy.loading[moduleUrl]) {
|
|
451
|
+
hy.loading[moduleUrl] = import(entryUrl).then(mod => {
|
|
452
|
+
hy.modules[moduleUrl] = mod;
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
pending.push(hy.loading[moduleUrl]);
|
|
456
|
+
}
|
|
457
|
+
return pending.length ? Promise.all(pending).then(() => {}) : undefined;
|
|
458
|
+
}
|
|
459
|
+
function createBoundaryTrigger() {
|
|
460
|
+
signals.setSnapshotCapture(false);
|
|
461
|
+
const [s, set] = signals.createSignal(undefined, {
|
|
462
|
+
equals: false
|
|
463
|
+
});
|
|
464
|
+
s();
|
|
465
|
+
signals.setSnapshotCapture(true);
|
|
466
|
+
return set;
|
|
467
|
+
}
|
|
468
|
+
function resumeBoundaryHydration(o, id, set) {
|
|
469
|
+
_pendingBoundaries--;
|
|
470
|
+
if (signals.isDisposed(o)) {
|
|
471
|
+
checkHydrationComplete();
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
sharedConfig.gather(id);
|
|
475
|
+
_hydratingValue = true;
|
|
476
|
+
signals.markSnapshotScope(o);
|
|
477
|
+
_snapshotRootOwner = o;
|
|
478
|
+
set();
|
|
479
|
+
signals.flush();
|
|
480
|
+
_snapshotRootOwner = null;
|
|
481
|
+
_hydratingValue = false;
|
|
482
|
+
signals.releaseSnapshotScope(o);
|
|
483
|
+
signals.flush();
|
|
484
|
+
checkHydrationComplete();
|
|
485
|
+
}
|
|
134
486
|
function Loading(props) {
|
|
135
487
|
if (!sharedConfig.hydrating) return signals.createLoadBoundary(() => props.children, () => props.fallback);
|
|
136
488
|
return signals.createMemo(() => {
|
|
137
489
|
const o = signals.getOwner();
|
|
138
490
|
const id = o.id;
|
|
491
|
+
let assetPromise;
|
|
492
|
+
if (sharedConfig.hydrating && sharedConfig.has(id + "_assets")) {
|
|
493
|
+
const mapping = sharedConfig.load(id + "_assets");
|
|
494
|
+
if (mapping && typeof mapping === "object") assetPromise = loadModuleAssets(mapping);
|
|
495
|
+
}
|
|
139
496
|
if (sharedConfig.hydrating && sharedConfig.has(id)) {
|
|
140
497
|
let ref = sharedConfig.load(id);
|
|
141
498
|
let p;
|
|
@@ -143,24 +500,38 @@ function Loading(props) {
|
|
|
143
500
|
if (typeof ref !== "object" || ref.s !== 1) p = ref;else sharedConfig.gather(id);
|
|
144
501
|
}
|
|
145
502
|
if (p) {
|
|
146
|
-
|
|
147
|
-
|
|
503
|
+
_pendingBoundaries++;
|
|
504
|
+
signals.onCleanup(() => {
|
|
505
|
+
if (!signals.isDisposed(o)) return;
|
|
506
|
+
sharedConfig.cleanupFragment?.(id);
|
|
148
507
|
});
|
|
149
|
-
|
|
508
|
+
const set = createBoundaryTrigger();
|
|
150
509
|
if (p !== "$$f") {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
510
|
+
const waitFor = assetPromise ? Promise.all([p, assetPromise]) : p;
|
|
511
|
+
waitFor.then(() => resumeBoundaryHydration(o, id, set), err => {
|
|
512
|
+
_pendingBoundaries--;
|
|
513
|
+
checkHydrationComplete();
|
|
514
|
+
signals.runWithOwner(o, () => {
|
|
515
|
+
throw err;
|
|
516
|
+
});
|
|
517
|
+
});
|
|
518
|
+
} else {
|
|
519
|
+
const afterAssets = () => {
|
|
520
|
+
_pendingBoundaries--;
|
|
154
521
|
set();
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}));
|
|
160
|
-
} else queueMicrotask(set);
|
|
522
|
+
checkHydrationComplete();
|
|
523
|
+
};
|
|
524
|
+
if (assetPromise) assetPromise.then(() => queueMicrotask(afterAssets));else queueMicrotask(afterAssets);
|
|
525
|
+
}
|
|
161
526
|
return props.fallback;
|
|
162
527
|
}
|
|
163
528
|
}
|
|
529
|
+
if (assetPromise) {
|
|
530
|
+
_pendingBoundaries++;
|
|
531
|
+
const set = createBoundaryTrigger();
|
|
532
|
+
assetPromise.then(() => resumeBoundaryHydration(o, id, set));
|
|
533
|
+
return undefined;
|
|
534
|
+
}
|
|
164
535
|
return signals.createLoadBoundary(() => props.children, () => props.fallback);
|
|
165
536
|
});
|
|
166
537
|
}
|
|
@@ -168,11 +539,24 @@ function Loading(props) {
|
|
|
168
539
|
function createComponent(Comp, props) {
|
|
169
540
|
return devComponent(Comp, props || {});
|
|
170
541
|
}
|
|
171
|
-
function lazy(fn) {
|
|
542
|
+
function lazy(fn, moduleUrl) {
|
|
172
543
|
let comp;
|
|
173
544
|
let p;
|
|
174
545
|
const wrap = props => {
|
|
175
|
-
|
|
546
|
+
if (sharedConfig.hydrating && moduleUrl) {
|
|
547
|
+
const cached = globalThis._$HY?.modules?.[moduleUrl];
|
|
548
|
+
if (!cached) {
|
|
549
|
+
throw new Error(`lazy() module "${moduleUrl}" was not preloaded before hydration. ` + "Ensure it is inside a Loading boundary.");
|
|
550
|
+
}
|
|
551
|
+
comp = () => cached.default;
|
|
552
|
+
}
|
|
553
|
+
if (!comp) {
|
|
554
|
+
p || (p = fn());
|
|
555
|
+
p.then(mod => {
|
|
556
|
+
comp = () => mod.default;
|
|
557
|
+
});
|
|
558
|
+
comp = signals.createMemo(() => p.then(mod => mod.default));
|
|
559
|
+
}
|
|
176
560
|
let Comp;
|
|
177
561
|
return signals.createMemo(() => (Comp = comp()) ? signals.untrack(() => {
|
|
178
562
|
Object.assign(Comp, {
|
|
@@ -197,6 +581,7 @@ function For(props) {
|
|
|
197
581
|
} : {
|
|
198
582
|
keyed: props.keyed
|
|
199
583
|
};
|
|
584
|
+
options.name = "<For>";
|
|
200
585
|
return signals.mapArray(() => props.each, props.children, options);
|
|
201
586
|
}
|
|
202
587
|
function Repeat(props) {
|
|
@@ -204,6 +589,7 @@ function Repeat(props) {
|
|
|
204
589
|
fallback: () => props.fallback
|
|
205
590
|
} : {};
|
|
206
591
|
options.from = () => props.from;
|
|
592
|
+
options.name = "<Repeat>";
|
|
207
593
|
return signals.repeat(() => props.count, index => typeof props.children === "function" ? props.children(index) : props.children, options);
|
|
208
594
|
}
|
|
209
595
|
function Show(props) {
|
|
@@ -220,10 +606,17 @@ function Show(props) {
|
|
|
220
606
|
if (c) {
|
|
221
607
|
const child = props.children;
|
|
222
608
|
const fn = typeof child === "function" && child.length > 0;
|
|
223
|
-
return fn ? signals.untrack(() =>
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
609
|
+
return fn ? signals.untrack(() => {
|
|
610
|
+
signals.setStrictRead("<Show>");
|
|
611
|
+
try {
|
|
612
|
+
return child(() => {
|
|
613
|
+
if (!signals.untrack(condition)) throw narrowedError("Show");
|
|
614
|
+
return conditionValue();
|
|
615
|
+
});
|
|
616
|
+
} finally {
|
|
617
|
+
signals.setStrictRead(false);
|
|
618
|
+
}
|
|
619
|
+
}) : child;
|
|
227
620
|
}
|
|
228
621
|
return props.fallback;
|
|
229
622
|
}, undefined, {
|
|
@@ -256,10 +649,17 @@ function Switch(props) {
|
|
|
256
649
|
const [index, conditionValue, mp] = sel;
|
|
257
650
|
const child = mp.children;
|
|
258
651
|
const fn = typeof child === "function" && child.length > 0;
|
|
259
|
-
return fn ? signals.untrack(() =>
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
652
|
+
return fn ? signals.untrack(() => {
|
|
653
|
+
signals.setStrictRead("<Match>");
|
|
654
|
+
try {
|
|
655
|
+
return child(() => {
|
|
656
|
+
if (signals.untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
|
|
657
|
+
return conditionValue();
|
|
658
|
+
});
|
|
659
|
+
} finally {
|
|
660
|
+
signals.setStrictRead(false);
|
|
661
|
+
}
|
|
662
|
+
}) : child;
|
|
263
663
|
}, undefined, {
|
|
264
664
|
name: "eval conditions"
|
|
265
665
|
} );
|
|
@@ -268,7 +668,7 @@ function Match(props) {
|
|
|
268
668
|
return props;
|
|
269
669
|
}
|
|
270
670
|
function Errored(props) {
|
|
271
|
-
return
|
|
671
|
+
return createErrorBoundary(() => props.children, (err, reset) => {
|
|
272
672
|
const f = props.fallback;
|
|
273
673
|
if ((typeof f !== "function" || f.length == 0)) console.error(err);
|
|
274
674
|
return typeof f === "function" && f.length ? f(err, reset) : f;
|
|
@@ -306,18 +706,6 @@ Object.defineProperty(exports, "createEffect", {
|
|
|
306
706
|
enumerable: true,
|
|
307
707
|
get: function () { return signals.createEffect; }
|
|
308
708
|
});
|
|
309
|
-
Object.defineProperty(exports, "createOptimistic", {
|
|
310
|
-
enumerable: true,
|
|
311
|
-
get: function () { return signals.createOptimistic; }
|
|
312
|
-
});
|
|
313
|
-
Object.defineProperty(exports, "createOptimisticStore", {
|
|
314
|
-
enumerable: true,
|
|
315
|
-
get: function () { return signals.createOptimisticStore; }
|
|
316
|
-
});
|
|
317
|
-
Object.defineProperty(exports, "createProjection", {
|
|
318
|
-
enumerable: true,
|
|
319
|
-
get: function () { return signals.createProjection; }
|
|
320
|
-
});
|
|
321
709
|
Object.defineProperty(exports, "createReaction", {
|
|
322
710
|
enumerable: true,
|
|
323
711
|
get: function () { return signals.createReaction; }
|
|
@@ -330,10 +718,6 @@ Object.defineProperty(exports, "createRoot", {
|
|
|
330
718
|
enumerable: true,
|
|
331
719
|
get: function () { return signals.createRoot; }
|
|
332
720
|
});
|
|
333
|
-
Object.defineProperty(exports, "createStore", {
|
|
334
|
-
enumerable: true,
|
|
335
|
-
get: function () { return signals.createStore; }
|
|
336
|
-
});
|
|
337
721
|
Object.defineProperty(exports, "createTrackedEffect", {
|
|
338
722
|
enumerable: true,
|
|
339
723
|
get: function () { return signals.createTrackedEffect; }
|
|
@@ -439,7 +823,11 @@ exports.children = children;
|
|
|
439
823
|
exports.createComponent = createComponent;
|
|
440
824
|
exports.createContext = createContext;
|
|
441
825
|
exports.createMemo = createMemo;
|
|
826
|
+
exports.createOptimistic = createOptimistic;
|
|
827
|
+
exports.createOptimisticStore = createOptimisticStore;
|
|
828
|
+
exports.createProjection = createProjection;
|
|
442
829
|
exports.createSignal = createSignal;
|
|
830
|
+
exports.createStore = createStore;
|
|
443
831
|
exports.createUniqueId = createUniqueId;
|
|
444
832
|
exports.enableHydration = enableHydration;
|
|
445
833
|
exports.lazy = lazy;
|