solid-js 1.7.8 → 1.7.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/dist/dev.cjs +35 -19
- package/dist/dev.js +558 -309
- package/dist/server.cjs +38 -23
- package/dist/server.js +202 -94
- package/dist/solid.cjs +35 -19
- package/dist/solid.js +485 -267
- package/h/dist/h.cjs +2 -2
- package/h/dist/h.js +36 -10
- package/h/jsx-runtime/dist/jsx.js +1 -1
- package/h/jsx-runtime/types/index.d.ts +11 -8
- package/h/jsx-runtime/types/jsx.d.ts +3 -0
- package/h/types/hyperscript.d.ts +11 -11
- package/h/types/index.d.ts +3 -2
- package/html/dist/html.cjs +2 -2
- package/html/dist/html.js +218 -96
- package/html/types/index.d.ts +3 -2
- package/html/types/lit.d.ts +45 -31
- package/package.json +1 -1
- package/store/dist/dev.cjs +36 -33
- package/store/dist/dev.js +143 -68
- package/store/dist/server.js +19 -8
- package/store/dist/store.cjs +36 -33
- package/store/dist/store.js +134 -65
- package/store/types/index.d.ts +21 -7
- package/store/types/modifiers.d.ts +6 -3
- package/store/types/mutable.d.ts +5 -2
- package/store/types/server.d.ts +12 -4
- package/store/types/store.d.ts +220 -63
- package/types/index.d.ts +72 -9
- package/types/jsx.d.ts +3 -0
- package/types/reactive/array.d.ts +12 -4
- package/types/reactive/observable.d.ts +25 -17
- package/types/reactive/scheduler.d.ts +9 -6
- package/types/reactive/signal.d.ts +237 -146
- package/types/render/Suspense.d.ts +5 -5
- package/types/render/component.d.ts +62 -31
- package/types/render/flow.d.ts +43 -31
- package/types/render/hydration.d.ts +12 -12
- package/types/server/index.d.ts +56 -2
- package/types/server/reactive.d.ts +71 -45
- package/types/server/rendering.d.ts +171 -95
- package/universal/dist/dev.js +28 -12
- package/universal/dist/universal.js +28 -12
- package/universal/types/index.d.ts +3 -1
- package/universal/types/universal.d.ts +0 -1
- package/web/dist/dev.js +610 -79
- package/web/dist/server.cjs +5 -1
- package/web/dist/server.js +181 -78
- package/web/dist/web.js +610 -79
- package/web/types/client.d.ts +2 -2
- package/web/types/core.d.ts +10 -1
- package/web/types/index.d.ts +27 -10
- package/web/types/server-mock.d.ts +47 -32
- package/web/types/server.d.ts +1 -1
package/dist/server.cjs
CHANGED
|
@@ -13,7 +13,7 @@ function castError(err) {
|
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
function handleError(err, owner = Owner) {
|
|
16
|
-
const fns =
|
|
16
|
+
const fns = owner && owner.context && owner.context[ERROR];
|
|
17
17
|
const error = castError(err);
|
|
18
18
|
if (!fns) throw error;
|
|
19
19
|
try {
|
|
@@ -32,7 +32,7 @@ let Owner = null;
|
|
|
32
32
|
function createOwner() {
|
|
33
33
|
const o = {
|
|
34
34
|
owner: Owner,
|
|
35
|
-
context: null,
|
|
35
|
+
context: Owner ? Owner.context : null,
|
|
36
36
|
owned: null,
|
|
37
37
|
cleanups: null
|
|
38
38
|
};
|
|
@@ -43,9 +43,10 @@ function createOwner() {
|
|
|
43
43
|
}
|
|
44
44
|
function createRoot(fn, detachedOwner) {
|
|
45
45
|
const owner = Owner,
|
|
46
|
+
current = detachedOwner === undefined ? owner : detachedOwner,
|
|
46
47
|
root = fn.length === 0 ? UNOWNED : {
|
|
47
|
-
context: null,
|
|
48
|
-
owner:
|
|
48
|
+
context: current ? current.context : null,
|
|
49
|
+
owner: current,
|
|
49
50
|
owned: null,
|
|
50
51
|
cleanups: null
|
|
51
52
|
};
|
|
@@ -135,14 +136,12 @@ function cleanNode(node) {
|
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
138
|
function catchError(fn, handler) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
context
|
|
141
|
-
|
|
142
|
-
},
|
|
143
|
-
owned: null,
|
|
144
|
-
cleanups: null
|
|
139
|
+
const owner = createOwner();
|
|
140
|
+
owner.context = {
|
|
141
|
+
...owner.context,
|
|
142
|
+
[ERROR]: [handler]
|
|
145
143
|
};
|
|
144
|
+
Owner = owner;
|
|
146
145
|
try {
|
|
147
146
|
return fn();
|
|
148
147
|
} catch (err) {
|
|
@@ -151,13 +150,6 @@ function catchError(fn, handler) {
|
|
|
151
150
|
Owner = Owner.owner;
|
|
152
151
|
}
|
|
153
152
|
}
|
|
154
|
-
function onError(fn) {
|
|
155
|
-
if (Owner) {
|
|
156
|
-
if (Owner.context === null) Owner.context = {
|
|
157
|
-
[ERROR]: [fn]
|
|
158
|
-
};else if (!Owner.context[ERROR]) Owner.context[ERROR] = [fn];else Owner.context[ERROR].push(fn);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
153
|
function getListener() {
|
|
162
154
|
return null;
|
|
163
155
|
}
|
|
@@ -170,8 +162,7 @@ function createContext(defaultValue) {
|
|
|
170
162
|
};
|
|
171
163
|
}
|
|
172
164
|
function useContext(context) {
|
|
173
|
-
|
|
174
|
-
return (ctx = lookup(Owner, context.id)) !== undefined ? ctx : context.defaultValue;
|
|
165
|
+
return Owner && Owner.context && Owner.context[context.id] !== undefined ? Owner.context[context.id] : context.defaultValue;
|
|
175
166
|
}
|
|
176
167
|
function getOwner() {
|
|
177
168
|
return Owner;
|
|
@@ -195,9 +186,6 @@ function runWithOwner(o, fn) {
|
|
|
195
186
|
Owner = prev;
|
|
196
187
|
}
|
|
197
188
|
}
|
|
198
|
-
function lookup(owner, key) {
|
|
199
|
-
return owner ? owner.context && owner.context[key] !== undefined ? owner.context[key] : lookup(owner.owner, key) : undefined;
|
|
200
|
-
}
|
|
201
189
|
function resolveChildren(children) {
|
|
202
190
|
if (typeof children === "function" && !children.length) return resolveChildren(children());
|
|
203
191
|
if (Array.isArray(children)) {
|
|
@@ -214,6 +202,7 @@ function createProvider(id) {
|
|
|
214
202
|
return function provider(props) {
|
|
215
203
|
return createMemo(() => {
|
|
216
204
|
Owner.context = {
|
|
205
|
+
...Owner.context,
|
|
217
206
|
[id]: props.value
|
|
218
207
|
};
|
|
219
208
|
return children(() => props.children);
|
|
@@ -279,6 +268,31 @@ function from(producer) {
|
|
|
279
268
|
return s;
|
|
280
269
|
}
|
|
281
270
|
function enableExternalSource(factory) {}
|
|
271
|
+
function onError(fn) {
|
|
272
|
+
if (Owner) {
|
|
273
|
+
if (Owner.context === null || !Owner.context[ERROR]) {
|
|
274
|
+
Owner.context = {
|
|
275
|
+
...Owner.context,
|
|
276
|
+
[ERROR]: [fn]
|
|
277
|
+
};
|
|
278
|
+
mutateContext(Owner, ERROR, [fn]);
|
|
279
|
+
} else Owner.context[ERROR].push(fn);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
function mutateContext(o, key, value) {
|
|
283
|
+
if (o.owned) {
|
|
284
|
+
for (let i = 0; i < o.owned.length; i++) {
|
|
285
|
+
if (o.owned[i].context === o.context) mutateContext(o.owned[i], key, value);
|
|
286
|
+
if (!o.owned[i].context) {
|
|
287
|
+
o.owned[i].context = o.context;
|
|
288
|
+
mutateContext(o.owned[i], key, value);
|
|
289
|
+
} else if (!o.owned[i].context[key]) {
|
|
290
|
+
o.owned[i].context[key] = value;
|
|
291
|
+
mutateContext(o.owned[i], key, value);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
282
296
|
|
|
283
297
|
function resolveSSRNode(node) {
|
|
284
298
|
const t = typeof node;
|
|
@@ -663,6 +677,7 @@ exports.Suspense = Suspense;
|
|
|
663
677
|
exports.SuspenseList = SuspenseList;
|
|
664
678
|
exports.Switch = Switch;
|
|
665
679
|
exports.batch = batch;
|
|
680
|
+
exports.catchError = catchError;
|
|
666
681
|
exports.children = children;
|
|
667
682
|
exports.createComponent = createComponent;
|
|
668
683
|
exports.createComputed = createComputed;
|
package/dist/server.js
CHANGED
|
@@ -11,13 +11,13 @@ function castError(err) {
|
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
function handleError(err, owner = Owner) {
|
|
14
|
-
const fns =
|
|
14
|
+
const fns = owner && owner.context && owner.context[ERROR];
|
|
15
15
|
const error = castError(err);
|
|
16
16
|
if (!fns) throw error;
|
|
17
17
|
try {
|
|
18
18
|
for (const f of fns) f(error);
|
|
19
19
|
} catch (e) {
|
|
20
|
-
handleError(e, owner && owner.owner || null);
|
|
20
|
+
handleError(e, (owner && owner.owner) || null);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
const UNOWNED = {
|
|
@@ -30,23 +30,28 @@ let Owner = null;
|
|
|
30
30
|
function createOwner() {
|
|
31
31
|
const o = {
|
|
32
32
|
owner: Owner,
|
|
33
|
-
context: null,
|
|
33
|
+
context: Owner ? Owner.context : null,
|
|
34
34
|
owned: null,
|
|
35
35
|
cleanups: null
|
|
36
36
|
};
|
|
37
37
|
if (Owner) {
|
|
38
|
-
if (!Owner.owned) Owner.owned = [o];
|
|
38
|
+
if (!Owner.owned) Owner.owned = [o];
|
|
39
|
+
else Owner.owned.push(o);
|
|
39
40
|
}
|
|
40
41
|
return o;
|
|
41
42
|
}
|
|
42
43
|
function createRoot(fn, detachedOwner) {
|
|
43
44
|
const owner = Owner,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
current = detachedOwner === undefined ? owner : detachedOwner,
|
|
46
|
+
root =
|
|
47
|
+
fn.length === 0
|
|
48
|
+
? UNOWNED
|
|
49
|
+
: {
|
|
50
|
+
context: current ? current.context : null,
|
|
51
|
+
owner: current,
|
|
52
|
+
owned: null,
|
|
53
|
+
cleanups: null
|
|
54
|
+
};
|
|
50
55
|
Owner = root;
|
|
51
56
|
let result;
|
|
52
57
|
try {
|
|
@@ -59,9 +64,12 @@ function createRoot(fn, detachedOwner) {
|
|
|
59
64
|
return result;
|
|
60
65
|
}
|
|
61
66
|
function createSignal(value, options) {
|
|
62
|
-
return [
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
return [
|
|
68
|
+
() => value,
|
|
69
|
+
v => {
|
|
70
|
+
return (value = typeof v === "function" ? v(value) : v);
|
|
71
|
+
}
|
|
72
|
+
];
|
|
65
73
|
}
|
|
66
74
|
function createComputed(fn, value) {
|
|
67
75
|
Owner = createOwner();
|
|
@@ -118,7 +126,8 @@ function on(deps, fn, options = {}) {
|
|
|
118
126
|
function onMount(fn) {}
|
|
119
127
|
function onCleanup(fn) {
|
|
120
128
|
if (Owner) {
|
|
121
|
-
if (!Owner.cleanups) Owner.cleanups = [fn];
|
|
129
|
+
if (!Owner.cleanups) Owner.cleanups = [fn];
|
|
130
|
+
else Owner.cleanups.push(fn);
|
|
122
131
|
}
|
|
123
132
|
return fn;
|
|
124
133
|
}
|
|
@@ -133,14 +142,12 @@ function cleanNode(node) {
|
|
|
133
142
|
}
|
|
134
143
|
}
|
|
135
144
|
function catchError(fn, handler) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
context
|
|
139
|
-
|
|
140
|
-
},
|
|
141
|
-
owned: null,
|
|
142
|
-
cleanups: null
|
|
145
|
+
const owner = createOwner();
|
|
146
|
+
owner.context = {
|
|
147
|
+
...owner.context,
|
|
148
|
+
[ERROR]: [handler]
|
|
143
149
|
};
|
|
150
|
+
Owner = owner;
|
|
144
151
|
try {
|
|
145
152
|
return fn();
|
|
146
153
|
} catch (err) {
|
|
@@ -149,13 +156,6 @@ function catchError(fn, handler) {
|
|
|
149
156
|
Owner = Owner.owner;
|
|
150
157
|
}
|
|
151
158
|
}
|
|
152
|
-
function onError(fn) {
|
|
153
|
-
if (Owner) {
|
|
154
|
-
if (Owner.context === null) Owner.context = {
|
|
155
|
-
[ERROR]: [fn]
|
|
156
|
-
};else if (!Owner.context[ERROR]) Owner.context[ERROR] = [fn];else Owner.context[ERROR].push(fn);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
159
|
function getListener() {
|
|
160
160
|
return null;
|
|
161
161
|
}
|
|
@@ -168,8 +168,9 @@ function createContext(defaultValue) {
|
|
|
168
168
|
};
|
|
169
169
|
}
|
|
170
170
|
function useContext(context) {
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
return Owner && Owner.context && Owner.context[context.id] !== undefined
|
|
172
|
+
? Owner.context[context.id]
|
|
173
|
+
: context.defaultValue;
|
|
173
174
|
}
|
|
174
175
|
function getOwner() {
|
|
175
176
|
return Owner;
|
|
@@ -193,9 +194,6 @@ function runWithOwner(o, fn) {
|
|
|
193
194
|
Owner = prev;
|
|
194
195
|
}
|
|
195
196
|
}
|
|
196
|
-
function lookup(owner, key) {
|
|
197
|
-
return owner ? owner.context && owner.context[key] !== undefined ? owner.context[key] : lookup(owner.owner, key) : undefined;
|
|
198
|
-
}
|
|
199
197
|
function resolveChildren(children) {
|
|
200
198
|
if (typeof children === "function" && !children.length) return resolveChildren(children());
|
|
201
199
|
if (Array.isArray(children)) {
|
|
@@ -212,6 +210,7 @@ function createProvider(id) {
|
|
|
212
210
|
return function provider(props) {
|
|
213
211
|
return createMemo(() => {
|
|
214
212
|
Owner.context = {
|
|
213
|
+
...Owner.context,
|
|
215
214
|
[id]: props.value
|
|
216
215
|
};
|
|
217
216
|
return children(() => props.children);
|
|
@@ -240,7 +239,8 @@ function observable(input) {
|
|
|
240
239
|
if (!(observer instanceof Object) || observer == null) {
|
|
241
240
|
throw new TypeError("Expected the observer to be an object.");
|
|
242
241
|
}
|
|
243
|
-
const handler =
|
|
242
|
+
const handler =
|
|
243
|
+
typeof observer === "function" ? observer : observer.next && observer.next.bind(observer);
|
|
244
244
|
if (!handler) {
|
|
245
245
|
return {
|
|
246
246
|
unsubscribe() {}
|
|
@@ -269,7 +269,7 @@ function from(producer) {
|
|
|
269
269
|
const [s, set] = createSignal(undefined);
|
|
270
270
|
if ("subscribe" in producer) {
|
|
271
271
|
const unsub = producer.subscribe(v => set(() => v));
|
|
272
|
-
onCleanup(() => "unsubscribe" in unsub ? unsub.unsubscribe() : unsub());
|
|
272
|
+
onCleanup(() => ("unsubscribe" in unsub ? unsub.unsubscribe() : unsub()));
|
|
273
273
|
} else {
|
|
274
274
|
const clean = producer(set);
|
|
275
275
|
onCleanup(clean);
|
|
@@ -277,6 +277,31 @@ function from(producer) {
|
|
|
277
277
|
return s;
|
|
278
278
|
}
|
|
279
279
|
function enableExternalSource(factory) {}
|
|
280
|
+
function onError(fn) {
|
|
281
|
+
if (Owner) {
|
|
282
|
+
if (Owner.context === null || !Owner.context[ERROR]) {
|
|
283
|
+
Owner.context = {
|
|
284
|
+
...Owner.context,
|
|
285
|
+
[ERROR]: [fn]
|
|
286
|
+
};
|
|
287
|
+
mutateContext(Owner, ERROR, [fn]);
|
|
288
|
+
} else Owner.context[ERROR].push(fn);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function mutateContext(o, key, value) {
|
|
292
|
+
if (o.owned) {
|
|
293
|
+
for (let i = 0; i < o.owned.length; i++) {
|
|
294
|
+
if (o.owned[i].context === o.context) mutateContext(o.owned[i], key, value);
|
|
295
|
+
if (!o.owned[i].context) {
|
|
296
|
+
o.owned[i].context = o.context;
|
|
297
|
+
mutateContext(o.owned[i], key, value);
|
|
298
|
+
} else if (!o.owned[i].context[key]) {
|
|
299
|
+
o.owned[i].context[key] = value;
|
|
300
|
+
mutateContext(o.owned[i], key, value);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
280
305
|
|
|
281
306
|
function resolveSSRNode(node) {
|
|
282
307
|
const t = typeof node;
|
|
@@ -296,11 +321,13 @@ function setHydrateContext(context) {
|
|
|
296
321
|
sharedConfig.context = context;
|
|
297
322
|
}
|
|
298
323
|
function nextHydrateContext() {
|
|
299
|
-
return sharedConfig.context
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
324
|
+
return sharedConfig.context
|
|
325
|
+
? {
|
|
326
|
+
...sharedConfig.context,
|
|
327
|
+
id: `${sharedConfig.context.id}${sharedConfig.context.count++}-`,
|
|
328
|
+
count: 0
|
|
329
|
+
}
|
|
330
|
+
: undefined;
|
|
304
331
|
}
|
|
305
332
|
function createUniqueId() {
|
|
306
333
|
const ctx = sharedConfig.context;
|
|
@@ -376,7 +403,11 @@ function Index(props) {
|
|
|
376
403
|
}
|
|
377
404
|
function Show(props) {
|
|
378
405
|
let c;
|
|
379
|
-
return props.when
|
|
406
|
+
return props.when
|
|
407
|
+
? typeof (c = props.children) === "function"
|
|
408
|
+
? c(props.keyed ? props.when : () => props.when)
|
|
409
|
+
: c
|
|
410
|
+
: props.fallback || "";
|
|
380
411
|
}
|
|
381
412
|
function Switch(props) {
|
|
382
413
|
let conditions = props.children;
|
|
@@ -413,11 +444,14 @@ function ErrorBoundary(props) {
|
|
|
413
444
|
}
|
|
414
445
|
createMemo(() => {
|
|
415
446
|
clean = Owner;
|
|
416
|
-
return catchError(
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
447
|
+
return catchError(
|
|
448
|
+
() => (res = props.children),
|
|
449
|
+
err => {
|
|
450
|
+
error = err;
|
|
451
|
+
!sync && ctx.replace("e" + id, displayFallback);
|
|
452
|
+
sync = true;
|
|
453
|
+
}
|
|
454
|
+
);
|
|
421
455
|
});
|
|
422
456
|
if (error) return displayFallback();
|
|
423
457
|
sync = false;
|
|
@@ -447,14 +481,18 @@ function createResource(source, fetcher, options = {}) {
|
|
|
447
481
|
if (sharedConfig.context.async && options.ssrLoadFrom !== "initial") {
|
|
448
482
|
resource = sharedConfig.context.resources[id] || (sharedConfig.context.resources[id] = {});
|
|
449
483
|
if (resource.ref) {
|
|
450
|
-
if (!resource.data && !resource.ref[0].loading && !resource.ref[0].error)
|
|
484
|
+
if (!resource.data && !resource.ref[0].loading && !resource.ref[0].error)
|
|
485
|
+
resource.ref[1].refetch();
|
|
451
486
|
return resource.ref;
|
|
452
487
|
}
|
|
453
488
|
}
|
|
454
489
|
const read = () => {
|
|
455
490
|
if (error) throw error;
|
|
456
491
|
if (resourceContext && p) resourceContext.push(p);
|
|
457
|
-
const resolved =
|
|
492
|
+
const resolved =
|
|
493
|
+
options.ssrLoadFrom !== "initial" &&
|
|
494
|
+
sharedConfig.context.async &&
|
|
495
|
+
"data" in sharedConfig.context.resources[id];
|
|
458
496
|
if (!resolved && read.loading) {
|
|
459
497
|
const ctx = useContext(SuspenseContext);
|
|
460
498
|
if (ctx) {
|
|
@@ -474,7 +512,7 @@ function createResource(source, fetcher, options = {}) {
|
|
|
474
512
|
});
|
|
475
513
|
function load() {
|
|
476
514
|
const ctx = sharedConfig.context;
|
|
477
|
-
if (!ctx.async) return read.loading = !!(typeof source === "function" ? source() : source);
|
|
515
|
+
if (!ctx.async) return (read.loading = !!(typeof source === "function" ? source() : source));
|
|
478
516
|
if (ctx.resources && id in ctx.resources && "data" in ctx.resources[id]) {
|
|
479
517
|
value = ctx.resources[id].data;
|
|
480
518
|
return;
|
|
@@ -482,9 +520,11 @@ function createResource(source, fetcher, options = {}) {
|
|
|
482
520
|
resourceContext = [];
|
|
483
521
|
const lookup = typeof source === "function" ? source() : source;
|
|
484
522
|
if (resourceContext.length) {
|
|
485
|
-
p = Promise.all(resourceContext).then(() =>
|
|
486
|
-
|
|
487
|
-
|
|
523
|
+
p = Promise.all(resourceContext).then(() =>
|
|
524
|
+
fetcher(source(), {
|
|
525
|
+
value
|
|
526
|
+
})
|
|
527
|
+
);
|
|
488
528
|
}
|
|
489
529
|
resourceContext = null;
|
|
490
530
|
if (!p) {
|
|
@@ -497,20 +537,22 @@ function createResource(source, fetcher, options = {}) {
|
|
|
497
537
|
read.loading = true;
|
|
498
538
|
read.state = "pending";
|
|
499
539
|
if (ctx.writeResource) ctx.writeResource(id, p, undefined, options.deferStream);
|
|
500
|
-
return p
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
540
|
+
return p
|
|
541
|
+
.then(res => {
|
|
542
|
+
read.loading = false;
|
|
543
|
+
read.state = "ready";
|
|
544
|
+
ctx.resources[id].data = res;
|
|
545
|
+
p = null;
|
|
546
|
+
notifySuspense(contexts);
|
|
547
|
+
return res;
|
|
548
|
+
})
|
|
549
|
+
.catch(err => {
|
|
550
|
+
read.loading = false;
|
|
551
|
+
read.state = "errored";
|
|
552
|
+
read.error = error = castError(err);
|
|
553
|
+
p = null;
|
|
554
|
+
notifySuspense(contexts);
|
|
555
|
+
});
|
|
514
556
|
}
|
|
515
557
|
ctx.resources[id].data = p;
|
|
516
558
|
if (ctx.writeResource) ctx.writeResource(id, p);
|
|
@@ -518,17 +560,20 @@ function createResource(source, fetcher, options = {}) {
|
|
|
518
560
|
return ctx.resources[id].data;
|
|
519
561
|
}
|
|
520
562
|
if (options.ssrLoadFrom !== "initial") load();
|
|
521
|
-
return resource.ref = [
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
563
|
+
return (resource.ref = [
|
|
564
|
+
read,
|
|
565
|
+
{
|
|
566
|
+
refetch: load,
|
|
567
|
+
mutate: v => (value = v)
|
|
568
|
+
}
|
|
569
|
+
]);
|
|
525
570
|
}
|
|
526
571
|
function lazy(fn) {
|
|
527
572
|
let p;
|
|
528
573
|
let load = id => {
|
|
529
574
|
if (!p) {
|
|
530
575
|
p = fn();
|
|
531
|
-
p.then(mod => p.resolved = mod.default);
|
|
576
|
+
p.then(mod => (p.resolved = mod.default));
|
|
532
577
|
if (id) sharedConfig.context.lazy[id] = p;
|
|
533
578
|
}
|
|
534
579
|
return p;
|
|
@@ -537,7 +582,8 @@ function lazy(fn) {
|
|
|
537
582
|
const wrap = props => {
|
|
538
583
|
const id = sharedConfig.context.id.slice(0, -1);
|
|
539
584
|
let ref = sharedConfig.context.lazy[id];
|
|
540
|
-
if (ref) p = ref;
|
|
585
|
+
if (ref) p = ref;
|
|
586
|
+
else load(id);
|
|
541
587
|
if (p.resolved) return p.resolved(props);
|
|
542
588
|
const ctx = useContext(SuspenseContext);
|
|
543
589
|
const track = {
|
|
@@ -549,10 +595,12 @@ function lazy(fn) {
|
|
|
549
595
|
contexts.add(ctx);
|
|
550
596
|
}
|
|
551
597
|
if (sharedConfig.context.async) {
|
|
552
|
-
sharedConfig.context.block(
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
598
|
+
sharedConfig.context.block(
|
|
599
|
+
p.then(() => {
|
|
600
|
+
track.loading = false;
|
|
601
|
+
notifySuspense(contexts);
|
|
602
|
+
})
|
|
603
|
+
);
|
|
556
604
|
}
|
|
557
605
|
return "";
|
|
558
606
|
};
|
|
@@ -580,9 +628,12 @@ function startTransition(fn) {
|
|
|
580
628
|
fn();
|
|
581
629
|
}
|
|
582
630
|
function useTransition() {
|
|
583
|
-
return [
|
|
584
|
-
|
|
585
|
-
|
|
631
|
+
return [
|
|
632
|
+
() => false,
|
|
633
|
+
fn => {
|
|
634
|
+
fn();
|
|
635
|
+
}
|
|
636
|
+
];
|
|
586
637
|
}
|
|
587
638
|
function SuspenseList(props) {
|
|
588
639
|
return props.children;
|
|
@@ -592,15 +643,17 @@ function Suspense(props) {
|
|
|
592
643
|
const ctx = sharedConfig.context;
|
|
593
644
|
const id = ctx.id + ctx.count;
|
|
594
645
|
const o = createOwner();
|
|
595
|
-
const value =
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
646
|
+
const value =
|
|
647
|
+
ctx.suspense[id] ||
|
|
648
|
+
(ctx.suspense[id] = {
|
|
649
|
+
resources: new Map(),
|
|
650
|
+
completed: () => {
|
|
651
|
+
const res = runSuspense();
|
|
652
|
+
if (suspenseComplete(value)) {
|
|
653
|
+
done(resolveSSRNode(res));
|
|
654
|
+
}
|
|
601
655
|
}
|
|
602
|
-
}
|
|
603
|
-
});
|
|
656
|
+
});
|
|
604
657
|
function suspenseError(err) {
|
|
605
658
|
if (!done || !done(undefined, err)) {
|
|
606
659
|
runWithOwner(o.owner, () => {
|
|
@@ -614,12 +667,14 @@ function Suspense(props) {
|
|
|
614
667
|
count: 0
|
|
615
668
|
});
|
|
616
669
|
cleanNode(o);
|
|
617
|
-
return runWithOwner(o, () =>
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
670
|
+
return runWithOwner(o, () =>
|
|
671
|
+
createComponent(SuspenseContext.Provider, {
|
|
672
|
+
value,
|
|
673
|
+
get children() {
|
|
674
|
+
return catchError(() => props.children, suspenseError);
|
|
675
|
+
}
|
|
676
|
+
})
|
|
677
|
+
);
|
|
623
678
|
}
|
|
624
679
|
const res = runSuspense();
|
|
625
680
|
if (suspenseComplete(value)) return res;
|
|
@@ -648,4 +703,57 @@ function Suspense(props) {
|
|
|
648
703
|
}, suspenseError);
|
|
649
704
|
}
|
|
650
705
|
|
|
651
|
-
export {
|
|
706
|
+
export {
|
|
707
|
+
$DEVCOMP,
|
|
708
|
+
$PROXY,
|
|
709
|
+
$TRACK,
|
|
710
|
+
DEV,
|
|
711
|
+
ErrorBoundary,
|
|
712
|
+
For,
|
|
713
|
+
Index,
|
|
714
|
+
Match,
|
|
715
|
+
Show,
|
|
716
|
+
Suspense,
|
|
717
|
+
SuspenseList,
|
|
718
|
+
Switch,
|
|
719
|
+
batch,
|
|
720
|
+
catchError,
|
|
721
|
+
children,
|
|
722
|
+
createComponent,
|
|
723
|
+
createComputed,
|
|
724
|
+
createContext,
|
|
725
|
+
createDeferred,
|
|
726
|
+
createEffect,
|
|
727
|
+
createMemo,
|
|
728
|
+
createReaction,
|
|
729
|
+
createRenderEffect,
|
|
730
|
+
createResource,
|
|
731
|
+
createRoot,
|
|
732
|
+
createSelector,
|
|
733
|
+
createSignal,
|
|
734
|
+
createUniqueId,
|
|
735
|
+
enableExternalSource,
|
|
736
|
+
enableHydration,
|
|
737
|
+
enableScheduling,
|
|
738
|
+
equalFn,
|
|
739
|
+
from,
|
|
740
|
+
getListener,
|
|
741
|
+
getOwner,
|
|
742
|
+
lazy,
|
|
743
|
+
mapArray,
|
|
744
|
+
mergeProps,
|
|
745
|
+
observable,
|
|
746
|
+
on,
|
|
747
|
+
onCleanup,
|
|
748
|
+
onError,
|
|
749
|
+
onMount,
|
|
750
|
+
requestCallback,
|
|
751
|
+
resetErrorBoundaries,
|
|
752
|
+
runWithOwner,
|
|
753
|
+
sharedConfig,
|
|
754
|
+
splitProps,
|
|
755
|
+
startTransition,
|
|
756
|
+
untrack,
|
|
757
|
+
useContext,
|
|
758
|
+
useTransition
|
|
759
|
+
};
|