solid-js 2.0.0-experimental.13 → 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 +506 -78
- package/dist/dev.js +509 -64
- package/dist/server.cjs +827 -0
- package/dist/server.js +732 -0
- package/dist/solid.cjs +492 -77
- package/dist/solid.js +495 -63
- package/package.json +4 -4
- package/types/client/component.d.ts +1 -2
- package/types/client/flow.d.ts +1 -5
- package/types/client/hydration.d.ts +36 -0
- package/types/index.d.ts +3 -4
- package/types/server/component.d.ts +66 -0
- package/types/server/core.d.ts +43 -0
- package/types/server/flow.d.ts +60 -0
- package/types/server/hydration.d.ts +21 -0
- package/types/server/index.d.ts +12 -1
- package/types/server/shared.d.ts +45 -0
- package/types/server/signals.d.ts +60 -0
- package/types/utilities.d.ts +0 -36
package/dist/solid.cjs
CHANGED
|
@@ -28,27 +28,6 @@ function children(fn) {
|
|
|
28
28
|
return memo;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
function tryCatch(fn) {
|
|
32
|
-
try {
|
|
33
|
-
const v = fn();
|
|
34
|
-
if (v instanceof Promise) {
|
|
35
|
-
return v.then(v => [undefined, v], e => {
|
|
36
|
-
if (e instanceof signals.NotReadyError) throw e;
|
|
37
|
-
return [e];
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
return [undefined, v];
|
|
41
|
-
} catch (e) {
|
|
42
|
-
if (e instanceof signals.NotReadyError) throw e;
|
|
43
|
-
return [e];
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function reducer(source, reducerFn) {
|
|
47
|
-
return [source[0], action => {
|
|
48
|
-
source[1](s => reducerFn(s, action));
|
|
49
|
-
}];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
31
|
const sharedConfig = {
|
|
53
32
|
hydrating: false,
|
|
54
33
|
registry: undefined,
|
|
@@ -59,50 +38,496 @@ const sharedConfig = {
|
|
|
59
38
|
return signals.getNextChildId(o);
|
|
60
39
|
}
|
|
61
40
|
};
|
|
41
|
+
let _hydrationEndCallbacks = null;
|
|
42
|
+
let _pendingBoundaries = 0;
|
|
43
|
+
let _hydrationDone = false;
|
|
44
|
+
let _snapshotRootOwner = null;
|
|
45
|
+
function markTopLevelSnapshotScope() {
|
|
46
|
+
if (_snapshotRootOwner) return;
|
|
47
|
+
let owner = signals.getOwner();
|
|
48
|
+
if (!owner) return;
|
|
49
|
+
while (owner._parent) owner = owner._parent;
|
|
50
|
+
signals.markSnapshotScope(owner);
|
|
51
|
+
_snapshotRootOwner = owner;
|
|
52
|
+
}
|
|
53
|
+
function drainHydrationCallbacks() {
|
|
54
|
+
if (_hydrationDone) return;
|
|
55
|
+
_hydrationDone = true;
|
|
56
|
+
_doneValue = true;
|
|
57
|
+
signals.clearSnapshots();
|
|
58
|
+
signals.setSnapshotCapture(false);
|
|
59
|
+
signals.flush();
|
|
60
|
+
const cbs = _hydrationEndCallbacks;
|
|
61
|
+
_hydrationEndCallbacks = null;
|
|
62
|
+
if (cbs) for (const cb of cbs) cb();
|
|
63
|
+
setTimeout(() => {
|
|
64
|
+
if (globalThis._$HY) globalThis._$HY.done = true;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function checkHydrationComplete() {
|
|
68
|
+
if (_pendingBoundaries === 0) drainHydrationCallbacks();
|
|
69
|
+
}
|
|
70
|
+
let _hydratingValue = false;
|
|
71
|
+
let _doneValue = false;
|
|
72
|
+
let _createMemo;
|
|
73
|
+
let _createSignal;
|
|
74
|
+
let _createErrorBoundary;
|
|
75
|
+
let _createOptimistic;
|
|
76
|
+
let _createProjection;
|
|
77
|
+
let _createStore;
|
|
78
|
+
let _createOptimisticStore;
|
|
79
|
+
class MockPromise {
|
|
80
|
+
static all() {
|
|
81
|
+
return new MockPromise();
|
|
82
|
+
}
|
|
83
|
+
static allSettled() {
|
|
84
|
+
return new MockPromise();
|
|
85
|
+
}
|
|
86
|
+
static any() {
|
|
87
|
+
return new MockPromise();
|
|
88
|
+
}
|
|
89
|
+
static race() {
|
|
90
|
+
return new MockPromise();
|
|
91
|
+
}
|
|
92
|
+
static reject() {
|
|
93
|
+
return new MockPromise();
|
|
94
|
+
}
|
|
95
|
+
static resolve() {
|
|
96
|
+
return new MockPromise();
|
|
97
|
+
}
|
|
98
|
+
catch() {
|
|
99
|
+
return new MockPromise();
|
|
100
|
+
}
|
|
101
|
+
then() {
|
|
102
|
+
return new MockPromise();
|
|
103
|
+
}
|
|
104
|
+
finally() {
|
|
105
|
+
return new MockPromise();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function subFetch(fn, prev) {
|
|
109
|
+
const ogFetch = fetch;
|
|
110
|
+
const ogPromise = Promise;
|
|
111
|
+
try {
|
|
112
|
+
window.fetch = () => new MockPromise();
|
|
113
|
+
Promise = MockPromise;
|
|
114
|
+
const result = fn(prev);
|
|
115
|
+
if (result && typeof result[Symbol.asyncIterator] === "function") {
|
|
116
|
+
result[Symbol.asyncIterator]().next();
|
|
117
|
+
}
|
|
118
|
+
return result;
|
|
119
|
+
} finally {
|
|
120
|
+
window.fetch = ogFetch;
|
|
121
|
+
Promise = ogPromise;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function consumeFirstSync(ai) {
|
|
125
|
+
const iter = ai[Symbol.asyncIterator]();
|
|
126
|
+
const r = iter.next();
|
|
127
|
+
const value = !(r instanceof Promise) && !r.done ? r.value : undefined;
|
|
128
|
+
return [value, iter];
|
|
129
|
+
}
|
|
130
|
+
function applyPatches(target, patches) {
|
|
131
|
+
for (const patch of patches) {
|
|
132
|
+
const path = patch[0];
|
|
133
|
+
let current = target;
|
|
134
|
+
for (let i = 0; i < path.length - 1; i++) current = current[path[i]];
|
|
135
|
+
const key = path[path.length - 1];
|
|
136
|
+
if (patch.length === 1) {
|
|
137
|
+
Array.isArray(current) ? current.splice(key, 1) : delete current[key];
|
|
138
|
+
} else if (patch.length === 3) {
|
|
139
|
+
current.splice(key, 0, patch[1]);
|
|
140
|
+
} else {
|
|
141
|
+
current[key] = patch[1];
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function scheduleIteratorConsumption(iter, apply) {
|
|
146
|
+
const consume = () => {
|
|
147
|
+
while (true) {
|
|
148
|
+
const n = iter.next();
|
|
149
|
+
if (n instanceof Promise) {
|
|
150
|
+
n.then(r => {
|
|
151
|
+
if (r.done) return;
|
|
152
|
+
apply(r.value);
|
|
153
|
+
consume();
|
|
154
|
+
});
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (n.done) break;
|
|
158
|
+
apply(n.value);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
consume();
|
|
162
|
+
}
|
|
163
|
+
function isAsyncIterable(v) {
|
|
164
|
+
return v != null && typeof v[Symbol.asyncIterator] === "function";
|
|
165
|
+
}
|
|
166
|
+
function hydrateSignalFromAsyncIterable(coreFn, compute, value, options) {
|
|
167
|
+
const parent = signals.getOwner();
|
|
168
|
+
const expectedId = signals.peekNextChildId(parent);
|
|
169
|
+
if (!sharedConfig.has(expectedId)) return null;
|
|
170
|
+
const initP = sharedConfig.load(expectedId);
|
|
171
|
+
if (!isAsyncIterable(initP)) return null;
|
|
172
|
+
const [firstValue, iter] = consumeFirstSync(initP);
|
|
173
|
+
const [get, set] = signals.createSignal(firstValue);
|
|
174
|
+
const result = coreFn(() => get(), firstValue, options);
|
|
175
|
+
scheduleIteratorConsumption(iter, v => {
|
|
176
|
+
set(() => v);
|
|
177
|
+
signals.flush();
|
|
178
|
+
});
|
|
179
|
+
return result;
|
|
180
|
+
}
|
|
181
|
+
function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
|
|
182
|
+
const parent = signals.getOwner();
|
|
183
|
+
const expectedId = signals.peekNextChildId(parent);
|
|
184
|
+
if (!sharedConfig.has(expectedId)) return null;
|
|
185
|
+
const initP = sharedConfig.load(expectedId);
|
|
186
|
+
if (!isAsyncIterable(initP)) return null;
|
|
187
|
+
const [firstState, iter] = consumeFirstSync(initP);
|
|
188
|
+
const [store, setStore] = coreFn(() => {}, firstState ?? initialValue, options);
|
|
189
|
+
scheduleIteratorConsumption(iter, patches => {
|
|
190
|
+
setStore(d => {
|
|
191
|
+
applyPatches(d, patches);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
return [store, setStore];
|
|
195
|
+
}
|
|
196
|
+
function hydratedCreateMemo(compute, value, options) {
|
|
197
|
+
if (!sharedConfig.hydrating) return signals.createMemo(compute, value, options);
|
|
198
|
+
markTopLevelSnapshotScope();
|
|
199
|
+
const ssrSource = options?.ssrSource;
|
|
200
|
+
if (ssrSource === "client") {
|
|
201
|
+
const [hydrated, setHydrated] = signals.createSignal(false);
|
|
202
|
+
const memo = signals.createMemo(prev => {
|
|
203
|
+
if (!hydrated()) return prev ?? value;
|
|
204
|
+
return compute(prev);
|
|
205
|
+
}, value, options);
|
|
206
|
+
setHydrated(true);
|
|
207
|
+
return memo;
|
|
208
|
+
}
|
|
209
|
+
if (ssrSource === "initial") {
|
|
210
|
+
return signals.createMemo(prev => {
|
|
211
|
+
if (!sharedConfig.hydrating) return compute(prev);
|
|
212
|
+
subFetch(compute, prev);
|
|
213
|
+
return prev ?? value;
|
|
214
|
+
}, value, options);
|
|
215
|
+
}
|
|
216
|
+
const aiResult = hydrateSignalFromAsyncIterable(signals.createMemo, compute, value, options);
|
|
217
|
+
if (aiResult !== null) return aiResult;
|
|
218
|
+
return signals.createMemo(prev => {
|
|
219
|
+
const o = signals.getOwner();
|
|
220
|
+
if (!sharedConfig.hydrating) return compute(prev);
|
|
221
|
+
let initP;
|
|
222
|
+
if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
|
|
223
|
+
const init = initP?.v ?? initP;
|
|
224
|
+
return init != null ? (subFetch(compute, prev), init) : compute(prev);
|
|
225
|
+
}, value, options);
|
|
226
|
+
}
|
|
227
|
+
function hydratedCreateSignal(fn, second, third) {
|
|
228
|
+
if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createSignal(fn, second, third);
|
|
229
|
+
markTopLevelSnapshotScope();
|
|
230
|
+
const ssrSource = third?.ssrSource;
|
|
231
|
+
if (ssrSource === "client") {
|
|
232
|
+
const [hydrated, setHydrated] = signals.createSignal(false);
|
|
233
|
+
const sig = signals.createSignal(prev => {
|
|
234
|
+
if (!hydrated()) return prev ?? second;
|
|
235
|
+
return fn(prev);
|
|
236
|
+
}, second, third);
|
|
237
|
+
setHydrated(true);
|
|
238
|
+
return sig;
|
|
239
|
+
}
|
|
240
|
+
if (ssrSource === "initial") {
|
|
241
|
+
return signals.createSignal(prev => {
|
|
242
|
+
if (!sharedConfig.hydrating) return fn(prev);
|
|
243
|
+
subFetch(fn, prev);
|
|
244
|
+
return prev ?? second;
|
|
245
|
+
}, second, third);
|
|
246
|
+
}
|
|
247
|
+
const aiResult = hydrateSignalFromAsyncIterable(signals.createSignal, fn, second, third);
|
|
248
|
+
if (aiResult !== null) return aiResult;
|
|
249
|
+
return signals.createSignal(prev => {
|
|
250
|
+
if (!sharedConfig.hydrating) return fn(prev);
|
|
251
|
+
const o = signals.getOwner();
|
|
252
|
+
let initP;
|
|
253
|
+
if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
|
|
254
|
+
const init = initP?.v ?? initP;
|
|
255
|
+
return init != null ? (subFetch(fn, prev), init) : fn(prev);
|
|
256
|
+
}, second, third);
|
|
257
|
+
}
|
|
258
|
+
function hydratedCreateErrorBoundary(fn, fallback) {
|
|
259
|
+
if (!sharedConfig.hydrating) return signals.createErrorBoundary(fn, fallback);
|
|
260
|
+
markTopLevelSnapshotScope();
|
|
261
|
+
const parent = signals.getOwner();
|
|
262
|
+
const expectedId = signals.peekNextChildId(parent);
|
|
263
|
+
if (sharedConfig.has(expectedId)) {
|
|
264
|
+
const err = sharedConfig.load(expectedId);
|
|
265
|
+
if (err !== undefined) {
|
|
266
|
+
let hydrated = true;
|
|
267
|
+
return signals.createErrorBoundary(() => {
|
|
268
|
+
if (hydrated) {
|
|
269
|
+
hydrated = false;
|
|
270
|
+
throw err;
|
|
271
|
+
}
|
|
272
|
+
return fn();
|
|
273
|
+
}, fallback);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return signals.createErrorBoundary(fn, fallback);
|
|
277
|
+
}
|
|
278
|
+
function hydratedCreateOptimistic(fn, second, third) {
|
|
279
|
+
if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createOptimistic(fn, second, third);
|
|
280
|
+
markTopLevelSnapshotScope();
|
|
281
|
+
const ssrSource = third?.ssrSource;
|
|
282
|
+
if (ssrSource === "client") {
|
|
283
|
+
const [hydrated, setHydrated] = signals.createSignal(false);
|
|
284
|
+
const sig = signals.createOptimistic(prev => {
|
|
285
|
+
if (!hydrated()) return prev ?? second;
|
|
286
|
+
return fn(prev);
|
|
287
|
+
}, second, third);
|
|
288
|
+
setHydrated(true);
|
|
289
|
+
return sig;
|
|
290
|
+
}
|
|
291
|
+
if (ssrSource === "initial") {
|
|
292
|
+
return signals.createOptimistic(prev => {
|
|
293
|
+
if (!sharedConfig.hydrating) return fn(prev);
|
|
294
|
+
subFetch(fn, prev);
|
|
295
|
+
return prev ?? second;
|
|
296
|
+
}, second, third);
|
|
297
|
+
}
|
|
298
|
+
const aiResult = hydrateSignalFromAsyncIterable(signals.createOptimistic, fn, second, third);
|
|
299
|
+
if (aiResult !== null) return aiResult;
|
|
300
|
+
return signals.createOptimistic(prev => {
|
|
301
|
+
const o = signals.getOwner();
|
|
302
|
+
if (!sharedConfig.hydrating) return fn(prev);
|
|
303
|
+
let initP;
|
|
304
|
+
if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
|
|
305
|
+
const init = initP?.v ?? initP;
|
|
306
|
+
return init != null ? (subFetch(fn, prev), init) : fn(prev);
|
|
307
|
+
}, second, third);
|
|
308
|
+
}
|
|
309
|
+
function wrapStoreFn(fn, ssrSource) {
|
|
310
|
+
if (ssrSource === "initial") {
|
|
311
|
+
return draft => {
|
|
312
|
+
if (!sharedConfig.hydrating) return fn(draft);
|
|
313
|
+
subFetch(fn, draft);
|
|
314
|
+
return undefined;
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
return draft => {
|
|
318
|
+
const o = signals.getOwner();
|
|
319
|
+
if (!sharedConfig.hydrating) return fn(draft);
|
|
320
|
+
let initP;
|
|
321
|
+
if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
|
|
322
|
+
const init = initP?.v ?? initP;
|
|
323
|
+
return init != null ? (subFetch(fn, draft), init) : fn(draft);
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
function hydratedCreateStore(first, second, third) {
|
|
327
|
+
if (typeof first !== "function" || !sharedConfig.hydrating) return signals.createStore(first, second, third);
|
|
328
|
+
markTopLevelSnapshotScope();
|
|
329
|
+
const ssrSource = third?.ssrSource;
|
|
330
|
+
if (ssrSource === "client" || ssrSource === "initial") {
|
|
331
|
+
return signals.createStore(second ?? {}, undefined, third);
|
|
332
|
+
}
|
|
333
|
+
const aiResult = hydrateStoreFromAsyncIterable(signals.createStore, second ?? {}, third);
|
|
334
|
+
if (aiResult !== null) return aiResult;
|
|
335
|
+
return signals.createStore(wrapStoreFn(first, ssrSource), second, third);
|
|
336
|
+
}
|
|
337
|
+
function hydratedCreateOptimisticStore(first, second, third) {
|
|
338
|
+
if (typeof first !== "function" || !sharedConfig.hydrating) return signals.createOptimisticStore(first, second, third);
|
|
339
|
+
markTopLevelSnapshotScope();
|
|
340
|
+
const ssrSource = third?.ssrSource;
|
|
341
|
+
if (ssrSource === "client" || ssrSource === "initial") {
|
|
342
|
+
return signals.createOptimisticStore(second ?? {}, undefined, third);
|
|
343
|
+
}
|
|
344
|
+
const aiResult = hydrateStoreFromAsyncIterable(signals.createOptimisticStore, second ?? {}, third);
|
|
345
|
+
if (aiResult !== null) return aiResult;
|
|
346
|
+
return signals.createOptimisticStore(wrapStoreFn(first, ssrSource), second, third);
|
|
347
|
+
}
|
|
348
|
+
function hydratedCreateProjection(fn, initialValue, options) {
|
|
349
|
+
if (!sharedConfig.hydrating) return signals.createProjection(fn, initialValue, options);
|
|
350
|
+
markTopLevelSnapshotScope();
|
|
351
|
+
const ssrSource = options?.ssrSource;
|
|
352
|
+
if (ssrSource === "client" || ssrSource === "initial") {
|
|
353
|
+
return signals.createProjection(draft => draft, initialValue, options);
|
|
354
|
+
}
|
|
355
|
+
const aiResult = hydrateStoreFromAsyncIterable(signals.createStore, initialValue, options);
|
|
356
|
+
if (aiResult !== null) return aiResult[0];
|
|
357
|
+
return signals.createProjection(wrapStoreFn(fn, ssrSource), initialValue, options);
|
|
358
|
+
}
|
|
359
|
+
function enableHydration() {
|
|
360
|
+
_createMemo = hydratedCreateMemo;
|
|
361
|
+
_createSignal = hydratedCreateSignal;
|
|
362
|
+
_createErrorBoundary = hydratedCreateErrorBoundary;
|
|
363
|
+
_createOptimistic = hydratedCreateOptimistic;
|
|
364
|
+
_createProjection = hydratedCreateProjection;
|
|
365
|
+
_createStore = hydratedCreateStore;
|
|
366
|
+
_createOptimisticStore = hydratedCreateOptimisticStore;
|
|
367
|
+
_hydratingValue = sharedConfig.hydrating;
|
|
368
|
+
_doneValue = sharedConfig.done;
|
|
369
|
+
Object.defineProperty(sharedConfig, "hydrating", {
|
|
370
|
+
get() {
|
|
371
|
+
return _hydratingValue;
|
|
372
|
+
},
|
|
373
|
+
set(v) {
|
|
374
|
+
const was = _hydratingValue;
|
|
375
|
+
_hydratingValue = v;
|
|
376
|
+
if (!was && v) {
|
|
377
|
+
_hydrationDone = false;
|
|
378
|
+
_doneValue = false;
|
|
379
|
+
_pendingBoundaries = 0;
|
|
380
|
+
signals.setSnapshotCapture(true);
|
|
381
|
+
_snapshotRootOwner = null;
|
|
382
|
+
} else if (was && !v) {
|
|
383
|
+
if (_snapshotRootOwner) {
|
|
384
|
+
signals.releaseSnapshotScope(_snapshotRootOwner);
|
|
385
|
+
_snapshotRootOwner = null;
|
|
386
|
+
}
|
|
387
|
+
checkHydrationComplete();
|
|
388
|
+
}
|
|
389
|
+
},
|
|
390
|
+
configurable: true,
|
|
391
|
+
enumerable: true
|
|
392
|
+
});
|
|
393
|
+
Object.defineProperty(sharedConfig, "done", {
|
|
394
|
+
get() {
|
|
395
|
+
return _doneValue;
|
|
396
|
+
},
|
|
397
|
+
set(v) {
|
|
398
|
+
_doneValue = v;
|
|
399
|
+
if (v) drainHydrationCallbacks();
|
|
400
|
+
},
|
|
401
|
+
configurable: true,
|
|
402
|
+
enumerable: true
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
const createMemo = (...args) => (_createMemo || signals.createMemo)(...args);
|
|
406
|
+
const createSignal = (...args) => (_createSignal || signals.createSignal)(...args);
|
|
407
|
+
const createErrorBoundary = (...args) => (_createErrorBoundary || signals.createErrorBoundary)(...args);
|
|
408
|
+
const createOptimistic = (...args) => (_createOptimistic || signals.createOptimistic)(...args);
|
|
409
|
+
const createProjection = (...args) => (_createProjection || signals.createProjection)(...args);
|
|
410
|
+
const createStore = (...args) => (_createStore || signals.createStore)(...args);
|
|
411
|
+
const createOptimisticStore = (...args) => (_createOptimisticStore || signals.createOptimisticStore)(...args);
|
|
412
|
+
function loadModuleAssets(mapping) {
|
|
413
|
+
const hy = globalThis._$HY;
|
|
414
|
+
if (!hy) return;
|
|
415
|
+
if (!hy.modules) hy.modules = {};
|
|
416
|
+
if (!hy.loading) hy.loading = {};
|
|
417
|
+
const pending = [];
|
|
418
|
+
for (const moduleUrl in mapping) {
|
|
419
|
+
if (hy.modules[moduleUrl]) continue;
|
|
420
|
+
const entryUrl = mapping[moduleUrl];
|
|
421
|
+
if (!hy.loading[moduleUrl]) {
|
|
422
|
+
hy.loading[moduleUrl] = import(entryUrl).then(mod => {
|
|
423
|
+
hy.modules[moduleUrl] = mod;
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
pending.push(hy.loading[moduleUrl]);
|
|
427
|
+
}
|
|
428
|
+
return pending.length ? Promise.all(pending).then(() => {}) : undefined;
|
|
429
|
+
}
|
|
430
|
+
function createBoundaryTrigger() {
|
|
431
|
+
signals.setSnapshotCapture(false);
|
|
432
|
+
const [s, set] = signals.createSignal(undefined, {
|
|
433
|
+
equals: false
|
|
434
|
+
});
|
|
435
|
+
s();
|
|
436
|
+
signals.setSnapshotCapture(true);
|
|
437
|
+
return set;
|
|
438
|
+
}
|
|
439
|
+
function resumeBoundaryHydration(o, id, set) {
|
|
440
|
+
_pendingBoundaries--;
|
|
441
|
+
if (signals.isDisposed(o)) {
|
|
442
|
+
checkHydrationComplete();
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
sharedConfig.gather(id);
|
|
446
|
+
_hydratingValue = true;
|
|
447
|
+
signals.markSnapshotScope(o);
|
|
448
|
+
_snapshotRootOwner = o;
|
|
449
|
+
set();
|
|
450
|
+
signals.flush();
|
|
451
|
+
_snapshotRootOwner = null;
|
|
452
|
+
_hydratingValue = false;
|
|
453
|
+
signals.releaseSnapshotScope(o);
|
|
454
|
+
signals.flush();
|
|
455
|
+
checkHydrationComplete();
|
|
456
|
+
}
|
|
62
457
|
function Loading(props) {
|
|
63
458
|
if (!sharedConfig.hydrating) return signals.createLoadBoundary(() => props.children, () => props.fallback);
|
|
64
459
|
return signals.createMemo(() => {
|
|
65
460
|
const o = signals.getOwner();
|
|
66
461
|
const id = o.id;
|
|
462
|
+
let assetPromise;
|
|
463
|
+
if (sharedConfig.hydrating && sharedConfig.has(id + "_assets")) {
|
|
464
|
+
const mapping = sharedConfig.load(id + "_assets");
|
|
465
|
+
if (mapping && typeof mapping === "object") assetPromise = loadModuleAssets(mapping);
|
|
466
|
+
}
|
|
67
467
|
if (sharedConfig.hydrating && sharedConfig.has(id)) {
|
|
68
468
|
let ref = sharedConfig.load(id);
|
|
69
469
|
let p;
|
|
70
470
|
if (ref) {
|
|
71
|
-
if (typeof ref !== "object" || ref.s !==
|
|
471
|
+
if (typeof ref !== "object" || ref.s !== 1) p = ref;else sharedConfig.gather(id);
|
|
72
472
|
}
|
|
73
473
|
if (p) {
|
|
74
|
-
|
|
75
|
-
|
|
474
|
+
_pendingBoundaries++;
|
|
475
|
+
signals.onCleanup(() => {
|
|
476
|
+
if (!signals.isDisposed(o)) return;
|
|
477
|
+
sharedConfig.cleanupFragment?.(id);
|
|
76
478
|
});
|
|
77
|
-
|
|
479
|
+
const set = createBoundaryTrigger();
|
|
78
480
|
if (p !== "$$f") {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
481
|
+
const waitFor = assetPromise ? Promise.all([p, assetPromise]) : p;
|
|
482
|
+
waitFor.then(() => resumeBoundaryHydration(o, id, set), err => {
|
|
483
|
+
_pendingBoundaries--;
|
|
484
|
+
checkHydrationComplete();
|
|
485
|
+
signals.runWithOwner(o, () => {
|
|
486
|
+
throw err;
|
|
487
|
+
});
|
|
488
|
+
});
|
|
489
|
+
} else {
|
|
490
|
+
const afterAssets = () => {
|
|
491
|
+
_pendingBoundaries--;
|
|
82
492
|
set();
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}));
|
|
88
|
-
} else queueMicrotask(set);
|
|
493
|
+
checkHydrationComplete();
|
|
494
|
+
};
|
|
495
|
+
if (assetPromise) assetPromise.then(() => queueMicrotask(afterAssets));else queueMicrotask(afterAssets);
|
|
496
|
+
}
|
|
89
497
|
return props.fallback;
|
|
90
498
|
}
|
|
91
499
|
}
|
|
500
|
+
if (assetPromise) {
|
|
501
|
+
_pendingBoundaries++;
|
|
502
|
+
const set = createBoundaryTrigger();
|
|
503
|
+
assetPromise.then(() => resumeBoundaryHydration(o, id, set));
|
|
504
|
+
return undefined;
|
|
505
|
+
}
|
|
92
506
|
return signals.createLoadBoundary(() => props.children, () => props.fallback);
|
|
93
507
|
});
|
|
94
508
|
}
|
|
95
509
|
|
|
96
|
-
function enableHydration() {
|
|
97
|
-
}
|
|
98
510
|
function createComponent(Comp, props) {
|
|
99
511
|
return signals.untrack(() => Comp(props || {}));
|
|
100
512
|
}
|
|
101
|
-
function lazy(fn) {
|
|
513
|
+
function lazy(fn, moduleUrl) {
|
|
102
514
|
let comp;
|
|
103
515
|
let p;
|
|
104
516
|
const wrap = props => {
|
|
105
|
-
|
|
517
|
+
if (sharedConfig.hydrating && moduleUrl) {
|
|
518
|
+
const cached = globalThis._$HY?.modules?.[moduleUrl];
|
|
519
|
+
if (!cached) {
|
|
520
|
+
throw new Error(`lazy() module "${moduleUrl}" was not preloaded before hydration. ` + "Ensure it is inside a Loading boundary.");
|
|
521
|
+
}
|
|
522
|
+
comp = () => cached.default;
|
|
523
|
+
}
|
|
524
|
+
if (!comp) {
|
|
525
|
+
p || (p = fn());
|
|
526
|
+
p.then(mod => {
|
|
527
|
+
comp = () => mod.default;
|
|
528
|
+
});
|
|
529
|
+
comp = signals.createMemo(() => p.then(mod => mod.default));
|
|
530
|
+
}
|
|
106
531
|
let Comp;
|
|
107
532
|
return signals.createMemo(() => (Comp = comp()) ? signals.untrack(() => {
|
|
108
533
|
return Comp(props);
|
|
@@ -144,10 +569,15 @@ function Show(props) {
|
|
|
144
569
|
if (c) {
|
|
145
570
|
const child = props.children;
|
|
146
571
|
const fn = typeof child === "function" && child.length > 0;
|
|
147
|
-
return fn ? signals.untrack(() =>
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
572
|
+
return fn ? signals.untrack(() => {
|
|
573
|
+
try {
|
|
574
|
+
return child(() => {
|
|
575
|
+
if (!signals.untrack(condition)) throw narrowedError("Show");
|
|
576
|
+
return conditionValue();
|
|
577
|
+
});
|
|
578
|
+
} finally {
|
|
579
|
+
}
|
|
580
|
+
}) : child;
|
|
151
581
|
}
|
|
152
582
|
return props.fallback;
|
|
153
583
|
}, undefined, undefined);
|
|
@@ -175,24 +605,26 @@ function Switch(props) {
|
|
|
175
605
|
const [index, conditionValue, mp] = sel;
|
|
176
606
|
const child = mp.children;
|
|
177
607
|
const fn = typeof child === "function" && child.length > 0;
|
|
178
|
-
return fn ? signals.untrack(() =>
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
608
|
+
return fn ? signals.untrack(() => {
|
|
609
|
+
try {
|
|
610
|
+
return child(() => {
|
|
611
|
+
if (signals.untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
|
|
612
|
+
return conditionValue();
|
|
613
|
+
});
|
|
614
|
+
} finally {
|
|
615
|
+
}
|
|
616
|
+
}) : child;
|
|
182
617
|
}, undefined, undefined);
|
|
183
618
|
}
|
|
184
619
|
function Match(props) {
|
|
185
620
|
return props;
|
|
186
621
|
}
|
|
187
622
|
function Errored(props) {
|
|
188
|
-
return
|
|
623
|
+
return createErrorBoundary(() => props.children, (err, reset) => {
|
|
189
624
|
const f = props.fallback;
|
|
190
625
|
return typeof f === "function" && f.length ? f(err, reset) : f;
|
|
191
626
|
});
|
|
192
627
|
}
|
|
193
|
-
function Boundary(props) {
|
|
194
|
-
return signals.createBoundary(() => props.children, () => props.mode);
|
|
195
|
-
}
|
|
196
628
|
|
|
197
629
|
function ssrHandleError() {}
|
|
198
630
|
function ssrRunInScope() {}
|
|
@@ -206,6 +638,10 @@ Object.defineProperty(exports, "$TRACK", {
|
|
|
206
638
|
enumerable: true,
|
|
207
639
|
get: function () { return signals.$TRACK; }
|
|
208
640
|
});
|
|
641
|
+
Object.defineProperty(exports, "NotReadyError", {
|
|
642
|
+
enumerable: true,
|
|
643
|
+
get: function () { return signals.NotReadyError; }
|
|
644
|
+
});
|
|
209
645
|
Object.defineProperty(exports, "action", {
|
|
210
646
|
enumerable: true,
|
|
211
647
|
get: function () { return signals.action; }
|
|
@@ -214,22 +650,6 @@ Object.defineProperty(exports, "createEffect", {
|
|
|
214
650
|
enumerable: true,
|
|
215
651
|
get: function () { return signals.createEffect; }
|
|
216
652
|
});
|
|
217
|
-
Object.defineProperty(exports, "createMemo", {
|
|
218
|
-
enumerable: true,
|
|
219
|
-
get: function () { return signals.createMemo; }
|
|
220
|
-
});
|
|
221
|
-
Object.defineProperty(exports, "createOptimistic", {
|
|
222
|
-
enumerable: true,
|
|
223
|
-
get: function () { return signals.createOptimistic; }
|
|
224
|
-
});
|
|
225
|
-
Object.defineProperty(exports, "createOptimisticStore", {
|
|
226
|
-
enumerable: true,
|
|
227
|
-
get: function () { return signals.createOptimisticStore; }
|
|
228
|
-
});
|
|
229
|
-
Object.defineProperty(exports, "createProjection", {
|
|
230
|
-
enumerable: true,
|
|
231
|
-
get: function () { return signals.createProjection; }
|
|
232
|
-
});
|
|
233
653
|
Object.defineProperty(exports, "createReaction", {
|
|
234
654
|
enumerable: true,
|
|
235
655
|
get: function () { return signals.createReaction; }
|
|
@@ -242,14 +662,6 @@ Object.defineProperty(exports, "createRoot", {
|
|
|
242
662
|
enumerable: true,
|
|
243
663
|
get: function () { return signals.createRoot; }
|
|
244
664
|
});
|
|
245
|
-
Object.defineProperty(exports, "createSignal", {
|
|
246
|
-
enumerable: true,
|
|
247
|
-
get: function () { return signals.createSignal; }
|
|
248
|
-
});
|
|
249
|
-
Object.defineProperty(exports, "createStore", {
|
|
250
|
-
enumerable: true,
|
|
251
|
-
get: function () { return signals.createStore; }
|
|
252
|
-
});
|
|
253
665
|
Object.defineProperty(exports, "createTrackedEffect", {
|
|
254
666
|
enumerable: true,
|
|
255
667
|
get: function () { return signals.createTrackedEffect; }
|
|
@@ -343,7 +755,6 @@ Object.defineProperty(exports, "untrack", {
|
|
|
343
755
|
get: function () { return signals.untrack; }
|
|
344
756
|
});
|
|
345
757
|
exports.$DEVCOMP = $DEVCOMP;
|
|
346
|
-
exports.Boundary = Boundary;
|
|
347
758
|
exports.DEV = DEV;
|
|
348
759
|
exports.Errored = Errored;
|
|
349
760
|
exports.For = For;
|
|
@@ -355,12 +766,16 @@ exports.Switch = Switch;
|
|
|
355
766
|
exports.children = children;
|
|
356
767
|
exports.createComponent = createComponent;
|
|
357
768
|
exports.createContext = createContext;
|
|
769
|
+
exports.createMemo = createMemo;
|
|
770
|
+
exports.createOptimistic = createOptimistic;
|
|
771
|
+
exports.createOptimisticStore = createOptimisticStore;
|
|
772
|
+
exports.createProjection = createProjection;
|
|
773
|
+
exports.createSignal = createSignal;
|
|
774
|
+
exports.createStore = createStore;
|
|
358
775
|
exports.createUniqueId = createUniqueId;
|
|
359
776
|
exports.enableHydration = enableHydration;
|
|
360
777
|
exports.lazy = lazy;
|
|
361
|
-
exports.reducer = reducer;
|
|
362
778
|
exports.sharedConfig = sharedConfig;
|
|
363
779
|
exports.ssrHandleError = ssrHandleError;
|
|
364
780
|
exports.ssrRunInScope = ssrRunInScope;
|
|
365
|
-
exports.tryCatch = tryCatch;
|
|
366
781
|
exports.useContext = useContext;
|