solid-js 2.0.0-beta.10 → 2.0.0-beta.11
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 +15 -8
- package/dist/dev.js +16 -8
- package/dist/server.cjs +310 -134
- package/dist/server.js +237 -39
- package/dist/solid.cjs +17 -8
- package/dist/solid.js +18 -8
- package/package.json +2 -2
- package/types/client/hydration.d.ts +14 -16
- package/types/index.d.ts +1 -3
- package/types/server/core.d.ts +0 -7
- package/types/server/index.d.ts +1 -1
- package/types/server/shared.d.ts +5 -1
- package/types/server/signals.d.ts +41 -5
- package/types-cjs/client/hydration.d.cts +14 -16
- package/types-cjs/index.d.cts +1 -3
- package/types-cjs/server/core.d.cts +0 -7
- package/types-cjs/server/index.d.cts +1 -1
- package/types-cjs/server/shared.d.cts +5 -1
- package/types-cjs/server/signals.d.cts +41 -5
package/dist/server.cjs
CHANGED
|
@@ -8,13 +8,149 @@ const NoHydrateContext = {
|
|
|
8
8
|
};
|
|
9
9
|
const sharedConfig = {
|
|
10
10
|
getNextContextId() {
|
|
11
|
-
const o =
|
|
11
|
+
const o = getOwner();
|
|
12
12
|
if (!o) throw new Error(`getNextContextId cannot be used under non-hydrating context`);
|
|
13
|
-
if (
|
|
14
|
-
return
|
|
13
|
+
if (getContext(NoHydrateContext)) return undefined;
|
|
14
|
+
return getNextChildId(o);
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
const defaultSSRContext = {};
|
|
19
|
+
let currentOwner = null;
|
|
20
|
+
const OWNER_POOL_MAX = 4096;
|
|
21
|
+
const ownerPool = [];
|
|
22
|
+
function formatChildId(prefix, id) {
|
|
23
|
+
const num = id.toString(36);
|
|
24
|
+
const len = num.length - 1;
|
|
25
|
+
return prefix + (len ? String.fromCharCode(64 + len) : "") + num;
|
|
26
|
+
}
|
|
27
|
+
function nextChildIdFor(owner, consume) {
|
|
28
|
+
let counter = owner;
|
|
29
|
+
while (counter._transparent && counter._parent) counter = counter._parent;
|
|
30
|
+
if (counter.id != null) {
|
|
31
|
+
return formatChildId(counter.id, counter._childCount++ );
|
|
32
|
+
}
|
|
33
|
+
throw new Error("Cannot get child id from owner without an id");
|
|
34
|
+
}
|
|
35
|
+
function getNextChildId(owner) {
|
|
36
|
+
return nextChildIdFor(owner);
|
|
37
|
+
}
|
|
38
|
+
function createOwner(options) {
|
|
39
|
+
const parent = currentOwner;
|
|
40
|
+
const transparent = options?.transparent ?? false;
|
|
41
|
+
const id = options?.id ?? (transparent ? parent?.id : parent?.id != null ? nextChildIdFor(parent) : undefined);
|
|
42
|
+
const ctx = parent?._context ?? defaultSSRContext;
|
|
43
|
+
let owner;
|
|
44
|
+
if (ownerPool.length) {
|
|
45
|
+
owner = ownerPool.pop();
|
|
46
|
+
owner.id = id;
|
|
47
|
+
owner._transparent = transparent;
|
|
48
|
+
owner._disposal = null;
|
|
49
|
+
owner._parent = parent;
|
|
50
|
+
owner._context = ctx;
|
|
51
|
+
owner._childCount = 0;
|
|
52
|
+
owner._firstChild = null;
|
|
53
|
+
owner._nextSibling = null;
|
|
54
|
+
owner._disposed = false;
|
|
55
|
+
} else {
|
|
56
|
+
owner = {
|
|
57
|
+
id,
|
|
58
|
+
_transparent: transparent,
|
|
59
|
+
_disposal: null,
|
|
60
|
+
_parent: parent,
|
|
61
|
+
_context: ctx,
|
|
62
|
+
_childCount: 0,
|
|
63
|
+
_firstChild: null,
|
|
64
|
+
_nextSibling: null,
|
|
65
|
+
_disposed: false
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (parent) {
|
|
69
|
+
const lastChild = parent._firstChild;
|
|
70
|
+
if (lastChild) owner._nextSibling = lastChild;
|
|
71
|
+
parent._firstChild = owner;
|
|
72
|
+
}
|
|
73
|
+
return owner;
|
|
74
|
+
}
|
|
75
|
+
function runWithOwner(owner, fn) {
|
|
76
|
+
const prev = currentOwner;
|
|
77
|
+
currentOwner = owner;
|
|
78
|
+
try {
|
|
79
|
+
return fn();
|
|
80
|
+
} finally {
|
|
81
|
+
currentOwner = prev;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function getOwner() {
|
|
85
|
+
return currentOwner;
|
|
86
|
+
}
|
|
87
|
+
function isDisposed(owner) {
|
|
88
|
+
return owner._disposed;
|
|
89
|
+
}
|
|
90
|
+
function onCleanup(fn) {
|
|
91
|
+
const o = currentOwner;
|
|
92
|
+
if (!o) return fn;
|
|
93
|
+
if (!o._disposal) o._disposal = fn;else if (Array.isArray(o._disposal)) o._disposal.push(fn);else o._disposal = [o._disposal, fn];
|
|
94
|
+
return fn;
|
|
95
|
+
}
|
|
96
|
+
function getContext(context, owner = currentOwner) {
|
|
97
|
+
if (!owner) throw new signals.NoOwnerError();
|
|
98
|
+
const map = owner._context;
|
|
99
|
+
const stored = map[context.id];
|
|
100
|
+
const value = stored !== undefined ? stored : context.defaultValue;
|
|
101
|
+
if (value === undefined) throw new signals.ContextNotFoundError();
|
|
102
|
+
return value;
|
|
103
|
+
}
|
|
104
|
+
function setContext(context, value, owner = currentOwner) {
|
|
105
|
+
if (!owner) throw new signals.NoOwnerError();
|
|
106
|
+
const o = owner;
|
|
107
|
+
o._context = {
|
|
108
|
+
...o._context,
|
|
109
|
+
[context.id]: value === undefined ? context.defaultValue : value
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function disposeOwner(owner, self = true) {
|
|
113
|
+
const node = owner;
|
|
114
|
+
if (node._disposed) return;
|
|
115
|
+
if (!node._firstChild && !node._disposal) {
|
|
116
|
+
if (self) {
|
|
117
|
+
node._disposed = true;
|
|
118
|
+
if (ownerPool.length < OWNER_POOL_MAX) {
|
|
119
|
+
node._parent = null;
|
|
120
|
+
node._nextSibling = null;
|
|
121
|
+
ownerPool.push(node);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (self) node._disposed = true;
|
|
127
|
+
let child = node._firstChild;
|
|
128
|
+
while (child) {
|
|
129
|
+
const next = child._nextSibling;
|
|
130
|
+
disposeOwner(child, true);
|
|
131
|
+
child = next;
|
|
132
|
+
}
|
|
133
|
+
node._firstChild = null;
|
|
134
|
+
node._childCount = 0;
|
|
135
|
+
const d = node._disposal;
|
|
136
|
+
if (d) {
|
|
137
|
+
if (Array.isArray(d)) {
|
|
138
|
+
for (let i = 0, len = d.length; i < len; i++) d[i]();
|
|
139
|
+
} else {
|
|
140
|
+
d();
|
|
141
|
+
}
|
|
142
|
+
node._disposal = null;
|
|
143
|
+
}
|
|
144
|
+
if (self && ownerPool.length < OWNER_POOL_MAX) {
|
|
145
|
+
node._parent = null;
|
|
146
|
+
node._nextSibling = null;
|
|
147
|
+
ownerPool.push(node);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function createRoot(init, options) {
|
|
151
|
+
const owner = createOwner(options);
|
|
152
|
+
return runWithOwner(owner, () => init(() => disposeOwner(owner)));
|
|
153
|
+
}
|
|
18
154
|
let Observer = null;
|
|
19
155
|
function runWithObserver(comp, fn) {
|
|
20
156
|
const prev = Observer;
|
|
@@ -99,8 +235,11 @@ function createSignal(first, second) {
|
|
|
99
235
|
}];
|
|
100
236
|
}
|
|
101
237
|
function createMemo(compute, options) {
|
|
238
|
+
if (options?.sync) {
|
|
239
|
+
return createSyncMemo(compute, options);
|
|
240
|
+
}
|
|
102
241
|
const ctx = sharedConfig.context;
|
|
103
|
-
const owner =
|
|
242
|
+
const owner = createOwner();
|
|
104
243
|
const comp = {
|
|
105
244
|
owner,
|
|
106
245
|
value: undefined,
|
|
@@ -109,12 +248,12 @@ function createMemo(compute, options) {
|
|
|
109
248
|
computed: false,
|
|
110
249
|
disposed: false
|
|
111
250
|
};
|
|
112
|
-
|
|
251
|
+
runWithOwner(owner, () => onCleanup(() => {
|
|
113
252
|
comp.disposed = true;
|
|
114
253
|
}));
|
|
115
254
|
function update() {
|
|
116
255
|
if (comp.disposed) return;
|
|
117
|
-
const run = () =>
|
|
256
|
+
const run = () => runWithOwner(owner, () => runWithObserver(comp, () => comp.compute(comp.value)));
|
|
118
257
|
try {
|
|
119
258
|
comp.error = undefined;
|
|
120
259
|
const result = run();
|
|
@@ -134,7 +273,7 @@ function createMemo(compute, options) {
|
|
|
134
273
|
} else if (!options?.lazy) {
|
|
135
274
|
update();
|
|
136
275
|
}
|
|
137
|
-
|
|
276
|
+
const read = () => {
|
|
138
277
|
if (!comp.computed) {
|
|
139
278
|
update();
|
|
140
279
|
}
|
|
@@ -143,6 +282,44 @@ function createMemo(compute, options) {
|
|
|
143
282
|
}
|
|
144
283
|
return comp.value;
|
|
145
284
|
};
|
|
285
|
+
read[signals.$REFRESH] = comp;
|
|
286
|
+
return read;
|
|
287
|
+
}
|
|
288
|
+
function createSyncMemo(compute, options) {
|
|
289
|
+
const owner = createOwner();
|
|
290
|
+
let value;
|
|
291
|
+
let error;
|
|
292
|
+
let cached = false;
|
|
293
|
+
function pull() {
|
|
294
|
+
const prev = currentOwner;
|
|
295
|
+
currentOwner = owner;
|
|
296
|
+
try {
|
|
297
|
+
value = compute(value);
|
|
298
|
+
error = undefined;
|
|
299
|
+
cached = true;
|
|
300
|
+
return value;
|
|
301
|
+
} catch (err) {
|
|
302
|
+
if (err instanceof signals.NotReadyError) throw err;
|
|
303
|
+
error = err;
|
|
304
|
+
cached = true;
|
|
305
|
+
throw err;
|
|
306
|
+
} finally {
|
|
307
|
+
currentOwner = prev;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (!options?.lazy) {
|
|
311
|
+
try {
|
|
312
|
+
pull();
|
|
313
|
+
} catch {
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return () => {
|
|
317
|
+
if (cached) {
|
|
318
|
+
if (error !== undefined) throw error;
|
|
319
|
+
return value;
|
|
320
|
+
}
|
|
321
|
+
return pull();
|
|
322
|
+
};
|
|
146
323
|
}
|
|
147
324
|
function createDeepProxy(target, patches, basePath = []) {
|
|
148
325
|
const childProxies = new Map();
|
|
@@ -207,7 +384,7 @@ function createDeepProxy(target, patches, basePath = []) {
|
|
|
207
384
|
function processResult(comp, result, owner, ctx, deferStream, ssrSource, rerun) {
|
|
208
385
|
if (comp.disposed) return;
|
|
209
386
|
const id = owner.id;
|
|
210
|
-
const noHydrate =
|
|
387
|
+
const noHydrate = getContext(NoHydrateContext, owner);
|
|
211
388
|
if (result instanceof Promise) {
|
|
212
389
|
if (result.s === 1) {
|
|
213
390
|
comp.value = result.v;
|
|
@@ -326,11 +503,11 @@ function closeAsyncIterator(iter, value) {
|
|
|
326
503
|
function serverEffect(compute, effectFn, options) {
|
|
327
504
|
const ssrSource = options?.ssrSource;
|
|
328
505
|
if (ssrSource === "client") {
|
|
329
|
-
|
|
506
|
+
createOwner();
|
|
330
507
|
return;
|
|
331
508
|
}
|
|
332
509
|
const ctx = sharedConfig.context;
|
|
333
|
-
const owner =
|
|
510
|
+
const owner = createOwner();
|
|
334
511
|
const comp = {
|
|
335
512
|
owner,
|
|
336
513
|
value: undefined,
|
|
@@ -340,12 +517,12 @@ function serverEffect(compute, effectFn, options) {
|
|
|
340
517
|
disposed: false
|
|
341
518
|
};
|
|
342
519
|
if (ssrSource) {
|
|
343
|
-
|
|
520
|
+
runWithOwner(owner, () => onCleanup(() => {
|
|
344
521
|
comp.disposed = true;
|
|
345
522
|
}));
|
|
346
523
|
}
|
|
347
524
|
try {
|
|
348
|
-
const result =
|
|
525
|
+
const result = runWithOwner(owner, () => runWithObserver(comp, () => compute(undefined)));
|
|
349
526
|
if (ssrSource) {
|
|
350
527
|
processResult(comp, result, owner, ctx, options?.deferStream, ssrSource);
|
|
351
528
|
}
|
|
@@ -360,8 +537,8 @@ function createRenderEffect(compute, effectFn, options) {
|
|
|
360
537
|
serverEffect(compute, effectFn, options);
|
|
361
538
|
}
|
|
362
539
|
function createTrackedEffect(compute, options) {
|
|
363
|
-
const o =
|
|
364
|
-
if (o?.id != null)
|
|
540
|
+
const o = getOwner();
|
|
541
|
+
if (o?.id != null) getNextChildId(o);
|
|
365
542
|
}
|
|
366
543
|
function createReaction(effectFn, options) {
|
|
367
544
|
return tracking => {
|
|
@@ -404,20 +581,20 @@ function createPendingProxy(state, source) {
|
|
|
404
581
|
}
|
|
405
582
|
function createProjection(fn, initialValue, options) {
|
|
406
583
|
const ctx = sharedConfig.context;
|
|
407
|
-
const owner =
|
|
584
|
+
const owner = createOwner();
|
|
408
585
|
const [state] = createStore(initialValue);
|
|
409
586
|
if (options?.ssrSource === "client") {
|
|
410
587
|
return state;
|
|
411
588
|
}
|
|
412
589
|
let disposed = false;
|
|
413
|
-
|
|
590
|
+
runWithOwner(owner, () => onCleanup(() => {
|
|
414
591
|
disposed = true;
|
|
415
592
|
}));
|
|
416
593
|
const ssrSource = options?.ssrSource;
|
|
417
594
|
const useProxy = ssrSource !== "hybrid";
|
|
418
595
|
const patches = [];
|
|
419
596
|
const draft = useProxy ? createDeepProxy(state, patches) : state;
|
|
420
|
-
const runProjection = () =>
|
|
597
|
+
const runProjection = () => runWithOwner(owner, () => fn(draft));
|
|
421
598
|
const result = runProjection();
|
|
422
599
|
const iteratorFn = result?.[Symbol.asyncIterator];
|
|
423
600
|
if (typeof iteratorFn === "function") {
|
|
@@ -448,7 +625,7 @@ function createProjection(fn, initialValue, options) {
|
|
|
448
625
|
}, error => {
|
|
449
626
|
markReady();
|
|
450
627
|
}, () => disposed);
|
|
451
|
-
if (ctx?.async && !
|
|
628
|
+
if (ctx?.async && !getContext(NoHydrateContext) && owner.id) ctx.serialize(owner.id, deferred.promise, options?.deferStream);
|
|
452
629
|
return pending;
|
|
453
630
|
} else {
|
|
454
631
|
let currentResult = result;
|
|
@@ -480,7 +657,7 @@ function createProjection(fn, initialValue, options) {
|
|
|
480
657
|
}, error => {
|
|
481
658
|
markReady();
|
|
482
659
|
}, () => disposed);
|
|
483
|
-
if (ctx?.async && !
|
|
660
|
+
if (ctx?.async && !getContext(NoHydrateContext) && owner.id) {
|
|
484
661
|
let tappedFirst = true;
|
|
485
662
|
const tapped = {
|
|
486
663
|
[Symbol.asyncIterator]: () => ({
|
|
@@ -541,7 +718,7 @@ function createProjection(fn, initialValue, options) {
|
|
|
541
718
|
}, error => {
|
|
542
719
|
markReady();
|
|
543
720
|
}, () => disposed);
|
|
544
|
-
if (ctx?.async && !
|
|
721
|
+
if (ctx?.async && !getContext(NoHydrateContext) && owner.id) ctx.serialize(owner.id, deferred.promise, options?.deferStream);
|
|
545
722
|
return pending;
|
|
546
723
|
}
|
|
547
724
|
if (result !== undefined && result !== state && result !== draft) {
|
|
@@ -568,44 +745,62 @@ function deep(store) {
|
|
|
568
745
|
return store;
|
|
569
746
|
}
|
|
570
747
|
function mapArray(list, mapFn, options = {}) {
|
|
571
|
-
const parent = signals.createOwner();
|
|
572
748
|
return createMemo(() => {
|
|
573
749
|
const items = list();
|
|
574
|
-
|
|
750
|
+
const s = [];
|
|
575
751
|
if (items && items.length) {
|
|
576
|
-
|
|
752
|
+
const parent = currentOwner;
|
|
753
|
+
const origId = parent.id;
|
|
754
|
+
const origChildCount = parent._childCount;
|
|
755
|
+
try {
|
|
577
756
|
for (let i = 0, len = items.length; i < len; i++) {
|
|
578
|
-
|
|
579
|
-
|
|
757
|
+
if (origId !== undefined) {
|
|
758
|
+
parent.id = formatChildId(origId, origChildCount + i);
|
|
759
|
+
}
|
|
760
|
+
parent._childCount = 0;
|
|
761
|
+
s.push(mapFn(() => items[i], () => i));
|
|
580
762
|
}
|
|
581
|
-
}
|
|
763
|
+
} finally {
|
|
764
|
+
parent.id = origId;
|
|
765
|
+
parent._childCount = origChildCount + items.length;
|
|
766
|
+
}
|
|
582
767
|
} else if (options.fallback) {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
return signals.runWithOwner(fo, () => options.fallback());
|
|
586
|
-
})];
|
|
768
|
+
const fo = createOwner();
|
|
769
|
+
s.push(runWithOwner(fo, () => options.fallback()));
|
|
587
770
|
}
|
|
588
771
|
return s;
|
|
772
|
+
}, {
|
|
773
|
+
sync: true
|
|
589
774
|
});
|
|
590
775
|
}
|
|
591
776
|
function repeat(count, mapFn, options = {}) {
|
|
592
|
-
const owner = signals.createOwner();
|
|
593
777
|
return createMemo(() => {
|
|
594
778
|
const len = count();
|
|
595
779
|
const offset = options.from?.() || 0;
|
|
596
780
|
if (!len) {
|
|
597
781
|
if (!options.fallback) return [];
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
return signals.runWithOwner(fallbackOwner, () => options.fallback());
|
|
601
|
-
})];
|
|
782
|
+
const fo = createOwner();
|
|
783
|
+
return [runWithOwner(fo, () => options.fallback())];
|
|
602
784
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
785
|
+
const out = new Array(len);
|
|
786
|
+
const parent = currentOwner;
|
|
787
|
+
const origId = parent.id;
|
|
788
|
+
const origChildCount = parent._childCount;
|
|
789
|
+
try {
|
|
790
|
+
for (let i = 0; i < len; i++) {
|
|
791
|
+
if (origId !== undefined) {
|
|
792
|
+
parent.id = formatChildId(origId, origChildCount + i);
|
|
793
|
+
}
|
|
794
|
+
parent._childCount = 0;
|
|
795
|
+
out[i] = mapFn(i + offset);
|
|
796
|
+
}
|
|
797
|
+
} finally {
|
|
798
|
+
parent.id = origId;
|
|
799
|
+
parent._childCount = origChildCount + len;
|
|
800
|
+
}
|
|
801
|
+
return out;
|
|
802
|
+
}, {
|
|
803
|
+
sync: true
|
|
609
804
|
});
|
|
610
805
|
}
|
|
611
806
|
const ErrorContext = {
|
|
@@ -620,9 +815,9 @@ function runWithBoundaryErrorContext(owner, render, onError, context, boundaryId
|
|
|
620
815
|
if (boundaryId !== undefined) context._currentBoundaryId = boundaryId;
|
|
621
816
|
}
|
|
622
817
|
try {
|
|
623
|
-
return
|
|
624
|
-
const parentHandler =
|
|
625
|
-
|
|
818
|
+
return runWithOwner(owner, () => {
|
|
819
|
+
const parentHandler = getContext(ErrorContext);
|
|
820
|
+
setContext(ErrorContext, err => onError(err, parentHandler));
|
|
626
821
|
return render();
|
|
627
822
|
});
|
|
628
823
|
} finally {
|
|
@@ -634,19 +829,19 @@ function runWithBoundaryErrorContext(owner, render, onError, context, boundaryId
|
|
|
634
829
|
}
|
|
635
830
|
function createErrorBoundary(fn, fallback) {
|
|
636
831
|
const ctx = sharedConfig.context;
|
|
637
|
-
const parent =
|
|
638
|
-
const owner =
|
|
832
|
+
const parent = getOwner();
|
|
833
|
+
const owner = createOwner();
|
|
639
834
|
const resolve = () => {
|
|
640
|
-
const resolved = ctx.resolve(
|
|
835
|
+
const resolved = ctx.resolve(runWithOwner(createOwner(), fn));
|
|
641
836
|
if (resolved?.p?.length) throw new signals.NotReadyError(Promise.all(resolved.p));
|
|
642
837
|
return resolved;
|
|
643
838
|
};
|
|
644
|
-
const renderFallback = err => ctx ?
|
|
645
|
-
const fallbackOwner =
|
|
646
|
-
return
|
|
839
|
+
const renderFallback = err => ctx ? runWithOwner(parent, () => {
|
|
840
|
+
const fallbackOwner = createOwner();
|
|
841
|
+
return runWithOwner(fallbackOwner, () => fallback(err, () => {}));
|
|
647
842
|
}) : fallback(err, () => {});
|
|
648
843
|
const serializeError = err => {
|
|
649
|
-
if (ctx && owner.id && !
|
|
844
|
+
if (ctx && owner.id && !runWithOwner(owner, () => getContext(NoHydrateContext))) {
|
|
650
845
|
ctx.serialize(owner.id, err);
|
|
651
846
|
}
|
|
652
847
|
};
|
|
@@ -657,14 +852,14 @@ function createErrorBoundary(fn, fallback) {
|
|
|
657
852
|
return () => {
|
|
658
853
|
let result;
|
|
659
854
|
let handled = false;
|
|
660
|
-
if (ctx) owner
|
|
855
|
+
if (ctx) disposeOwner(owner, false);
|
|
661
856
|
try {
|
|
662
857
|
result = ctx ? runWithBoundaryErrorContext(owner, resolve, err => {
|
|
663
858
|
if (err instanceof signals.NotReadyError) throw err;
|
|
664
859
|
handled = true;
|
|
665
860
|
result = handleError(err);
|
|
666
861
|
throw err;
|
|
667
|
-
}) :
|
|
862
|
+
}) : runWithOwner(owner, fn);
|
|
668
863
|
} catch (err) {
|
|
669
864
|
if (err instanceof signals.NotReadyError) throw err;
|
|
670
865
|
result = handled ? result : handleError(err);
|
|
@@ -684,8 +879,8 @@ function createLoadingBoundary$1(fn, fallback, options) {
|
|
|
684
879
|
}
|
|
685
880
|
}
|
|
686
881
|
function createRevealOrder(fn, _options) {
|
|
687
|
-
const o =
|
|
688
|
-
return
|
|
882
|
+
const o = createOwner();
|
|
883
|
+
return runWithOwner(o, fn);
|
|
689
884
|
}
|
|
690
885
|
function untrack(fn) {
|
|
691
886
|
return fn();
|
|
@@ -711,23 +906,23 @@ function latest(fn) {
|
|
|
711
906
|
function isRefreshing() {
|
|
712
907
|
return false;
|
|
713
908
|
}
|
|
714
|
-
function refresh(
|
|
715
|
-
return
|
|
909
|
+
function refresh(_target) {
|
|
910
|
+
return undefined;
|
|
716
911
|
}
|
|
717
912
|
function action(fn) {
|
|
718
913
|
return fn;
|
|
719
914
|
}
|
|
720
915
|
function onSettled(callback) {
|
|
721
|
-
const o =
|
|
722
|
-
if (o?.id != null)
|
|
916
|
+
const o = getOwner();
|
|
917
|
+
if (o?.id != null) getNextChildId(o);
|
|
723
918
|
}
|
|
724
919
|
|
|
725
920
|
const $DEVCOMP = Symbol("solid-dev-component");
|
|
726
921
|
function createContext(defaultValue, options) {
|
|
727
922
|
const id = Symbol(options && options.name || "");
|
|
728
923
|
function provider(props) {
|
|
729
|
-
return
|
|
730
|
-
|
|
924
|
+
return createRoot(() => {
|
|
925
|
+
setContext(provider, props.value);
|
|
731
926
|
return children(() => props.children);
|
|
732
927
|
});
|
|
733
928
|
}
|
|
@@ -736,14 +931,15 @@ function createContext(defaultValue, options) {
|
|
|
736
931
|
return provider;
|
|
737
932
|
}
|
|
738
933
|
function useContext(context) {
|
|
739
|
-
return
|
|
934
|
+
return getContext(context);
|
|
740
935
|
}
|
|
741
936
|
function children(fn) {
|
|
742
937
|
const c = createMemo(fn, {
|
|
743
938
|
lazy: true
|
|
744
939
|
});
|
|
745
940
|
const memo = createMemo(() => signals.flatten(c()), {
|
|
746
|
-
lazy: true
|
|
941
|
+
lazy: true,
|
|
942
|
+
sync: true
|
|
747
943
|
});
|
|
748
944
|
memo.toArray = () => {
|
|
749
945
|
const v = memo();
|
|
@@ -751,11 +947,6 @@ function children(fn) {
|
|
|
751
947
|
};
|
|
752
948
|
return memo;
|
|
753
949
|
}
|
|
754
|
-
function ssrRunInScope(fn) {
|
|
755
|
-
const owner = signals.getOwner();
|
|
756
|
-
if (!owner) return fn;
|
|
757
|
-
return Array.isArray(fn) ? fn.map(hole => () => signals.runWithOwner(owner, hole)) : () => signals.runWithOwner(owner, fn);
|
|
758
|
-
}
|
|
759
950
|
|
|
760
951
|
function enableHydration() {}
|
|
761
952
|
function createComponent(Comp, props) {
|
|
@@ -773,7 +964,7 @@ function lazy(fn, moduleUrl) {
|
|
|
773
964
|
return p;
|
|
774
965
|
};
|
|
775
966
|
const wrap = props => {
|
|
776
|
-
const noHydrate =
|
|
967
|
+
const noHydrate = getContext(NoHydrateContext);
|
|
777
968
|
if (!noHydrate && !moduleUrl) {
|
|
778
969
|
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.");
|
|
779
970
|
}
|
|
@@ -799,6 +990,8 @@ function lazy(fn, moduleUrl) {
|
|
|
799
990
|
return createMemo(() => {
|
|
800
991
|
if (!p.v) throw new signals.NotReadyError(p);
|
|
801
992
|
return p.v(props);
|
|
993
|
+
}, {
|
|
994
|
+
sync: true
|
|
802
995
|
});
|
|
803
996
|
};
|
|
804
997
|
wrap.preload = load;
|
|
@@ -806,9 +999,9 @@ function lazy(fn, moduleUrl) {
|
|
|
806
999
|
return wrap;
|
|
807
1000
|
}
|
|
808
1001
|
function createUniqueId() {
|
|
809
|
-
const o =
|
|
1002
|
+
const o = getOwner();
|
|
810
1003
|
if (!o) throw new Error(`createUniqueId cannot be used outside of a reactive context`);
|
|
811
|
-
return
|
|
1004
|
+
return getNextChildId(o);
|
|
812
1005
|
}
|
|
813
1006
|
|
|
814
1007
|
const RevealGroupContext = {
|
|
@@ -819,7 +1012,7 @@ function ssrHandleError(err) {
|
|
|
819
1012
|
if (err instanceof signals.NotReadyError) {
|
|
820
1013
|
return err.source;
|
|
821
1014
|
}
|
|
822
|
-
const handler =
|
|
1015
|
+
const handler = getContext(ErrorContext);
|
|
823
1016
|
if (handler) {
|
|
824
1017
|
handler(err);
|
|
825
1018
|
return;
|
|
@@ -832,10 +1025,10 @@ function createLoadingBoundary(fn, fallback, options) {
|
|
|
832
1025
|
return createLoadingBoundary$1(fn, fallback);
|
|
833
1026
|
}
|
|
834
1027
|
const ctx = currentCtx;
|
|
835
|
-
const parent =
|
|
836
|
-
const parentHandler = parent &&
|
|
837
|
-
const revealGroup = parent &&
|
|
838
|
-
const o =
|
|
1028
|
+
const parent = getOwner();
|
|
1029
|
+
const parentHandler = parent && runWithOwner(parent, () => getContext(ErrorContext));
|
|
1030
|
+
const revealGroup = parent && runWithOwner(parent, () => getContext(RevealGroupContext));
|
|
1031
|
+
const o = createOwner();
|
|
839
1032
|
const id = o.id;
|
|
840
1033
|
o.id = id + "00";
|
|
841
1034
|
let done;
|
|
@@ -876,13 +1069,13 @@ function createLoadingBoundary(fn, fallback, options) {
|
|
|
876
1069
|
if (done?.(undefined, err)) return;
|
|
877
1070
|
if (!parentHandler) throw err;
|
|
878
1071
|
try {
|
|
879
|
-
|
|
1072
|
+
runWithOwner(parent, () => parentHandler(err));
|
|
880
1073
|
} catch (caught) {
|
|
881
1074
|
if (caught !== err) throw caught;
|
|
882
1075
|
}
|
|
883
1076
|
}
|
|
884
1077
|
function runDiscovery() {
|
|
885
|
-
o
|
|
1078
|
+
disposeOwner(o, false);
|
|
886
1079
|
serializeBuffer = [];
|
|
887
1080
|
retryPromise = undefined;
|
|
888
1081
|
return runLoadingPhase(() => {
|
|
@@ -909,10 +1102,10 @@ function createLoadingBoundary(fn, fallback, options) {
|
|
|
909
1102
|
ctx.serialize(id, "$$f");
|
|
910
1103
|
return () => undefined;
|
|
911
1104
|
}
|
|
912
|
-
const fallbackOwner =
|
|
1105
|
+
const fallbackOwner = createOwner({
|
|
913
1106
|
id
|
|
914
1107
|
});
|
|
915
|
-
const fallbackResult =
|
|
1108
|
+
const fallbackResult = runWithOwner(fallbackOwner, () => {
|
|
916
1109
|
if (!ctx.async) return fallback();
|
|
917
1110
|
const tpl = collapseFallback ? [`<template id="pl-${id}">`, `</template><!--pl-${id}-->`] : [`<template id="pl-${id}"></template>`, `<!--pl-${id}-->`];
|
|
918
1111
|
return ctx.ssr(tpl, ctx.escape(fallback()));
|
|
@@ -929,12 +1122,13 @@ function createLoadingBoundary(fn, fallback, options) {
|
|
|
929
1122
|
ret = runDiscovery();
|
|
930
1123
|
}
|
|
931
1124
|
commitBoundaryState();
|
|
932
|
-
while (ret.p.length) {
|
|
933
|
-
|
|
934
|
-
|
|
1125
|
+
while (ret && ret.p && ret.p.length) {
|
|
1126
|
+
const pending = ret;
|
|
1127
|
+
await Promise.all(pending.p).catch(() => {});
|
|
1128
|
+
ret = runLoadingPhase(() => ctx.ssr(pending.t, ...pending.h));
|
|
935
1129
|
}
|
|
936
1130
|
flushSerializeBuffer();
|
|
937
|
-
done(ret.t[0]);
|
|
1131
|
+
done(ret && Array.isArray(ret.t) ? ret.t[0] : ret && ret.t);
|
|
938
1132
|
if (revealGroup) revealGroup.onResolved(id);
|
|
939
1133
|
} catch (err) {
|
|
940
1134
|
finalizeError(err);
|
|
@@ -947,19 +1141,19 @@ function createLoadingBoundary(fn, fallback, options) {
|
|
|
947
1141
|
return () => fallbackResult;
|
|
948
1142
|
}
|
|
949
1143
|
function NoHydration(props) {
|
|
950
|
-
const o =
|
|
951
|
-
return
|
|
952
|
-
|
|
1144
|
+
const o = createOwner();
|
|
1145
|
+
return runWithOwner(o, () => {
|
|
1146
|
+
setContext(NoHydrateContext, true);
|
|
953
1147
|
return props.children;
|
|
954
1148
|
});
|
|
955
1149
|
}
|
|
956
1150
|
function Hydration(props) {
|
|
957
|
-
if (!
|
|
958
|
-
const o =
|
|
1151
|
+
if (!getContext(NoHydrateContext)) return props.children;
|
|
1152
|
+
const o = createOwner({
|
|
959
1153
|
id: props.id ?? ""
|
|
960
1154
|
});
|
|
961
|
-
return
|
|
962
|
-
|
|
1155
|
+
return runWithOwner(o, () => {
|
|
1156
|
+
setContext(NoHydrateContext, false);
|
|
963
1157
|
return props.children;
|
|
964
1158
|
});
|
|
965
1159
|
}
|
|
@@ -981,10 +1175,10 @@ function Repeat(props) {
|
|
|
981
1175
|
return repeat(() => props.count, index => typeof props.children === "function" ? props.children(index) : props.children, options);
|
|
982
1176
|
}
|
|
983
1177
|
function Show(props) {
|
|
984
|
-
const o =
|
|
1178
|
+
const o = getOwner();
|
|
985
1179
|
if (o?.id != null) {
|
|
986
|
-
|
|
987
|
-
if (!props.keyed)
|
|
1180
|
+
getNextChildId(o);
|
|
1181
|
+
if (!props.keyed) getNextChildId(o);
|
|
988
1182
|
}
|
|
989
1183
|
return createMemo(() => {
|
|
990
1184
|
const when = props.when;
|
|
@@ -996,12 +1190,14 @@ function Show(props) {
|
|
|
996
1190
|
return child;
|
|
997
1191
|
}
|
|
998
1192
|
return props.fallback;
|
|
1193
|
+
}, {
|
|
1194
|
+
sync: true
|
|
999
1195
|
});
|
|
1000
1196
|
}
|
|
1001
1197
|
function Switch(props) {
|
|
1002
1198
|
const chs = children(() => props.children);
|
|
1003
|
-
const o =
|
|
1004
|
-
if (o?.id != null)
|
|
1199
|
+
const o = getOwner();
|
|
1200
|
+
if (o?.id != null) getNextChildId(o);
|
|
1005
1201
|
return createMemo(() => {
|
|
1006
1202
|
let conds = chs();
|
|
1007
1203
|
if (!Array.isArray(conds)) conds = [conds];
|
|
@@ -1013,6 +1209,8 @@ function Switch(props) {
|
|
|
1013
1209
|
}
|
|
1014
1210
|
}
|
|
1015
1211
|
return props.fallback;
|
|
1212
|
+
}, {
|
|
1213
|
+
sync: true
|
|
1016
1214
|
});
|
|
1017
1215
|
}
|
|
1018
1216
|
function Match(props) {
|
|
@@ -1028,13 +1226,13 @@ function Loading(props) {
|
|
|
1028
1226
|
return createLoadingBoundary(() => props.children, () => props.fallback);
|
|
1029
1227
|
}
|
|
1030
1228
|
function Reveal(props) {
|
|
1031
|
-
const o =
|
|
1229
|
+
const o = createOwner();
|
|
1032
1230
|
const id = o.id;
|
|
1033
1231
|
const order = props.order ?? "sequential";
|
|
1034
1232
|
const collapsed = order === "sequential" && !!props.collapsed;
|
|
1035
1233
|
if (!sharedConfig.context?.async) {
|
|
1036
|
-
const parent =
|
|
1037
|
-
const parentGroup = parent ?
|
|
1234
|
+
const parent = getOwner();
|
|
1235
|
+
const parentGroup = parent ? runWithOwner(parent, () => getContext(RevealGroupContext)) : null;
|
|
1038
1236
|
let collapsedByParent = false;
|
|
1039
1237
|
if (parentGroup) {
|
|
1040
1238
|
const reg = parentGroup.register(id);
|
|
@@ -1042,8 +1240,8 @@ function Reveal(props) {
|
|
|
1042
1240
|
if (order === "together" || collapsed) console.warn("Nested <Reveal> with collapsed/together won't coordinate correctly with renderToString. Use renderToStream for full support.");
|
|
1043
1241
|
}
|
|
1044
1242
|
let count = 0;
|
|
1045
|
-
return
|
|
1046
|
-
|
|
1243
|
+
return runWithOwner(o, () => {
|
|
1244
|
+
setContext(RevealGroupContext, {
|
|
1047
1245
|
id,
|
|
1048
1246
|
register(_key) {
|
|
1049
1247
|
count++;
|
|
@@ -1071,8 +1269,8 @@ function Reveal(props) {
|
|
|
1071
1269
|
let collapsedByParent = false;
|
|
1072
1270
|
let selfMinimallyResolved = false;
|
|
1073
1271
|
let notifiedParentDone = false;
|
|
1074
|
-
const parent =
|
|
1075
|
-
const parentGroup = parent ?
|
|
1272
|
+
const parent = getOwner();
|
|
1273
|
+
const parentGroup = parent ? runWithOwner(parent, () => getContext(RevealGroupContext)) : null;
|
|
1076
1274
|
if (parentGroup) {
|
|
1077
1275
|
const reg = parentGroup.register(id, {
|
|
1078
1276
|
onActivate: () => {
|
|
@@ -1140,8 +1338,8 @@ function Reveal(props) {
|
|
|
1140
1338
|
composites.forEach((_, key) => activateComposite(key));
|
|
1141
1339
|
notifyParentIfDone();
|
|
1142
1340
|
}
|
|
1143
|
-
return
|
|
1144
|
-
|
|
1341
|
+
return runWithOwner(o, () => {
|
|
1342
|
+
setContext(RevealGroupContext, {
|
|
1145
1343
|
id,
|
|
1146
1344
|
register(key, options) {
|
|
1147
1345
|
keys.push(key);
|
|
@@ -1218,14 +1416,6 @@ Object.defineProperty(exports, "NotReadyError", {
|
|
|
1218
1416
|
enumerable: true,
|
|
1219
1417
|
get: function () { return signals.NotReadyError; }
|
|
1220
1418
|
});
|
|
1221
|
-
Object.defineProperty(exports, "createOwner", {
|
|
1222
|
-
enumerable: true,
|
|
1223
|
-
get: function () { return signals.createOwner; }
|
|
1224
|
-
});
|
|
1225
|
-
Object.defineProperty(exports, "createRoot", {
|
|
1226
|
-
enumerable: true,
|
|
1227
|
-
get: function () { return signals.createRoot; }
|
|
1228
|
-
});
|
|
1229
1419
|
Object.defineProperty(exports, "enableExternalSource", {
|
|
1230
1420
|
enumerable: true,
|
|
1231
1421
|
get: function () { return signals.enableExternalSource; }
|
|
@@ -1238,18 +1428,6 @@ Object.defineProperty(exports, "flatten", {
|
|
|
1238
1428
|
enumerable: true,
|
|
1239
1429
|
get: function () { return signals.flatten; }
|
|
1240
1430
|
});
|
|
1241
|
-
Object.defineProperty(exports, "getNextChildId", {
|
|
1242
|
-
enumerable: true,
|
|
1243
|
-
get: function () { return signals.getNextChildId; }
|
|
1244
|
-
});
|
|
1245
|
-
Object.defineProperty(exports, "getOwner", {
|
|
1246
|
-
enumerable: true,
|
|
1247
|
-
get: function () { return signals.getOwner; }
|
|
1248
|
-
});
|
|
1249
|
-
Object.defineProperty(exports, "isDisposed", {
|
|
1250
|
-
enumerable: true,
|
|
1251
|
-
get: function () { return signals.isDisposed; }
|
|
1252
|
-
});
|
|
1253
1431
|
Object.defineProperty(exports, "isEqual", {
|
|
1254
1432
|
enumerable: true,
|
|
1255
1433
|
get: function () { return signals.isEqual; }
|
|
@@ -1266,14 +1444,6 @@ Object.defineProperty(exports, "omit", {
|
|
|
1266
1444
|
enumerable: true,
|
|
1267
1445
|
get: function () { return signals.omit; }
|
|
1268
1446
|
});
|
|
1269
|
-
Object.defineProperty(exports, "onCleanup", {
|
|
1270
|
-
enumerable: true,
|
|
1271
|
-
get: function () { return signals.onCleanup; }
|
|
1272
|
-
});
|
|
1273
|
-
Object.defineProperty(exports, "runWithOwner", {
|
|
1274
|
-
enumerable: true,
|
|
1275
|
-
get: function () { return signals.runWithOwner; }
|
|
1276
|
-
});
|
|
1277
1447
|
Object.defineProperty(exports, "snapshot", {
|
|
1278
1448
|
enumerable: true,
|
|
1279
1449
|
get: function () { return signals.snapshot; }
|
|
@@ -1306,10 +1476,12 @@ exports.createLoadingBoundary = createLoadingBoundary;
|
|
|
1306
1476
|
exports.createMemo = createMemo;
|
|
1307
1477
|
exports.createOptimistic = createOptimistic;
|
|
1308
1478
|
exports.createOptimisticStore = createOptimisticStore;
|
|
1479
|
+
exports.createOwner = createOwner;
|
|
1309
1480
|
exports.createProjection = createProjection;
|
|
1310
1481
|
exports.createReaction = createReaction;
|
|
1311
1482
|
exports.createRenderEffect = createRenderEffect;
|
|
1312
1483
|
exports.createRevealOrder = createRevealOrder;
|
|
1484
|
+
exports.createRoot = createRoot;
|
|
1313
1485
|
exports.createSignal = createSignal;
|
|
1314
1486
|
exports.createStore = createStore;
|
|
1315
1487
|
exports.createTrackedEffect = createTrackedEffect;
|
|
@@ -1317,19 +1489,23 @@ exports.createUniqueId = createUniqueId;
|
|
|
1317
1489
|
exports.deep = deep;
|
|
1318
1490
|
exports.enableHydration = enableHydration;
|
|
1319
1491
|
exports.flush = flush;
|
|
1492
|
+
exports.getNextChildId = getNextChildId;
|
|
1320
1493
|
exports.getObserver = getObserver;
|
|
1494
|
+
exports.getOwner = getOwner;
|
|
1495
|
+
exports.isDisposed = isDisposed;
|
|
1321
1496
|
exports.isPending = isPending;
|
|
1322
1497
|
exports.isRefreshing = isRefreshing;
|
|
1323
1498
|
exports.latest = latest;
|
|
1324
1499
|
exports.lazy = lazy;
|
|
1325
1500
|
exports.mapArray = mapArray;
|
|
1501
|
+
exports.onCleanup = onCleanup;
|
|
1326
1502
|
exports.onSettled = onSettled;
|
|
1327
1503
|
exports.reconcile = reconcile;
|
|
1328
1504
|
exports.refresh = refresh;
|
|
1329
1505
|
exports.repeat = repeat;
|
|
1330
1506
|
exports.resolve = resolve;
|
|
1507
|
+
exports.runWithOwner = runWithOwner;
|
|
1331
1508
|
exports.sharedConfig = sharedConfig;
|
|
1332
1509
|
exports.ssrHandleError = ssrHandleError;
|
|
1333
|
-
exports.ssrRunInScope = ssrRunInScope;
|
|
1334
1510
|
exports.untrack = untrack;
|
|
1335
1511
|
exports.useContext = useContext;
|