solid-js 2.0.0-beta.0 → 2.0.0-beta.10
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/CHEATSHEET.md +640 -0
- package/README.md +42 -188
- package/dist/dev.cjs +451 -283
- package/dist/dev.js +428 -286
- package/dist/server.cjs +735 -279
- package/dist/server.js +715 -282
- package/dist/solid.cjs +443 -255
- package/dist/solid.js +420 -258
- package/package.json +67 -39
- package/types/client/component.d.ts +65 -19
- package/types/client/core.d.ts +110 -34
- package/types/client/flow.d.ts +176 -42
- package/types/client/hydration.d.ts +525 -31
- package/types/index.d.ts +9 -12
- package/types/server/component.d.ts +12 -11
- package/types/server/core.d.ts +19 -14
- package/types/server/flow.d.ts +76 -21
- package/types/server/hydration.d.ts +49 -7
- package/types/server/index.d.ts +5 -7
- package/types/server/shared.d.ts +9 -4
- package/types/server/signals.d.ts +45 -18
- package/types/types.d.ts +15 -0
- package/types-cjs/client/component.d.cts +120 -0
- package/types-cjs/client/core.d.cts +141 -0
- package/types-cjs/client/flow.d.cts +234 -0
- package/types-cjs/client/hydration.d.cts +570 -0
- package/types-cjs/index.d.cts +17 -0
- package/types-cjs/package.json +3 -0
- package/types-cjs/server/component.d.cts +67 -0
- package/types-cjs/server/core.d.cts +49 -0
- package/types-cjs/server/flow.d.cts +115 -0
- package/types-cjs/server/hydration.d.cts +63 -0
- package/types-cjs/server/index.d.cts +10 -0
- package/types-cjs/server/shared.d.cts +50 -0
- package/types-cjs/server/signals.d.cts +87 -0
- package/types-cjs/types.d.cts +15 -0
- package/jsx-runtime.d.ts +0 -1
- package/types/jsx.d.ts +0 -4129
package/dist/server.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { getOwner, getNextChildId, createOwner, runWithOwner, onCleanup,
|
|
2
|
-
export { $PROXY, $TRACK, NotReadyError, createOwner, createRoot, flatten, getNextChildId, getOwner, isEqual, isWrappable, merge, omit, onCleanup, runWithOwner, snapshot, storePath } from '@solidjs/signals';
|
|
1
|
+
import { getOwner, getContext, getNextChildId, createOwner, NotReadyError, runWithOwner, onCleanup, isWrappable, setContext, flatten, createRoot } from '@solidjs/signals';
|
|
2
|
+
export { $PROXY, $REFRESH, $TRACK, NotReadyError, createOwner, createRoot, enableExternalSource, enforceLoadingBoundary, flatten, getNextChildId, getOwner, isDisposed, isEqual, isWrappable, merge, omit, onCleanup, runWithOwner, snapshot, storePath } from '@solidjs/signals';
|
|
3
3
|
|
|
4
|
+
const NoHydrateContext = {
|
|
5
|
+
id: Symbol("NoHydrateContext"),
|
|
6
|
+
defaultValue: false
|
|
7
|
+
};
|
|
4
8
|
const sharedConfig = {
|
|
5
9
|
getNextContextId() {
|
|
6
10
|
const o = getOwner();
|
|
7
11
|
if (!o) throw new Error(`getNextContextId cannot be used under non-hydrating context`);
|
|
12
|
+
if (getContext(NoHydrateContext)) return undefined;
|
|
8
13
|
return getNextChildId(o);
|
|
9
14
|
}
|
|
10
15
|
};
|
|
@@ -22,38 +27,82 @@ function runWithObserver(comp, fn) {
|
|
|
22
27
|
function getObserver() {
|
|
23
28
|
return Observer;
|
|
24
29
|
}
|
|
25
|
-
function
|
|
30
|
+
function createDeferredPromise() {
|
|
31
|
+
let settled = false;
|
|
32
|
+
let resolvePromise;
|
|
33
|
+
let rejectPromise;
|
|
34
|
+
const promise = new Promise((resolve, reject) => {
|
|
35
|
+
resolvePromise = resolve;
|
|
36
|
+
rejectPromise = reject;
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
promise,
|
|
40
|
+
resolve(value) {
|
|
41
|
+
if (settled) return;
|
|
42
|
+
settled = true;
|
|
43
|
+
promise.s = 1;
|
|
44
|
+
promise.v = value;
|
|
45
|
+
resolvePromise(value);
|
|
46
|
+
},
|
|
47
|
+
reject(error) {
|
|
48
|
+
if (settled) return;
|
|
49
|
+
settled = true;
|
|
50
|
+
promise.s = 2;
|
|
51
|
+
promise.v = error;
|
|
52
|
+
rejectPromise(error);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function subscribePendingRetry(error, retry) {
|
|
57
|
+
if (!(error instanceof NotReadyError)) return false;
|
|
58
|
+
error.source?.then(() => retry(), () => retry());
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
function settleServerAsync(initial, rerun, deferred, onSuccess, onError, isDisposed) {
|
|
62
|
+
let first = true;
|
|
63
|
+
const attempt = () => {
|
|
64
|
+
if (isDisposed()) return;
|
|
65
|
+
let current;
|
|
66
|
+
try {
|
|
67
|
+
current = first ? initial : rerun();
|
|
68
|
+
first = false;
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (subscribePendingRetry(error, attempt)) return;
|
|
71
|
+
onError(error);
|
|
72
|
+
deferred.reject(error);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
Promise.resolve(current).then(value => {
|
|
76
|
+
if (isDisposed()) return;
|
|
77
|
+
deferred.resolve(onSuccess(value));
|
|
78
|
+
}, error => {
|
|
79
|
+
if (isDisposed()) return;
|
|
80
|
+
if (subscribePendingRetry(error, attempt)) return;
|
|
81
|
+
onError(error);
|
|
82
|
+
deferred.reject(error);
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
attempt();
|
|
86
|
+
}
|
|
87
|
+
function createSignal(first, second) {
|
|
26
88
|
if (typeof first === "function") {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
let value = second;
|
|
31
|
-
return [() => value, v => {
|
|
32
|
-
return value = typeof v === "function" ? v(value) : v;
|
|
33
|
-
}];
|
|
34
|
-
}
|
|
35
|
-
const memoOpts = third?.deferStream || ssrSource ? {
|
|
36
|
-
deferStream: third?.deferStream,
|
|
37
|
-
ssrSource
|
|
89
|
+
const opts = second?.deferStream || second?.ssrSource ? {
|
|
90
|
+
deferStream: second?.deferStream,
|
|
91
|
+
ssrSource: second?.ssrSource
|
|
38
92
|
} : undefined;
|
|
39
|
-
const memo = createMemo(
|
|
40
|
-
|
|
41
|
-
return [() => value, v => {
|
|
42
|
-
return value = typeof v === "function" ? v(value) : v;
|
|
43
|
-
}];
|
|
44
|
-
}, undefined, memoOpts);
|
|
45
|
-
return [() => memo()[0](), v => memo()[1](v)];
|
|
93
|
+
const memo = createMemo(prev => first(prev), opts);
|
|
94
|
+
return [memo, () => undefined];
|
|
46
95
|
}
|
|
47
96
|
return [() => first, v => {
|
|
48
97
|
return first = typeof v === "function" ? v(first) : v;
|
|
49
98
|
}];
|
|
50
99
|
}
|
|
51
|
-
function createMemo(compute,
|
|
100
|
+
function createMemo(compute, options) {
|
|
52
101
|
const ctx = sharedConfig.context;
|
|
53
102
|
const owner = createOwner();
|
|
54
103
|
const comp = {
|
|
55
104
|
owner,
|
|
56
|
-
value:
|
|
105
|
+
value: undefined,
|
|
57
106
|
compute: compute,
|
|
58
107
|
error: undefined,
|
|
59
108
|
computed: false,
|
|
@@ -64,21 +113,22 @@ function createMemo(compute, value, options) {
|
|
|
64
113
|
}));
|
|
65
114
|
function update() {
|
|
66
115
|
if (comp.disposed) return;
|
|
116
|
+
const run = () => runWithOwner(owner, () => runWithObserver(comp, () => comp.compute(comp.value)));
|
|
67
117
|
try {
|
|
68
118
|
comp.error = undefined;
|
|
69
|
-
const result =
|
|
119
|
+
const result = run();
|
|
70
120
|
comp.computed = true;
|
|
71
|
-
processResult(comp, result, owner, ctx, options?.deferStream, options?.ssrSource);
|
|
121
|
+
processResult(comp, result, owner, ctx, options?.deferStream, options?.ssrSource, run);
|
|
72
122
|
} catch (err) {
|
|
73
123
|
if (err instanceof NotReadyError) {
|
|
74
|
-
err
|
|
124
|
+
subscribePendingRetry(err, update);
|
|
75
125
|
}
|
|
76
126
|
comp.error = err;
|
|
77
127
|
comp.computed = true;
|
|
78
128
|
}
|
|
79
129
|
}
|
|
80
130
|
const ssrSource = options?.ssrSource;
|
|
81
|
-
if (ssrSource === "
|
|
131
|
+
if (ssrSource === "client") {
|
|
82
132
|
comp.computed = true;
|
|
83
133
|
} else if (!options?.lazy) {
|
|
84
134
|
update();
|
|
@@ -153,75 +203,128 @@ function createDeepProxy(target, patches, basePath = []) {
|
|
|
153
203
|
};
|
|
154
204
|
return new Proxy(target, handler);
|
|
155
205
|
}
|
|
156
|
-
function processResult(comp, result, owner, ctx, deferStream, ssrSource) {
|
|
206
|
+
function processResult(comp, result, owner, ctx, deferStream, ssrSource, rerun) {
|
|
157
207
|
if (comp.disposed) return;
|
|
158
208
|
const id = owner.id;
|
|
159
|
-
const
|
|
209
|
+
const noHydrate = getContext(NoHydrateContext, owner);
|
|
160
210
|
if (result instanceof Promise) {
|
|
161
|
-
result.
|
|
162
|
-
|
|
163
|
-
result.v = v;
|
|
164
|
-
if (comp.disposed) return;
|
|
165
|
-
comp.value = v;
|
|
211
|
+
if (result.s === 1) {
|
|
212
|
+
comp.value = result.v;
|
|
166
213
|
comp.error = undefined;
|
|
167
|
-
|
|
168
|
-
if (ctx?.async && ctx.serialize && id) ctx.serialize(id, result, deferStream);
|
|
169
|
-
if (uninitialized) {
|
|
170
|
-
comp.error = new NotReadyError(result);
|
|
214
|
+
return;
|
|
171
215
|
}
|
|
216
|
+
if (result.s === 2) {
|
|
217
|
+
comp.error = result.v;
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const deferred = createDeferredPromise();
|
|
221
|
+
if (ctx?.async && ctx.serialize && id && !noHydrate) ctx.serialize(id, deferred.promise, deferStream);
|
|
222
|
+
settleServerAsync(result, () => rerun ? rerun() : result, deferred, value => {
|
|
223
|
+
result.s = 1;
|
|
224
|
+
result.v = value;
|
|
225
|
+
comp.value = value;
|
|
226
|
+
comp.error = undefined;
|
|
227
|
+
return value;
|
|
228
|
+
}, error => {
|
|
229
|
+
result.s = 2;
|
|
230
|
+
result.v = error;
|
|
231
|
+
comp.error = error;
|
|
232
|
+
}, () => comp.disposed);
|
|
233
|
+
comp.error = new NotReadyError(deferred.promise);
|
|
172
234
|
return;
|
|
173
235
|
}
|
|
174
236
|
const iterator = result?.[Symbol.asyncIterator];
|
|
175
237
|
if (typeof iterator === "function") {
|
|
176
|
-
const iter = iterator.call(result);
|
|
177
238
|
if (ssrSource === "hybrid") {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
239
|
+
let currentResult = result;
|
|
240
|
+
let iter;
|
|
241
|
+
const deferred = createDeferredPromise();
|
|
242
|
+
const runFirst = () => {
|
|
243
|
+
const source = currentResult ?? (rerun ? rerun() : result);
|
|
244
|
+
currentResult = undefined;
|
|
245
|
+
const nextIterator = source?.[Symbol.asyncIterator];
|
|
246
|
+
if (typeof nextIterator !== "function") {
|
|
247
|
+
throw new Error("Expected async iterator while retrying server createMemo");
|
|
248
|
+
}
|
|
249
|
+
iter = nextIterator.call(source);
|
|
250
|
+
return iter.next().then(value => {
|
|
251
|
+
if (!value.done) closeAsyncIterator(iter);
|
|
252
|
+
return value.value;
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
settleServerAsync(runFirst(), runFirst, deferred, value => {
|
|
256
|
+
comp.value = value;
|
|
183
257
|
comp.error = undefined;
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
258
|
+
return value;
|
|
259
|
+
}, error => {
|
|
260
|
+
comp.error = error;
|
|
261
|
+
}, () => comp.disposed);
|
|
262
|
+
if (ctx?.async && ctx.serialize && id && !noHydrate) ctx.serialize(id, deferred.promise, deferStream);
|
|
263
|
+
comp.error = new NotReadyError(deferred.promise);
|
|
189
264
|
} else {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
265
|
+
let currentResult = result;
|
|
266
|
+
let iter;
|
|
267
|
+
let firstResult;
|
|
268
|
+
const deferred = createDeferredPromise();
|
|
269
|
+
const runFirst = () => {
|
|
270
|
+
const source = currentResult ?? (rerun ? rerun() : result);
|
|
271
|
+
currentResult = undefined;
|
|
272
|
+
const nextIterator = source?.[Symbol.asyncIterator];
|
|
273
|
+
if (typeof nextIterator !== "function") {
|
|
274
|
+
throw new Error("Expected async iterator while retrying server createMemo");
|
|
196
275
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
if (!servedFirst) {
|
|
203
|
-
servedFirst = true;
|
|
204
|
-
return firstNext.then(r => {
|
|
205
|
-
if (!r.done && !comp.disposed) comp.value = r.value;
|
|
206
|
-
return r;
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
return iter.next().then(r => r);
|
|
210
|
-
}
|
|
211
|
-
})
|
|
276
|
+
iter = nextIterator.call(source);
|
|
277
|
+
return iter.next().then(value => {
|
|
278
|
+
firstResult = value;
|
|
279
|
+
return Promise.resolve();
|
|
280
|
+
});
|
|
212
281
|
};
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
282
|
+
settleServerAsync(runFirst(), runFirst, deferred, () => {
|
|
283
|
+
const resolved = firstResult;
|
|
284
|
+
if (resolved && !resolved.done) {
|
|
285
|
+
comp.value = resolved.value;
|
|
286
|
+
}
|
|
287
|
+
comp.error = undefined;
|
|
288
|
+
return undefined;
|
|
289
|
+
}, error => {
|
|
290
|
+
comp.error = error;
|
|
291
|
+
}, () => comp.disposed);
|
|
292
|
+
if (ctx?.async && ctx.serialize && id && !noHydrate) {
|
|
293
|
+
let tappedFirst = true;
|
|
294
|
+
const tapped = {
|
|
295
|
+
[Symbol.asyncIterator]: () => ({
|
|
296
|
+
next() {
|
|
297
|
+
if (tappedFirst) {
|
|
298
|
+
tappedFirst = false;
|
|
299
|
+
return deferred.promise.then(() => firstResult?.done ? {
|
|
300
|
+
done: true,
|
|
301
|
+
value: undefined
|
|
302
|
+
} : firstResult);
|
|
303
|
+
}
|
|
304
|
+
return iter.next().then(r => r);
|
|
305
|
+
},
|
|
306
|
+
return(value) {
|
|
307
|
+
return iter.return?.(value);
|
|
308
|
+
}
|
|
309
|
+
})
|
|
310
|
+
};
|
|
311
|
+
ctx.serialize(id, tapped, deferStream);
|
|
216
312
|
}
|
|
313
|
+
comp.error = new NotReadyError(deferred.promise);
|
|
217
314
|
}
|
|
218
315
|
return;
|
|
219
316
|
}
|
|
220
317
|
comp.value = result;
|
|
221
318
|
}
|
|
222
|
-
function
|
|
319
|
+
function closeAsyncIterator(iter, value) {
|
|
320
|
+
const returned = iter.return?.(value);
|
|
321
|
+
if (returned && typeof returned.then === "function") {
|
|
322
|
+
returned.then(undefined, () => {});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function serverEffect(compute, effectFn, options) {
|
|
223
326
|
const ssrSource = options?.ssrSource;
|
|
224
|
-
if (ssrSource === "client"
|
|
327
|
+
if (ssrSource === "client") {
|
|
225
328
|
createOwner();
|
|
226
329
|
return;
|
|
227
330
|
}
|
|
@@ -229,7 +332,7 @@ function serverEffect(compute, effectFn, value, options) {
|
|
|
229
332
|
const owner = createOwner();
|
|
230
333
|
const comp = {
|
|
231
334
|
owner,
|
|
232
|
-
value:
|
|
335
|
+
value: undefined,
|
|
233
336
|
compute: compute,
|
|
234
337
|
error: undefined,
|
|
235
338
|
computed: true,
|
|
@@ -241,19 +344,19 @@ function serverEffect(compute, effectFn, value, options) {
|
|
|
241
344
|
}));
|
|
242
345
|
}
|
|
243
346
|
try {
|
|
244
|
-
const result = runWithOwner(owner, () => runWithObserver(comp, () => compute(
|
|
347
|
+
const result = runWithOwner(owner, () => runWithObserver(comp, () => compute(undefined)));
|
|
245
348
|
if (ssrSource) {
|
|
246
349
|
processResult(comp, result, owner, ctx, options?.deferStream, ssrSource);
|
|
247
350
|
}
|
|
248
|
-
effectFn?.(ssrSource ? comp.value ?? result : result,
|
|
351
|
+
effectFn?.(ssrSource ? comp.value ?? result : result, undefined);
|
|
249
352
|
} catch (err) {
|
|
250
353
|
}
|
|
251
354
|
}
|
|
252
|
-
function createEffect(compute, effect,
|
|
253
|
-
serverEffect(compute, undefined,
|
|
355
|
+
function createEffect(compute, effect, options) {
|
|
356
|
+
serverEffect(compute, undefined, options);
|
|
254
357
|
}
|
|
255
|
-
function createRenderEffect(compute, effectFn,
|
|
256
|
-
serverEffect(compute, effectFn,
|
|
358
|
+
function createRenderEffect(compute, effectFn, options) {
|
|
359
|
+
serverEffect(compute, effectFn, options);
|
|
257
360
|
}
|
|
258
361
|
function createTrackedEffect(compute, options) {
|
|
259
362
|
const o = getOwner();
|
|
@@ -264,8 +367,8 @@ function createReaction(effectFn, options) {
|
|
|
264
367
|
tracking();
|
|
265
368
|
};
|
|
266
369
|
}
|
|
267
|
-
function createOptimistic(first, second
|
|
268
|
-
return createSignal(first, second
|
|
370
|
+
function createOptimistic(first, second) {
|
|
371
|
+
return createSignal(first, second);
|
|
269
372
|
}
|
|
270
373
|
function setProperty(state, property, value) {
|
|
271
374
|
if (state[property] === value) return;
|
|
@@ -275,7 +378,7 @@ function setProperty(state, property, value) {
|
|
|
275
378
|
}
|
|
276
379
|
function createStore(first, second) {
|
|
277
380
|
if (typeof first === "function") {
|
|
278
|
-
const store = createProjection(first, second
|
|
381
|
+
const store = createProjection(first, second);
|
|
279
382
|
return [store, fn => fn(store)];
|
|
280
383
|
}
|
|
281
384
|
const state = first;
|
|
@@ -298,11 +401,11 @@ function createPendingProxy(state, source) {
|
|
|
298
401
|
pending = false;
|
|
299
402
|
}];
|
|
300
403
|
}
|
|
301
|
-
function createProjection(fn, initialValue
|
|
404
|
+
function createProjection(fn, initialValue, options) {
|
|
302
405
|
const ctx = sharedConfig.context;
|
|
303
406
|
const owner = createOwner();
|
|
304
407
|
const [state] = createStore(initialValue);
|
|
305
|
-
if (options?.ssrSource === "
|
|
408
|
+
if (options?.ssrSource === "client") {
|
|
306
409
|
return state;
|
|
307
410
|
}
|
|
308
411
|
let disposed = false;
|
|
@@ -313,100 +416,131 @@ function createProjection(fn, initialValue = {}, options) {
|
|
|
313
416
|
const useProxy = ssrSource !== "hybrid";
|
|
314
417
|
const patches = [];
|
|
315
418
|
const draft = useProxy ? createDeepProxy(state, patches) : state;
|
|
316
|
-
const
|
|
419
|
+
const runProjection = () => runWithOwner(owner, () => fn(draft));
|
|
420
|
+
const result = runProjection();
|
|
317
421
|
const iteratorFn = result?.[Symbol.asyncIterator];
|
|
318
422
|
if (typeof iteratorFn === "function") {
|
|
319
|
-
const iter = iteratorFn.call(result);
|
|
320
423
|
if (ssrSource === "hybrid") {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
424
|
+
let currentResult = result;
|
|
425
|
+
let iter;
|
|
426
|
+
const deferred = createDeferredPromise();
|
|
427
|
+
const [pending, markReady] = createPendingProxy(state, deferred.promise);
|
|
428
|
+
const runFirst = () => {
|
|
429
|
+
const source = currentResult ?? runProjection();
|
|
430
|
+
currentResult = undefined;
|
|
431
|
+
const nextIterator = source?.[Symbol.asyncIterator];
|
|
432
|
+
if (typeof nextIterator !== "function") {
|
|
433
|
+
throw new Error("Expected async iterator while retrying server createProjection");
|
|
326
434
|
}
|
|
327
|
-
|
|
328
|
-
|
|
435
|
+
iter = nextIterator.call(source);
|
|
436
|
+
return iter.next().then(r => {
|
|
437
|
+
if (!r.done) closeAsyncIterator(iter);
|
|
438
|
+
return r.value;
|
|
439
|
+
});
|
|
440
|
+
};
|
|
441
|
+
settleServerAsync(runFirst(), runFirst, deferred, value => {
|
|
442
|
+
if (value !== undefined && value !== state) {
|
|
443
|
+
Object.assign(state, value);
|
|
329
444
|
}
|
|
330
|
-
promise.v = state;
|
|
331
445
|
markReady();
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
446
|
+
return state;
|
|
447
|
+
}, error => {
|
|
448
|
+
markReady();
|
|
449
|
+
}, () => disposed);
|
|
450
|
+
if (ctx?.async && !getContext(NoHydrateContext) && owner.id) ctx.serialize(owner.id, deferred.promise, options?.deferStream);
|
|
335
451
|
return pending;
|
|
336
452
|
} else {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
453
|
+
let currentResult = result;
|
|
454
|
+
let iter;
|
|
455
|
+
let firstResult;
|
|
456
|
+
const deferred = createDeferredPromise();
|
|
457
|
+
const [pending, markReady] = createPendingProxy(state, deferred.promise);
|
|
458
|
+
const runFirst = () => {
|
|
459
|
+
const source = currentResult ?? runProjection();
|
|
460
|
+
currentResult = undefined;
|
|
461
|
+
const nextIterator = source?.[Symbol.asyncIterator];
|
|
462
|
+
if (typeof nextIterator !== "function") {
|
|
463
|
+
throw new Error("Expected async iterator while retrying server createProjection");
|
|
464
|
+
}
|
|
465
|
+
iter = nextIterator.call(source);
|
|
466
|
+
return iter.next().then(value => {
|
|
467
|
+
firstResult = value;
|
|
468
|
+
return Promise.resolve();
|
|
469
|
+
});
|
|
470
|
+
};
|
|
471
|
+
settleServerAsync(runFirst(), runFirst, deferred, () => {
|
|
340
472
|
patches.length = 0;
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
}
|
|
473
|
+
const resolved = firstResult;
|
|
474
|
+
if (resolved && !resolved.done && resolved.value !== undefined && resolved.value !== draft) {
|
|
475
|
+
Object.assign(state, resolved.value);
|
|
345
476
|
}
|
|
346
477
|
markReady(JSON.parse(JSON.stringify(state)));
|
|
347
|
-
|
|
478
|
+
return undefined;
|
|
479
|
+
}, error => {
|
|
348
480
|
markReady();
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
done
|
|
359
|
-
|
|
481
|
+
}, () => disposed);
|
|
482
|
+
if (ctx?.async && !getContext(NoHydrateContext) && owner.id) {
|
|
483
|
+
let tappedFirst = true;
|
|
484
|
+
const tapped = {
|
|
485
|
+
[Symbol.asyncIterator]: () => ({
|
|
486
|
+
next() {
|
|
487
|
+
if (tappedFirst) {
|
|
488
|
+
tappedFirst = false;
|
|
489
|
+
return deferred.promise.then(() => {
|
|
490
|
+
if (firstResult?.done) return {
|
|
491
|
+
done: true,
|
|
492
|
+
value: undefined
|
|
493
|
+
};
|
|
494
|
+
return {
|
|
495
|
+
done: false,
|
|
496
|
+
value: JSON.parse(JSON.stringify(state))
|
|
497
|
+
};
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
return iter.next().then(r => {
|
|
501
|
+
if (disposed) return {
|
|
502
|
+
done: true,
|
|
503
|
+
value: undefined
|
|
360
504
|
};
|
|
505
|
+
const flushed = patches.splice(0);
|
|
506
|
+
if (!r.done) {
|
|
507
|
+
if (r.value !== undefined && r.value !== draft) {
|
|
508
|
+
Object.assign(state, r.value);
|
|
509
|
+
}
|
|
510
|
+
return {
|
|
511
|
+
done: false,
|
|
512
|
+
value: flushed
|
|
513
|
+
};
|
|
514
|
+
}
|
|
361
515
|
return {
|
|
362
|
-
done:
|
|
516
|
+
done: true,
|
|
363
517
|
value: undefined
|
|
364
518
|
};
|
|
365
519
|
});
|
|
520
|
+
},
|
|
521
|
+
return(value) {
|
|
522
|
+
return iter.return?.(value);
|
|
366
523
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
};
|
|
372
|
-
const flushed = patches.splice(0);
|
|
373
|
-
if (!r.done) {
|
|
374
|
-
if (r.value !== undefined && r.value !== draft) {
|
|
375
|
-
Object.assign(state, r.value);
|
|
376
|
-
}
|
|
377
|
-
return {
|
|
378
|
-
done: false,
|
|
379
|
-
value: flushed
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
return {
|
|
383
|
-
done: true,
|
|
384
|
-
value: undefined
|
|
385
|
-
};
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
})
|
|
389
|
-
};
|
|
390
|
-
if (ctx?.async && !ctx.noHydrate && owner.id) ctx.serialize(owner.id, tapped, options?.deferStream);
|
|
391
|
-
const [pending, markReady] = createPendingProxy(state, firstReady);
|
|
524
|
+
})
|
|
525
|
+
};
|
|
526
|
+
ctx.serialize(owner.id, tapped, options?.deferStream);
|
|
527
|
+
}
|
|
392
528
|
return pending;
|
|
393
529
|
}
|
|
394
530
|
}
|
|
395
531
|
if (result instanceof Promise) {
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
532
|
+
const deferred = createDeferredPromise();
|
|
533
|
+
const [pending, markReady] = createPendingProxy(state, deferred.promise);
|
|
534
|
+
settleServerAsync(result, () => runProjection(), deferred, value => {
|
|
535
|
+
if (value !== undefined && value !== state) {
|
|
536
|
+
Object.assign(state, value);
|
|
401
537
|
}
|
|
402
|
-
if (v !== undefined && v !== state) {
|
|
403
|
-
Object.assign(state, v);
|
|
404
|
-
}
|
|
405
|
-
promise.v = state;
|
|
406
538
|
markReady();
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
539
|
+
return state;
|
|
540
|
+
}, error => {
|
|
541
|
+
markReady();
|
|
542
|
+
}, () => disposed);
|
|
543
|
+
if (ctx?.async && !getContext(NoHydrateContext) && owner.id) ctx.serialize(owner.id, deferred.promise, options?.deferStream);
|
|
410
544
|
return pending;
|
|
411
545
|
}
|
|
412
546
|
if (result !== undefined && result !== state && result !== draft) {
|
|
@@ -433,68 +567,111 @@ function deep(store) {
|
|
|
433
567
|
return store;
|
|
434
568
|
}
|
|
435
569
|
function mapArray(list, mapFn, options = {}) {
|
|
436
|
-
const
|
|
437
|
-
|
|
438
|
-
return () => {
|
|
570
|
+
const parent = createOwner();
|
|
571
|
+
return createMemo(() => {
|
|
439
572
|
const items = list();
|
|
440
573
|
let s = [];
|
|
441
574
|
if (items && items.length) {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
}
|
|
448
|
-
} else if (options.fallback)
|
|
575
|
+
runWithOwner(parent, () => {
|
|
576
|
+
for (let i = 0, len = items.length; i < len; i++) {
|
|
577
|
+
const o = createOwner();
|
|
578
|
+
s.push(runWithOwner(o, () => mapFn(() => items[i], () => i)));
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
} else if (options.fallback) {
|
|
582
|
+
s = [runWithOwner(parent, () => {
|
|
583
|
+
const fo = createOwner();
|
|
584
|
+
return runWithOwner(fo, () => options.fallback());
|
|
585
|
+
})];
|
|
586
|
+
}
|
|
449
587
|
return s;
|
|
450
|
-
};
|
|
588
|
+
});
|
|
451
589
|
}
|
|
452
590
|
function repeat(count, mapFn, options = {}) {
|
|
453
591
|
const owner = createOwner();
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
const
|
|
461
|
-
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
592
|
+
return createMemo(() => {
|
|
593
|
+
const len = count();
|
|
594
|
+
const offset = options.from?.() || 0;
|
|
595
|
+
if (!len) {
|
|
596
|
+
if (!options.fallback) return [];
|
|
597
|
+
return [runWithOwner(owner, () => {
|
|
598
|
+
const fallbackOwner = createOwner();
|
|
599
|
+
return runWithOwner(fallbackOwner, () => options.fallback());
|
|
600
|
+
})];
|
|
601
|
+
}
|
|
602
|
+
return runWithOwner(owner, () => Array.from({
|
|
603
|
+
length: len
|
|
604
|
+
}, (_, i) => {
|
|
605
|
+
const itemOwner = createOwner();
|
|
606
|
+
return runWithOwner(itemOwner, () => mapFn(i + offset));
|
|
607
|
+
}));
|
|
608
|
+
});
|
|
471
609
|
}
|
|
472
610
|
const ErrorContext = {
|
|
473
611
|
id: Symbol("ErrorContext"),
|
|
474
612
|
defaultValue: null
|
|
475
613
|
};
|
|
614
|
+
function runWithBoundaryErrorContext(owner, render, onError, context, boundaryId) {
|
|
615
|
+
const prevCtx = sharedConfig.context;
|
|
616
|
+
const prevBoundary = context?._currentBoundaryId;
|
|
617
|
+
if (context) {
|
|
618
|
+
sharedConfig.context = context;
|
|
619
|
+
if (boundaryId !== undefined) context._currentBoundaryId = boundaryId;
|
|
620
|
+
}
|
|
621
|
+
try {
|
|
622
|
+
return runWithOwner(owner, () => {
|
|
623
|
+
const parentHandler = getContext(ErrorContext);
|
|
624
|
+
setContext(ErrorContext, err => onError(err, parentHandler));
|
|
625
|
+
return render();
|
|
626
|
+
});
|
|
627
|
+
} finally {
|
|
628
|
+
if (context) {
|
|
629
|
+
if (boundaryId !== undefined) context._currentBoundaryId = prevBoundary;
|
|
630
|
+
sharedConfig.context = prevCtx;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
}
|
|
476
634
|
function createErrorBoundary(fn, fallback) {
|
|
477
635
|
const ctx = sharedConfig.context;
|
|
478
|
-
const owner = createOwner();
|
|
479
636
|
const parent = getOwner();
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
637
|
+
const owner = createOwner();
|
|
638
|
+
const resolve = () => {
|
|
639
|
+
const resolved = ctx.resolve(runWithOwner(createOwner(), fn));
|
|
640
|
+
if (resolved?.p?.length) throw new NotReadyError(Promise.all(resolved.p));
|
|
641
|
+
return resolved;
|
|
642
|
+
};
|
|
643
|
+
const renderFallback = err => ctx ? runWithOwner(parent, () => {
|
|
644
|
+
const fallbackOwner = createOwner();
|
|
645
|
+
return runWithOwner(fallbackOwner, () => fallback(err, () => {}));
|
|
646
|
+
}) : fallback(err, () => {});
|
|
647
|
+
const serializeError = err => {
|
|
648
|
+
if (ctx && owner.id && !runWithOwner(owner, () => getContext(NoHydrateContext))) {
|
|
649
|
+
ctx.serialize(owner.id, err);
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
const handleError = err => {
|
|
653
|
+
serializeError(err);
|
|
654
|
+
return renderFallback(err);
|
|
655
|
+
};
|
|
656
|
+
return () => {
|
|
483
657
|
let result;
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
result = fallback(err, () => {});
|
|
487
|
-
});
|
|
658
|
+
let handled = false;
|
|
659
|
+
if (ctx) owner.dispose(false);
|
|
488
660
|
try {
|
|
489
|
-
result =
|
|
661
|
+
result = ctx ? runWithBoundaryErrorContext(owner, resolve, err => {
|
|
662
|
+
if (err instanceof NotReadyError) throw err;
|
|
663
|
+
handled = true;
|
|
664
|
+
result = handleError(err);
|
|
665
|
+
throw err;
|
|
666
|
+
}) : runWithOwner(owner, fn);
|
|
490
667
|
} catch (err) {
|
|
491
|
-
if (
|
|
492
|
-
result =
|
|
668
|
+
if (err instanceof NotReadyError) throw err;
|
|
669
|
+
result = handled ? result : handleError(err);
|
|
493
670
|
}
|
|
494
|
-
return
|
|
495
|
-
}
|
|
671
|
+
return result;
|
|
672
|
+
};
|
|
496
673
|
}
|
|
497
|
-
function
|
|
674
|
+
function createLoadingBoundary$1(fn, fallback, options) {
|
|
498
675
|
try {
|
|
499
676
|
const result = fn();
|
|
500
677
|
return () => result;
|
|
@@ -505,6 +682,10 @@ function createLoadBoundary(fn, fallback) {
|
|
|
505
682
|
throw err;
|
|
506
683
|
}
|
|
507
684
|
}
|
|
685
|
+
function createRevealOrder(fn, _options) {
|
|
686
|
+
const o = createOwner();
|
|
687
|
+
return runWithOwner(o, fn);
|
|
688
|
+
}
|
|
508
689
|
function untrack(fn) {
|
|
509
690
|
return fn();
|
|
510
691
|
}
|
|
@@ -557,10 +738,10 @@ function useContext(context) {
|
|
|
557
738
|
return getContext(context);
|
|
558
739
|
}
|
|
559
740
|
function children(fn) {
|
|
560
|
-
const c = createMemo(fn,
|
|
741
|
+
const c = createMemo(fn, {
|
|
561
742
|
lazy: true
|
|
562
743
|
});
|
|
563
|
-
const memo = createMemo(() => flatten(c()),
|
|
744
|
+
const memo = createMemo(() => flatten(c()), {
|
|
564
745
|
lazy: true
|
|
565
746
|
});
|
|
566
747
|
memo.toArray = () => {
|
|
@@ -570,7 +751,9 @@ function children(fn) {
|
|
|
570
751
|
return memo;
|
|
571
752
|
}
|
|
572
753
|
function ssrRunInScope(fn) {
|
|
573
|
-
|
|
754
|
+
const owner = getOwner();
|
|
755
|
+
if (!owner) return fn;
|
|
756
|
+
return Array.isArray(fn) ? fn.map(hole => () => runWithOwner(owner, hole)) : () => runWithOwner(owner, fn);
|
|
574
757
|
}
|
|
575
758
|
|
|
576
759
|
function enableHydration() {}
|
|
@@ -589,20 +772,23 @@ function lazy(fn, moduleUrl) {
|
|
|
589
772
|
return p;
|
|
590
773
|
};
|
|
591
774
|
const wrap = props => {
|
|
592
|
-
|
|
775
|
+
const noHydrate = getContext(NoHydrateContext);
|
|
776
|
+
if (!noHydrate && !moduleUrl) {
|
|
593
777
|
throw new Error("lazy() used in SSR without a moduleUrl. " + "All lazy() components require a moduleUrl for correct hydration. " + "This is typically injected by the bundler plugin.");
|
|
594
778
|
}
|
|
595
|
-
if (!sharedConfig.context?.resolveAssets) {
|
|
779
|
+
if (!noHydrate && !sharedConfig.context?.resolveAssets) {
|
|
596
780
|
throw new Error(`lazy() called with moduleUrl "${moduleUrl}" but no asset manifest is set. ` + "Pass a manifest option to renderToStream/renderToString.");
|
|
597
781
|
}
|
|
598
782
|
load();
|
|
599
783
|
const ctx = sharedConfig.context;
|
|
600
|
-
if (!ctx?.registerAsset || !ctx.resolveAssets) return;
|
|
784
|
+
if (!ctx?.registerAsset || !ctx.resolveAssets || !moduleUrl) return;
|
|
601
785
|
const assets = ctx.resolveAssets(moduleUrl);
|
|
602
786
|
if (assets) {
|
|
603
787
|
for (let i = 0; i < assets.css.length; i++) ctx.registerAsset("style", assets.css[i]);
|
|
604
|
-
|
|
605
|
-
|
|
788
|
+
if (!noHydrate) {
|
|
789
|
+
for (let i = 0; i < assets.js.length; i++) ctx.registerAsset("module", assets.js[i]);
|
|
790
|
+
ctx.registerModule?.(moduleUrl, assets.js[0]);
|
|
791
|
+
}
|
|
606
792
|
}
|
|
607
793
|
if (ctx?.async) {
|
|
608
794
|
ctx.block(p.then(() => {
|
|
@@ -615,10 +801,166 @@ function lazy(fn, moduleUrl) {
|
|
|
615
801
|
});
|
|
616
802
|
};
|
|
617
803
|
wrap.preload = load;
|
|
804
|
+
wrap.moduleUrl = moduleUrl;
|
|
618
805
|
return wrap;
|
|
619
806
|
}
|
|
620
807
|
function createUniqueId() {
|
|
621
|
-
|
|
808
|
+
const o = getOwner();
|
|
809
|
+
if (!o) throw new Error(`createUniqueId cannot be used outside of a reactive context`);
|
|
810
|
+
return getNextChildId(o);
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
const RevealGroupContext = {
|
|
814
|
+
id: Symbol("RevealGroupContext"),
|
|
815
|
+
defaultValue: null
|
|
816
|
+
};
|
|
817
|
+
function ssrHandleError(err) {
|
|
818
|
+
if (err instanceof NotReadyError) {
|
|
819
|
+
return err.source;
|
|
820
|
+
}
|
|
821
|
+
const handler = getContext(ErrorContext);
|
|
822
|
+
if (handler) {
|
|
823
|
+
handler(err);
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
throw err;
|
|
827
|
+
}
|
|
828
|
+
function createLoadingBoundary(fn, fallback, options) {
|
|
829
|
+
const currentCtx = sharedConfig.context;
|
|
830
|
+
if (!currentCtx) {
|
|
831
|
+
return createLoadingBoundary$1(fn, fallback);
|
|
832
|
+
}
|
|
833
|
+
const ctx = currentCtx;
|
|
834
|
+
const parent = getOwner();
|
|
835
|
+
const parentHandler = parent && runWithOwner(parent, () => getContext(ErrorContext));
|
|
836
|
+
const revealGroup = parent && runWithOwner(parent, () => getContext(RevealGroupContext));
|
|
837
|
+
const o = createOwner();
|
|
838
|
+
const id = o.id;
|
|
839
|
+
o.id = id + "00";
|
|
840
|
+
let done;
|
|
841
|
+
let handledRenderError;
|
|
842
|
+
let retryPromise;
|
|
843
|
+
let serializeBuffer = [];
|
|
844
|
+
const bufferedCtx = Object.create(ctx);
|
|
845
|
+
bufferedCtx.serialize = (id, value, deferStream) => {
|
|
846
|
+
serializeBuffer.push([id, value, deferStream]);
|
|
847
|
+
};
|
|
848
|
+
bufferedCtx._currentBoundaryId = id;
|
|
849
|
+
function flushSerializeBuffer() {
|
|
850
|
+
for (const args of serializeBuffer) ctx.serialize(args[0], args[1], args[2]);
|
|
851
|
+
serializeBuffer = [];
|
|
852
|
+
}
|
|
853
|
+
function commitBoundaryState() {
|
|
854
|
+
flushSerializeBuffer();
|
|
855
|
+
const modules = ctx.getBoundaryModules?.(id);
|
|
856
|
+
if (modules) ctx.serialize(id + "_assets", modules);
|
|
857
|
+
}
|
|
858
|
+
function runLoadingPhase(render) {
|
|
859
|
+
handledRenderError = undefined;
|
|
860
|
+
return runWithBoundaryErrorContext(o, render, (err, parentHandler) => {
|
|
861
|
+
handledRenderError = err;
|
|
862
|
+
if (done?.(undefined, err)) throw err;
|
|
863
|
+
if (parentHandler) {
|
|
864
|
+
parentHandler(err);
|
|
865
|
+
return;
|
|
866
|
+
}
|
|
867
|
+
throw err;
|
|
868
|
+
}, bufferedCtx, id);
|
|
869
|
+
}
|
|
870
|
+
function finalizeError(err) {
|
|
871
|
+
if (handledRenderError === err) {
|
|
872
|
+
handledRenderError = undefined;
|
|
873
|
+
return;
|
|
874
|
+
}
|
|
875
|
+
if (done?.(undefined, err)) return;
|
|
876
|
+
if (!parentHandler) throw err;
|
|
877
|
+
try {
|
|
878
|
+
runWithOwner(parent, () => parentHandler(err));
|
|
879
|
+
} catch (caught) {
|
|
880
|
+
if (caught !== err) throw caught;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
function runDiscovery() {
|
|
884
|
+
o.dispose(false);
|
|
885
|
+
serializeBuffer = [];
|
|
886
|
+
retryPromise = undefined;
|
|
887
|
+
return runLoadingPhase(() => {
|
|
888
|
+
try {
|
|
889
|
+
return ctx.resolve(fn());
|
|
890
|
+
} catch (err) {
|
|
891
|
+
if (err instanceof NotReadyError) {
|
|
892
|
+
retryPromise = err.source;
|
|
893
|
+
return undefined;
|
|
894
|
+
}
|
|
895
|
+
throw err;
|
|
896
|
+
}
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
let ret = runDiscovery();
|
|
900
|
+
if (!retryPromise && !ret?.p?.length) {
|
|
901
|
+
commitBoundaryState();
|
|
902
|
+
return () => ret;
|
|
903
|
+
}
|
|
904
|
+
const regResult = revealGroup ? revealGroup.register(id) : null;
|
|
905
|
+
const collapseFallback = regResult?.collapseFallback ?? false;
|
|
906
|
+
if (collapseFallback && !ctx.async) {
|
|
907
|
+
commitBoundaryState();
|
|
908
|
+
ctx.serialize(id, "$$f");
|
|
909
|
+
return () => undefined;
|
|
910
|
+
}
|
|
911
|
+
const fallbackOwner = createOwner({
|
|
912
|
+
id
|
|
913
|
+
});
|
|
914
|
+
const fallbackResult = runWithOwner(fallbackOwner, () => {
|
|
915
|
+
if (!ctx.async) return fallback();
|
|
916
|
+
const tpl = collapseFallback ? [`<template id="pl-${id}">`, `</template><!--pl-${id}-->`] : [`<template id="pl-${id}"></template>`, `<!--pl-${id}-->`];
|
|
917
|
+
return ctx.ssr(tpl, ctx.escape(fallback()));
|
|
918
|
+
});
|
|
919
|
+
if (ctx.async) {
|
|
920
|
+
const regOpts = revealGroup ? {
|
|
921
|
+
revealGroup: revealGroup.id
|
|
922
|
+
} : undefined;
|
|
923
|
+
done = ctx.registerFragment(id, regOpts);
|
|
924
|
+
(async () => {
|
|
925
|
+
try {
|
|
926
|
+
while (retryPromise) {
|
|
927
|
+
await retryPromise.catch(() => {});
|
|
928
|
+
ret = runDiscovery();
|
|
929
|
+
}
|
|
930
|
+
commitBoundaryState();
|
|
931
|
+
while (ret.p.length) {
|
|
932
|
+
await Promise.all(ret.p).catch(() => {});
|
|
933
|
+
ret = runLoadingPhase(() => ctx.ssr(ret.t, ...ret.h));
|
|
934
|
+
}
|
|
935
|
+
flushSerializeBuffer();
|
|
936
|
+
done(ret.t[0]);
|
|
937
|
+
if (revealGroup) revealGroup.onResolved(id);
|
|
938
|
+
} catch (err) {
|
|
939
|
+
finalizeError(err);
|
|
940
|
+
}
|
|
941
|
+
})();
|
|
942
|
+
return () => fallbackResult;
|
|
943
|
+
}
|
|
944
|
+
commitBoundaryState();
|
|
945
|
+
ctx.serialize(id, "$$f");
|
|
946
|
+
return () => fallbackResult;
|
|
947
|
+
}
|
|
948
|
+
function NoHydration(props) {
|
|
949
|
+
const o = createOwner();
|
|
950
|
+
return runWithOwner(o, () => {
|
|
951
|
+
setContext(NoHydrateContext, true);
|
|
952
|
+
return props.children;
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
function Hydration(props) {
|
|
956
|
+
if (!getContext(NoHydrateContext)) return props.children;
|
|
957
|
+
const o = createOwner({
|
|
958
|
+
id: props.id ?? ""
|
|
959
|
+
});
|
|
960
|
+
return runWithOwner(o, () => {
|
|
961
|
+
setContext(NoHydrateContext, false);
|
|
962
|
+
return props.children;
|
|
963
|
+
});
|
|
622
964
|
}
|
|
623
965
|
|
|
624
966
|
function For(props) {
|
|
@@ -628,7 +970,7 @@ function For(props) {
|
|
|
628
970
|
} : {
|
|
629
971
|
keyed: props.keyed
|
|
630
972
|
};
|
|
631
|
-
return
|
|
973
|
+
return mapArray(() => props.each, props.children, options);
|
|
632
974
|
}
|
|
633
975
|
function Repeat(props) {
|
|
634
976
|
const options = "fallback" in props ? {
|
|
@@ -681,91 +1023,182 @@ function Errored(props) {
|
|
|
681
1023
|
return typeof f === "function" && f.length ? f(err, reset) : f;
|
|
682
1024
|
});
|
|
683
1025
|
}
|
|
684
|
-
|
|
685
|
-
function ssrHandleError(err) {
|
|
686
|
-
if (err instanceof NotReadyError) {
|
|
687
|
-
return err.source;
|
|
688
|
-
}
|
|
689
|
-
const handler = getContext(ErrorContext);
|
|
690
|
-
if (handler) {
|
|
691
|
-
handler(err);
|
|
692
|
-
return;
|
|
693
|
-
}
|
|
694
|
-
throw err;
|
|
695
|
-
}
|
|
696
1026
|
function Loading(props) {
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
}
|
|
1027
|
+
return createLoadingBoundary(() => props.children, () => props.fallback);
|
|
1028
|
+
}
|
|
1029
|
+
function Reveal(props) {
|
|
701
1030
|
const o = createOwner();
|
|
702
1031
|
const id = o.id;
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
1032
|
+
const order = props.order ?? "sequential";
|
|
1033
|
+
const collapsed = order === "sequential" && !!props.collapsed;
|
|
1034
|
+
if (!sharedConfig.context?.async) {
|
|
1035
|
+
const parent = getOwner();
|
|
1036
|
+
const parentGroup = parent ? runWithOwner(parent, () => getContext(RevealGroupContext)) : null;
|
|
1037
|
+
let collapsedByParent = false;
|
|
1038
|
+
if (parentGroup) {
|
|
1039
|
+
const reg = parentGroup.register(id);
|
|
1040
|
+
collapsedByParent = reg.collapseFallback;
|
|
1041
|
+
if (order === "together" || collapsed) console.warn("Nested <Reveal> with collapsed/together won't coordinate correctly with renderToString. Use renderToStream for full support.");
|
|
1042
|
+
}
|
|
1043
|
+
let count = 0;
|
|
1044
|
+
return runWithOwner(o, () => {
|
|
1045
|
+
setContext(RevealGroupContext, {
|
|
1046
|
+
id,
|
|
1047
|
+
register(_key) {
|
|
1048
|
+
count++;
|
|
1049
|
+
const collapseFallback = collapsedByParent || order === "sequential" && collapsed && count > 1;
|
|
1050
|
+
return {
|
|
1051
|
+
collapseFallback,
|
|
1052
|
+
held: false
|
|
1053
|
+
};
|
|
1054
|
+
},
|
|
1055
|
+
onResolved() {}
|
|
1056
|
+
});
|
|
1057
|
+
return props.children;
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
const ctx = sharedConfig.context;
|
|
1061
|
+
const keys = [];
|
|
1062
|
+
const resolved = new Set();
|
|
1063
|
+
const minimallyResolved = new Set();
|
|
1064
|
+
const composites = new Map();
|
|
1065
|
+
const activated = new Set();
|
|
1066
|
+
const stash = [];
|
|
1067
|
+
const collapsedLeafKeys = [];
|
|
1068
|
+
let frontier = 0;
|
|
1069
|
+
let heldByParent = false;
|
|
1070
|
+
let collapsedByParent = false;
|
|
1071
|
+
let selfMinimallyResolved = false;
|
|
1072
|
+
let notifiedParentDone = false;
|
|
1073
|
+
const parent = getOwner();
|
|
1074
|
+
const parentGroup = parent ? runWithOwner(parent, () => getContext(RevealGroupContext)) : null;
|
|
1075
|
+
if (parentGroup) {
|
|
1076
|
+
const reg = parentGroup.register(id, {
|
|
1077
|
+
onActivate: () => {
|
|
1078
|
+
if (!heldByParent) return;
|
|
1079
|
+
heldByParent = false;
|
|
1080
|
+
if (collapsedByParent) {
|
|
1081
|
+
collapsedByParent = false;
|
|
1082
|
+
if (collapsedLeafKeys.length) {
|
|
1083
|
+
ctx.revealFallbacks?.([...collapsedLeafKeys]);
|
|
1084
|
+
collapsedLeafKeys.length = 0;
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
if (order === "sequential") advanceFrontier();else if (order === "together") checkTogetherRelease();else naturalRelease();
|
|
720
1088
|
}
|
|
721
1089
|
});
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
return result;
|
|
1090
|
+
collapsedByParent = reg.collapseFallback;
|
|
1091
|
+
heldByParent = reg.held;
|
|
725
1092
|
}
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
return ret;
|
|
1093
|
+
function notifyParentIfDone() {
|
|
1094
|
+
if (notifiedParentDone) return;
|
|
1095
|
+
if (parentGroup && resolved.size === keys.length) {
|
|
1096
|
+
notifiedParentDone = true;
|
|
1097
|
+
parentGroup.onResolved(id);
|
|
1098
|
+
}
|
|
733
1099
|
}
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
1100
|
+
function activateComposite(key) {
|
|
1101
|
+
if (activated.has(key)) return;
|
|
1102
|
+
activated.add(key);
|
|
1103
|
+
composites.get(key)();
|
|
1104
|
+
}
|
|
1105
|
+
function updateSelfMinimallyResolved() {
|
|
1106
|
+
if (selfMinimallyResolved) return;
|
|
1107
|
+
if (keys.length === 0) selfMinimallyResolved = true;else if (order === "together") selfMinimallyResolved = minimallyResolved.size === keys.length;else if (order === "sequential") selfMinimallyResolved = minimallyResolved.has(keys[0]);
|
|
1108
|
+
else selfMinimallyResolved = resolved.size > 0;
|
|
1109
|
+
if (selfMinimallyResolved) parentGroup?.onMinimallyResolved?.(id);
|
|
1110
|
+
}
|
|
1111
|
+
function advanceFrontier() {
|
|
1112
|
+
if (heldByParent) return;
|
|
1113
|
+
while (frontier < keys.length && resolved.has(keys[frontier])) {
|
|
1114
|
+
const k = keys[frontier];
|
|
1115
|
+
if (composites.has(k)) activateComposite(k);else ctx.revealFragments?.([k]);
|
|
1116
|
+
frontier++;
|
|
1117
|
+
}
|
|
1118
|
+
if (frontier < keys.length) {
|
|
1119
|
+
const k = keys[frontier];
|
|
1120
|
+
if (composites.has(k)) activateComposite(k);else if (order === "sequential" && collapsed) ctx.revealFallbacks?.([k]);
|
|
1121
|
+
}
|
|
1122
|
+
notifyParentIfDone();
|
|
1123
|
+
}
|
|
1124
|
+
function checkTogetherRelease() {
|
|
1125
|
+
if (order !== "together" || heldByParent) return;
|
|
1126
|
+
if (minimallyResolved.size < keys.length) return;
|
|
1127
|
+
if (stash.length) {
|
|
1128
|
+
ctx.revealFragments?.([...stash]);
|
|
1129
|
+
stash.length = 0;
|
|
1130
|
+
}
|
|
1131
|
+
composites.forEach((_, key) => activateComposite(key));
|
|
1132
|
+
notifyParentIfDone();
|
|
1133
|
+
}
|
|
1134
|
+
function naturalRelease() {
|
|
1135
|
+
if (stash.length) {
|
|
1136
|
+
ctx.revealFragments?.([...stash]);
|
|
1137
|
+
stash.length = 0;
|
|
1138
|
+
}
|
|
1139
|
+
composites.forEach((_, key) => activateComposite(key));
|
|
1140
|
+
notifyParentIfDone();
|
|
1141
|
+
}
|
|
1142
|
+
return runWithOwner(o, () => {
|
|
1143
|
+
setContext(RevealGroupContext, {
|
|
1144
|
+
id,
|
|
1145
|
+
register(key, options) {
|
|
1146
|
+
keys.push(key);
|
|
1147
|
+
const isComposite = !!options?.onActivate;
|
|
1148
|
+
if (isComposite) composites.set(key, options.onActivate);
|
|
1149
|
+
const selfCollapse = order === "sequential" && collapsed && keys.length > 1;
|
|
1150
|
+
const collapseFallback = collapsedByParent || selfCollapse;
|
|
1151
|
+
if (collapseFallback && !isComposite) collapsedLeafKeys.push(key);
|
|
1152
|
+
let held = heldByParent;
|
|
1153
|
+
if (!held) {
|
|
1154
|
+
if (order === "together") held = true;else if (order === "sequential" && keys.length > 1) held = true;
|
|
747
1155
|
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
1156
|
+
return {
|
|
1157
|
+
collapseFallback,
|
|
1158
|
+
held
|
|
1159
|
+
};
|
|
1160
|
+
},
|
|
1161
|
+
onResolved(key) {
|
|
1162
|
+
resolved.add(key);
|
|
1163
|
+
const isLeaf = !composites.has(key);
|
|
1164
|
+
if (isLeaf) {
|
|
1165
|
+
if (order === "together") {
|
|
1166
|
+
stash.push(key);
|
|
1167
|
+
} else if (order === "natural" && heldByParent) {
|
|
1168
|
+
stash.push(key);
|
|
1169
|
+
} else if (order === "natural") {
|
|
1170
|
+
ctx.revealFragments?.([key]);
|
|
1171
|
+
}
|
|
1172
|
+
markMinimallyResolved(key);
|
|
1173
|
+
if (order === "sequential" && !heldByParent) advanceFrontier();
|
|
1174
|
+
if (order === "natural") updateSelfMinimallyResolved();
|
|
1175
|
+
} else {
|
|
1176
|
+
if (!heldByParent) {
|
|
1177
|
+
if (order === "sequential") advanceFrontier();else if (order === "natural") activateComposite(key);
|
|
1178
|
+
}
|
|
1179
|
+
if (order === "together") checkTogetherRelease();
|
|
1180
|
+
if (order === "natural") updateSelfMinimallyResolved();
|
|
753
1181
|
}
|
|
754
|
-
|
|
755
|
-
}
|
|
756
|
-
|
|
1182
|
+
notifyParentIfDone();
|
|
1183
|
+
},
|
|
1184
|
+
onMinimallyResolved(key) {
|
|
1185
|
+
markMinimallyResolved(key);
|
|
757
1186
|
}
|
|
758
|
-
})
|
|
759
|
-
|
|
1187
|
+
});
|
|
1188
|
+
const result = props.children;
|
|
1189
|
+
if (parentGroup && keys.length === 0) {
|
|
1190
|
+
parentGroup.onResolved(id);
|
|
1191
|
+
}
|
|
1192
|
+
return result;
|
|
1193
|
+
});
|
|
1194
|
+
function markMinimallyResolved(key) {
|
|
1195
|
+
if (minimallyResolved.has(key)) return;
|
|
1196
|
+
minimallyResolved.add(key);
|
|
1197
|
+
updateSelfMinimallyResolved();
|
|
1198
|
+
if (order === "together") checkTogetherRelease();
|
|
760
1199
|
}
|
|
761
|
-
for (const args of serializeBuffer) origSerialize(args[0], args[1], args[2]);
|
|
762
|
-
serializeBuffer = [];
|
|
763
|
-
const modules = ctx.getBoundaryModules?.(id);
|
|
764
|
-
if (modules) ctx.serialize(id + "_assets", modules);
|
|
765
|
-
ctx.serialize(id, "$$f");
|
|
766
|
-
return runWithOwner(fallbackOwner, () => props.fallback);
|
|
767
1200
|
}
|
|
768
1201
|
|
|
769
1202
|
const DEV = undefined;
|
|
770
1203
|
|
|
771
|
-
export { $DEVCOMP, DEV, Errored, For, Loading, Match, Repeat, Show, Switch, action, children, createComponent, createContext, createDeepProxy, createEffect, createMemo, createOptimistic, createOptimisticStore, createProjection, createReaction, createRenderEffect, createSignal, createStore, createTrackedEffect, createUniqueId, deep, enableHydration, flush, getObserver, isPending, isRefreshing, latest, lazy, mapArray, onSettled, reconcile, refresh, repeat, resolve, sharedConfig, ssrHandleError, ssrRunInScope, untrack, useContext };
|
|
1204
|
+
export { $DEVCOMP, DEV, Errored, For, Hydration, Loading, Match, NoHydrateContext, NoHydration, Repeat, Reveal, Show, Switch, action, children, createComponent, createContext, createDeepProxy, createEffect, createErrorBoundary, createLoadingBoundary, createMemo, createOptimistic, createOptimisticStore, createProjection, createReaction, createRenderEffect, createRevealOrder, createSignal, createStore, createTrackedEffect, createUniqueId, deep, enableHydration, flush, getObserver, isPending, isRefreshing, latest, lazy, mapArray, onSettled, reconcile, refresh, repeat, resolve, sharedConfig, ssrHandleError, ssrRunInScope, untrack, useContext };
|