solid-js 2.0.0-beta.5 → 2.0.0-beta.7
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 +126 -122
- package/dist/dev.js +120 -125
- package/dist/server.cjs +332 -97
- package/dist/server.js +328 -99
- package/dist/solid.cjs +120 -108
- package/dist/solid.js +114 -111
- package/package.json +78 -30
- package/types/client/core.d.ts +1 -8
- package/types/client/flow.d.ts +22 -0
- package/types/client/hydration.d.ts +4 -3
- package/types/index.d.ts +3 -6
- package/types/jsx-properties.d.ts +95 -0
- package/types/jsx.d.ts +438 -359
- package/types/server/flow.d.ts +9 -0
- package/types/server/hydration.d.ts +9 -0
- package/types/server/index.d.ts +1 -1
- package/types/server/shared.d.ts +5 -1
- package/types/server/signals.d.ts +13 -11
- package/types-cjs/client/component.d.cts +75 -0
- package/types-cjs/client/core.d.cts +58 -0
- package/types-cjs/client/flow.d.cts +142 -0
- package/types-cjs/client/hydration.d.cts +96 -0
- package/types-cjs/index.d.cts +17 -0
- package/types-cjs/jsx-properties.d.cts +95 -0
- package/types-cjs/jsx.d.cts +4263 -0
- package/types-cjs/package.json +3 -0
- package/types-cjs/server/component.d.cts +67 -0
- package/types-cjs/server/core.d.cts +44 -0
- package/types-cjs/server/flow.d.cts +82 -0
- package/types-cjs/server/hydration.d.cts +46 -0
- package/types-cjs/server/index.d.cts +12 -0
- package/types-cjs/server/shared.d.cts +50 -0
- package/types-cjs/server/signals.d.cts +67 -0
package/dist/server.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
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, isEqual, isWrappable, merge, omit, onCleanup, runWithOwner, snapshot, storePath } 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
4
|
const NoHydrateContext = {
|
|
5
5
|
id: Symbol("NoHydrateContext"),
|
|
@@ -27,25 +27,82 @@ function runWithObserver(comp, fn) {
|
|
|
27
27
|
function getObserver() {
|
|
28
28
|
return Observer;
|
|
29
29
|
}
|
|
30
|
-
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) {
|
|
31
88
|
if (typeof first === "function") {
|
|
32
|
-
const opts =
|
|
33
|
-
deferStream:
|
|
34
|
-
ssrSource:
|
|
89
|
+
const opts = second?.deferStream || second?.ssrSource ? {
|
|
90
|
+
deferStream: second?.deferStream,
|
|
91
|
+
ssrSource: second?.ssrSource
|
|
35
92
|
} : undefined;
|
|
36
|
-
const memo = createMemo(prev => first(prev),
|
|
93
|
+
const memo = createMemo(prev => first(prev), opts);
|
|
37
94
|
return [memo, () => undefined];
|
|
38
95
|
}
|
|
39
96
|
return [() => first, v => {
|
|
40
97
|
return first = typeof v === "function" ? v(first) : v;
|
|
41
98
|
}];
|
|
42
99
|
}
|
|
43
|
-
function createMemo(compute,
|
|
100
|
+
function createMemo(compute, options) {
|
|
44
101
|
const ctx = sharedConfig.context;
|
|
45
102
|
const owner = createOwner();
|
|
46
103
|
const comp = {
|
|
47
104
|
owner,
|
|
48
|
-
value:
|
|
105
|
+
value: undefined,
|
|
49
106
|
compute: compute,
|
|
50
107
|
error: undefined,
|
|
51
108
|
computed: false,
|
|
@@ -56,14 +113,15 @@ function createMemo(compute, value, options) {
|
|
|
56
113
|
}));
|
|
57
114
|
function update() {
|
|
58
115
|
if (comp.disposed) return;
|
|
116
|
+
const run = () => runWithOwner(owner, () => runWithObserver(comp, () => comp.compute(comp.value)));
|
|
59
117
|
try {
|
|
60
118
|
comp.error = undefined;
|
|
61
|
-
const result =
|
|
119
|
+
const result = run();
|
|
62
120
|
comp.computed = true;
|
|
63
|
-
processResult(comp, result, owner, ctx, options?.deferStream, options?.ssrSource);
|
|
121
|
+
processResult(comp, result, owner, ctx, options?.deferStream, options?.ssrSource, run);
|
|
64
122
|
} catch (err) {
|
|
65
123
|
if (err instanceof NotReadyError) {
|
|
66
|
-
err
|
|
124
|
+
subscribePendingRetry(err, update);
|
|
67
125
|
}
|
|
68
126
|
comp.error = err;
|
|
69
127
|
comp.computed = true;
|
|
@@ -145,7 +203,7 @@ function createDeepProxy(target, patches, basePath = []) {
|
|
|
145
203
|
};
|
|
146
204
|
return new Proxy(target, handler);
|
|
147
205
|
}
|
|
148
|
-
function processResult(comp, result, owner, ctx, deferStream, ssrSource) {
|
|
206
|
+
function processResult(comp, result, owner, ctx, deferStream, ssrSource, rerun) {
|
|
149
207
|
if (comp.disposed) return;
|
|
150
208
|
const id = owner.id;
|
|
151
209
|
const noHydrate = getContext(NoHydrateContext, owner);
|
|
@@ -159,47 +217,78 @@ function processResult(comp, result, owner, ctx, deferStream, ssrSource) {
|
|
|
159
217
|
comp.error = result.v;
|
|
160
218
|
return;
|
|
161
219
|
}
|
|
162
|
-
|
|
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 => {
|
|
163
223
|
result.s = 1;
|
|
164
|
-
result.v =
|
|
165
|
-
|
|
166
|
-
comp.value = v;
|
|
224
|
+
result.v = value;
|
|
225
|
+
comp.value = value;
|
|
167
226
|
comp.error = undefined;
|
|
168
|
-
|
|
227
|
+
return value;
|
|
228
|
+
}, error => {
|
|
169
229
|
result.s = 2;
|
|
170
|
-
result.v =
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (ctx?.async && ctx.serialize && id && !noHydrate) ctx.serialize(id, result, deferStream);
|
|
175
|
-
comp.error = new NotReadyError(result);
|
|
230
|
+
result.v = error;
|
|
231
|
+
comp.error = error;
|
|
232
|
+
}, () => comp.disposed);
|
|
233
|
+
comp.error = new NotReadyError(deferred.promise);
|
|
176
234
|
return;
|
|
177
235
|
}
|
|
178
236
|
const iterator = result?.[Symbol.asyncIterator];
|
|
179
237
|
if (typeof iterator === "function") {
|
|
180
|
-
const iter = iterator.call(result);
|
|
181
238
|
if (ssrSource === "hybrid") {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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;
|
|
188
257
|
comp.error = undefined;
|
|
189
|
-
return
|
|
190
|
-
},
|
|
191
|
-
|
|
192
|
-
|
|
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);
|
|
193
264
|
} else {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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");
|
|
275
|
+
}
|
|
276
|
+
iter = nextIterator.call(source);
|
|
277
|
+
return iter.next().then(value => {
|
|
278
|
+
firstResult = value;
|
|
279
|
+
return Promise.resolve();
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
settleServerAsync(runFirst(), runFirst, deferred, () => {
|
|
283
|
+
const resolved = firstResult;
|
|
284
|
+
if (resolved && !resolved.done) {
|
|
285
|
+
comp.value = resolved.value;
|
|
199
286
|
}
|
|
200
287
|
comp.error = undefined;
|
|
201
|
-
return
|
|
202
|
-
},
|
|
288
|
+
return undefined;
|
|
289
|
+
}, error => {
|
|
290
|
+
comp.error = error;
|
|
291
|
+
}, () => comp.disposed);
|
|
203
292
|
if (ctx?.async && ctx.serialize && id && !noHydrate) {
|
|
204
293
|
let tappedFirst = true;
|
|
205
294
|
const tapped = {
|
|
@@ -207,7 +296,10 @@ function processResult(comp, result, owner, ctx, deferStream, ssrSource) {
|
|
|
207
296
|
next() {
|
|
208
297
|
if (tappedFirst) {
|
|
209
298
|
tappedFirst = false;
|
|
210
|
-
return
|
|
299
|
+
return deferred.promise.then(() => firstResult?.done ? {
|
|
300
|
+
done: true,
|
|
301
|
+
value: undefined
|
|
302
|
+
} : firstResult);
|
|
211
303
|
}
|
|
212
304
|
return iter.next().then(r => r);
|
|
213
305
|
},
|
|
@@ -218,7 +310,7 @@ function processResult(comp, result, owner, ctx, deferStream, ssrSource) {
|
|
|
218
310
|
};
|
|
219
311
|
ctx.serialize(id, tapped, deferStream);
|
|
220
312
|
}
|
|
221
|
-
comp.error = new NotReadyError(
|
|
313
|
+
comp.error = new NotReadyError(deferred.promise);
|
|
222
314
|
}
|
|
223
315
|
return;
|
|
224
316
|
}
|
|
@@ -230,7 +322,7 @@ function closeAsyncIterator(iter, value) {
|
|
|
230
322
|
returned.then(undefined, () => {});
|
|
231
323
|
}
|
|
232
324
|
}
|
|
233
|
-
function serverEffect(compute, effectFn,
|
|
325
|
+
function serverEffect(compute, effectFn, options) {
|
|
234
326
|
const ssrSource = options?.ssrSource;
|
|
235
327
|
if (ssrSource === "client" || ssrSource === "initial") {
|
|
236
328
|
createOwner();
|
|
@@ -240,7 +332,7 @@ function serverEffect(compute, effectFn, value, options) {
|
|
|
240
332
|
const owner = createOwner();
|
|
241
333
|
const comp = {
|
|
242
334
|
owner,
|
|
243
|
-
value:
|
|
335
|
+
value: undefined,
|
|
244
336
|
compute: compute,
|
|
245
337
|
error: undefined,
|
|
246
338
|
computed: true,
|
|
@@ -252,19 +344,19 @@ function serverEffect(compute, effectFn, value, options) {
|
|
|
252
344
|
}));
|
|
253
345
|
}
|
|
254
346
|
try {
|
|
255
|
-
const result = runWithOwner(owner, () => runWithObserver(comp, () => compute(
|
|
347
|
+
const result = runWithOwner(owner, () => runWithObserver(comp, () => compute(undefined)));
|
|
256
348
|
if (ssrSource) {
|
|
257
349
|
processResult(comp, result, owner, ctx, options?.deferStream, ssrSource);
|
|
258
350
|
}
|
|
259
|
-
effectFn?.(ssrSource ? comp.value ?? result : result,
|
|
351
|
+
effectFn?.(ssrSource ? comp.value ?? result : result, undefined);
|
|
260
352
|
} catch (err) {
|
|
261
353
|
}
|
|
262
354
|
}
|
|
263
|
-
function createEffect(compute, effect,
|
|
264
|
-
serverEffect(compute, undefined,
|
|
355
|
+
function createEffect(compute, effect, options) {
|
|
356
|
+
serverEffect(compute, undefined, options);
|
|
265
357
|
}
|
|
266
|
-
function createRenderEffect(compute, effectFn,
|
|
267
|
-
serverEffect(compute, effectFn,
|
|
358
|
+
function createRenderEffect(compute, effectFn, options) {
|
|
359
|
+
serverEffect(compute, effectFn, options);
|
|
268
360
|
}
|
|
269
361
|
function createTrackedEffect(compute, options) {
|
|
270
362
|
const o = getOwner();
|
|
@@ -275,8 +367,8 @@ function createReaction(effectFn, options) {
|
|
|
275
367
|
tracking();
|
|
276
368
|
};
|
|
277
369
|
}
|
|
278
|
-
function createOptimistic(first, second
|
|
279
|
-
return createSignal(first, second
|
|
370
|
+
function createOptimistic(first, second) {
|
|
371
|
+
return createSignal(first, second);
|
|
280
372
|
}
|
|
281
373
|
function setProperty(state, property, value) {
|
|
282
374
|
if (state[property] === value) return;
|
|
@@ -286,7 +378,7 @@ function setProperty(state, property, value) {
|
|
|
286
378
|
}
|
|
287
379
|
function createStore(first, second) {
|
|
288
380
|
if (typeof first === "function") {
|
|
289
|
-
const store = createProjection(first, second
|
|
381
|
+
const store = createProjection(first, second);
|
|
290
382
|
return [store, fn => fn(store)];
|
|
291
383
|
}
|
|
292
384
|
const state = first;
|
|
@@ -309,7 +401,7 @@ function createPendingProxy(state, source) {
|
|
|
309
401
|
pending = false;
|
|
310
402
|
}];
|
|
311
403
|
}
|
|
312
|
-
function createProjection(fn, initialValue
|
|
404
|
+
function createProjection(fn, initialValue, options) {
|
|
313
405
|
const ctx = sharedConfig.context;
|
|
314
406
|
const owner = createOwner();
|
|
315
407
|
const [state] = createStore(initialValue);
|
|
@@ -324,43 +416,69 @@ function createProjection(fn, initialValue = {}, options) {
|
|
|
324
416
|
const useProxy = ssrSource !== "hybrid";
|
|
325
417
|
const patches = [];
|
|
326
418
|
const draft = useProxy ? createDeepProxy(state, patches) : state;
|
|
327
|
-
const
|
|
419
|
+
const runProjection = () => runWithOwner(owner, () => fn(draft));
|
|
420
|
+
const result = runProjection();
|
|
328
421
|
const iteratorFn = result?.[Symbol.asyncIterator];
|
|
329
422
|
if (typeof iteratorFn === "function") {
|
|
330
|
-
const iter = iteratorFn.call(result);
|
|
331
423
|
if (ssrSource === "hybrid") {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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");
|
|
338
434
|
}
|
|
339
|
-
|
|
340
|
-
|
|
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);
|
|
341
444
|
}
|
|
342
|
-
promise.v = state;
|
|
343
445
|
markReady();
|
|
344
446
|
return state;
|
|
345
|
-
},
|
|
346
|
-
|
|
347
|
-
|
|
447
|
+
}, error => {
|
|
448
|
+
markReady();
|
|
449
|
+
}, () => disposed);
|
|
450
|
+
if (ctx?.async && !getContext(NoHydrateContext) && owner.id) ctx.serialize(owner.id, deferred.promise, options?.deferStream);
|
|
348
451
|
return pending;
|
|
349
452
|
} else {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
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, () => {
|
|
353
472
|
patches.length = 0;
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
}
|
|
473
|
+
const resolved = firstResult;
|
|
474
|
+
if (resolved && !resolved.done && resolved.value !== undefined && resolved.value !== draft) {
|
|
475
|
+
Object.assign(state, resolved.value);
|
|
358
476
|
}
|
|
359
477
|
markReady(JSON.parse(JSON.stringify(state)));
|
|
360
|
-
return
|
|
361
|
-
},
|
|
478
|
+
return undefined;
|
|
479
|
+
}, error => {
|
|
362
480
|
markReady();
|
|
363
|
-
});
|
|
481
|
+
}, () => disposed);
|
|
364
482
|
if (ctx?.async && !getContext(NoHydrateContext) && owner.id) {
|
|
365
483
|
let tappedFirst = true;
|
|
366
484
|
const tapped = {
|
|
@@ -368,8 +486,8 @@ function createProjection(fn, initialValue = {}, options) {
|
|
|
368
486
|
next() {
|
|
369
487
|
if (tappedFirst) {
|
|
370
488
|
tappedFirst = false;
|
|
371
|
-
return
|
|
372
|
-
if (
|
|
489
|
+
return deferred.promise.then(() => {
|
|
490
|
+
if (firstResult?.done) return {
|
|
373
491
|
done: true,
|
|
374
492
|
value: undefined
|
|
375
493
|
};
|
|
@@ -407,25 +525,22 @@ function createProjection(fn, initialValue = {}, options) {
|
|
|
407
525
|
};
|
|
408
526
|
ctx.serialize(owner.id, tapped, options?.deferStream);
|
|
409
527
|
}
|
|
410
|
-
const [pending, markReady] = createPendingProxy(state, firstReady);
|
|
411
528
|
return pending;
|
|
412
529
|
}
|
|
413
530
|
}
|
|
414
531
|
if (result instanceof Promise) {
|
|
415
|
-
const
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
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);
|
|
420
537
|
}
|
|
421
|
-
if (v !== undefined && v !== state) {
|
|
422
|
-
Object.assign(state, v);
|
|
423
|
-
}
|
|
424
|
-
promise.v = state;
|
|
425
538
|
markReady();
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
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);
|
|
429
544
|
return pending;
|
|
430
545
|
}
|
|
431
546
|
if (result !== undefined && result !== state && result !== draft) {
|
|
@@ -567,6 +682,10 @@ function createLoadingBoundary$1(fn, fallback, options) {
|
|
|
567
682
|
throw err;
|
|
568
683
|
}
|
|
569
684
|
}
|
|
685
|
+
function createRevealOrder(fn, _options) {
|
|
686
|
+
const o = createOwner();
|
|
687
|
+
return runWithOwner(o, fn);
|
|
688
|
+
}
|
|
570
689
|
function untrack(fn) {
|
|
571
690
|
return fn();
|
|
572
691
|
}
|
|
@@ -619,10 +738,10 @@ function useContext(context) {
|
|
|
619
738
|
return getContext(context);
|
|
620
739
|
}
|
|
621
740
|
function children(fn) {
|
|
622
|
-
const c = createMemo(fn,
|
|
741
|
+
const c = createMemo(fn, {
|
|
623
742
|
lazy: true
|
|
624
743
|
});
|
|
625
|
-
const memo = createMemo(() => flatten(c()),
|
|
744
|
+
const memo = createMemo(() => flatten(c()), {
|
|
626
745
|
lazy: true
|
|
627
746
|
});
|
|
628
747
|
memo.toArray = () => {
|
|
@@ -691,6 +810,10 @@ function createUniqueId() {
|
|
|
691
810
|
return getNextChildId(o);
|
|
692
811
|
}
|
|
693
812
|
|
|
813
|
+
const RevealGroupContext = {
|
|
814
|
+
id: Symbol("RevealGroupContext"),
|
|
815
|
+
defaultValue: null
|
|
816
|
+
};
|
|
694
817
|
function ssrHandleError(err) {
|
|
695
818
|
if (err instanceof NotReadyError) {
|
|
696
819
|
return err.source;
|
|
@@ -716,6 +839,7 @@ function createLoadingBoundary(fn, fallback, options) {
|
|
|
716
839
|
const ctx = currentCtx;
|
|
717
840
|
const parent = getOwner();
|
|
718
841
|
const parentHandler = parent && runWithOwner(parent, () => getContext(ErrorContext));
|
|
842
|
+
const revealGroup = parent && runWithOwner(parent, () => getContext(RevealGroupContext));
|
|
719
843
|
const o = createOwner();
|
|
720
844
|
const id = o.id;
|
|
721
845
|
o.id = id + "00";
|
|
@@ -778,12 +902,25 @@ function createLoadingBoundary(fn, fallback, options) {
|
|
|
778
902
|
commitBoundaryState();
|
|
779
903
|
return () => ret;
|
|
780
904
|
}
|
|
905
|
+
const collapseFallback = revealGroup ? revealGroup.register(id) : false;
|
|
906
|
+
if (collapseFallback && !ctx.async) {
|
|
907
|
+
commitBoundaryState();
|
|
908
|
+
ctx.serialize(id, "$$f");
|
|
909
|
+
return () => undefined;
|
|
910
|
+
}
|
|
781
911
|
const fallbackOwner = createOwner({
|
|
782
912
|
id
|
|
783
913
|
});
|
|
784
|
-
const fallbackResult = runWithOwner(fallbackOwner, () =>
|
|
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
|
+
});
|
|
785
919
|
if (ctx.async) {
|
|
786
|
-
|
|
920
|
+
const regOpts = revealGroup ? {
|
|
921
|
+
revealGroup: revealGroup.id
|
|
922
|
+
} : undefined;
|
|
923
|
+
done = ctx.registerFragment(id, regOpts);
|
|
787
924
|
(async () => {
|
|
788
925
|
try {
|
|
789
926
|
commitBoundaryState();
|
|
@@ -793,6 +930,7 @@ function createLoadingBoundary(fn, fallback, options) {
|
|
|
793
930
|
}
|
|
794
931
|
flushSerializeBuffer();
|
|
795
932
|
done(ret.t[0]);
|
|
933
|
+
if (revealGroup) revealGroup.onResolved(id);
|
|
796
934
|
} catch (err) {
|
|
797
935
|
finalizeError(err);
|
|
798
936
|
}
|
|
@@ -884,7 +1022,98 @@ function Errored(props) {
|
|
|
884
1022
|
function Loading(props) {
|
|
885
1023
|
return createLoadingBoundary(() => props.children, () => props.fallback);
|
|
886
1024
|
}
|
|
1025
|
+
function Reveal(props) {
|
|
1026
|
+
const o = createOwner();
|
|
1027
|
+
const id = o.id;
|
|
1028
|
+
const together = !!props.together;
|
|
1029
|
+
const collapsed = !!props.collapsed;
|
|
1030
|
+
if (!sharedConfig.context?.async) {
|
|
1031
|
+
const parent = getOwner();
|
|
1032
|
+
const parentGroup = parent ? runWithOwner(parent, () => getContext(RevealGroupContext)) : null;
|
|
1033
|
+
let collapsedByParent = false;
|
|
1034
|
+
if (parentGroup) {
|
|
1035
|
+
collapsedByParent = parentGroup.register(id);
|
|
1036
|
+
if (collapsed || together) console.warn("Nested <Reveal> with collapsed/together won't coordinate correctly with renderToString. Use renderToStream for full support.");
|
|
1037
|
+
}
|
|
1038
|
+
let count = 0;
|
|
1039
|
+
return runWithOwner(o, () => {
|
|
1040
|
+
setContext(RevealGroupContext, {
|
|
1041
|
+
id,
|
|
1042
|
+
register(_key) {
|
|
1043
|
+
count++;
|
|
1044
|
+
if (collapsedByParent) return true;
|
|
1045
|
+
return !together && collapsed && count > 1;
|
|
1046
|
+
},
|
|
1047
|
+
onResolved() {}
|
|
1048
|
+
});
|
|
1049
|
+
return props.children;
|
|
1050
|
+
});
|
|
1051
|
+
}
|
|
1052
|
+
const ctx = sharedConfig.context;
|
|
1053
|
+
const keys = [];
|
|
1054
|
+
const resolved = new Set();
|
|
1055
|
+
const composites = new Map();
|
|
1056
|
+
let frontier = 0;
|
|
1057
|
+
const parent = getOwner();
|
|
1058
|
+
const parentGroup = parent ? runWithOwner(parent, () => getContext(RevealGroupContext)) : null;
|
|
1059
|
+
let collapsedByParent = false;
|
|
1060
|
+
if (parentGroup) {
|
|
1061
|
+
collapsedByParent = parentGroup.register(id, {
|
|
1062
|
+
onActivate: () => {
|
|
1063
|
+
collapsedByParent = false;
|
|
1064
|
+
advanceFrontier();
|
|
1065
|
+
}
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
function notifyParentIfDone() {
|
|
1069
|
+
if (parentGroup && resolved.size === keys.length) {
|
|
1070
|
+
parentGroup.onResolved(id);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
function advanceFrontier() {
|
|
1074
|
+
while (frontier < keys.length && resolved.has(keys[frontier])) {
|
|
1075
|
+
if (!composites.has(keys[frontier])) ctx.revealFragments?.([keys[frontier]]);
|
|
1076
|
+
frontier++;
|
|
1077
|
+
}
|
|
1078
|
+
if (frontier < keys.length) {
|
|
1079
|
+
const activate = composites.get(keys[frontier]);
|
|
1080
|
+
if (activate) activate();else if (!together && collapsed) ctx.revealFallbacks?.(keys.slice(frontier));
|
|
1081
|
+
}
|
|
1082
|
+
notifyParentIfDone();
|
|
1083
|
+
}
|
|
1084
|
+
return runWithOwner(o, () => {
|
|
1085
|
+
setContext(RevealGroupContext, {
|
|
1086
|
+
id,
|
|
1087
|
+
register(key, options) {
|
|
1088
|
+
keys.push(key);
|
|
1089
|
+
if (options?.onActivate) composites.set(key, options.onActivate);
|
|
1090
|
+
if (collapsedByParent) return true;
|
|
1091
|
+
return !together && collapsed && keys.length > 1;
|
|
1092
|
+
},
|
|
1093
|
+
onResolved(key) {
|
|
1094
|
+
resolved.add(key);
|
|
1095
|
+
if (collapsedByParent) {
|
|
1096
|
+
notifyParentIfDone();
|
|
1097
|
+
return;
|
|
1098
|
+
}
|
|
1099
|
+
if (together) {
|
|
1100
|
+
if (resolved.size === keys.length) {
|
|
1101
|
+
ctx.revealFragments?.(id);
|
|
1102
|
+
notifyParentIfDone();
|
|
1103
|
+
}
|
|
1104
|
+
} else {
|
|
1105
|
+
advanceFrontier();
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
});
|
|
1109
|
+
const result = props.children;
|
|
1110
|
+
if (parentGroup && keys.length === 0) {
|
|
1111
|
+
parentGroup.onResolved(id);
|
|
1112
|
+
}
|
|
1113
|
+
return result;
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
887
1116
|
|
|
888
1117
|
const DEV = undefined;
|
|
889
1118
|
|
|
890
|
-
export { $DEVCOMP, DEV, Errored, For, Hydration, Loading, Match, NoHydrateContext, NoHydration, Repeat, Show, Switch, action, children, createComponent, createContext, createDeepProxy, createEffect, createErrorBoundary, createLoadingBoundary, 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 };
|
|
1119
|
+
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 };
|