solid-js 1.2.5 → 1.3.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/README.md +3 -1
- package/dist/dev.cjs +137 -46
- package/dist/dev.js +135 -46
- package/dist/server.cjs +70 -60
- package/dist/server.js +70 -60
- package/dist/solid.cjs +137 -46
- package/dist/solid.js +135 -46
- package/package.json +27 -15
- package/types/index.d.ts +2 -3
- package/types/reactive/signal.d.ts +98 -82
- package/types/render/component.d.ts +4 -1
- package/types/render/hydration.d.ts +3 -2
- package/types/server/index.d.ts +2 -2
- package/types/server/reactive.d.ts +2 -2
- package/types/server/rendering.d.ts +7 -5
- package/web/dist/dev.cjs +32 -24
- package/web/dist/dev.js +33 -23
- package/web/dist/server.cjs +219 -135
- package/web/dist/server.js +220 -137
- package/web/dist/web.cjs +32 -24
- package/web/dist/web.js +33 -23
- package/web/types/client.d.ts +11 -3
- package/web/types/core.d.ts +2 -2
- package/web/types/index.d.ts +2 -0
- package/web/types/server-mock.d.ts +33 -20
package/dist/dev.js
CHANGED
|
@@ -145,6 +145,7 @@ const [transPending, setTransPending] = /*@__PURE__*/createSignal(false);
|
|
|
145
145
|
var Owner = null;
|
|
146
146
|
let Transition = null;
|
|
147
147
|
let Scheduler = null;
|
|
148
|
+
let ExternalSourceFactory = null;
|
|
148
149
|
let Listener = null;
|
|
149
150
|
let Pending = null;
|
|
150
151
|
let Updates = null;
|
|
@@ -183,12 +184,13 @@ function createSignal(value, options) {
|
|
|
183
184
|
comparator: options.equals || undefined
|
|
184
185
|
};
|
|
185
186
|
if (!options.internal) s.name = registerGraph(options.name || hashValue(value), s);
|
|
186
|
-
|
|
187
|
+
const setter = value => {
|
|
187
188
|
if (typeof value === "function") {
|
|
188
189
|
if (Transition && Transition.running && Transition.sources.has(s)) value = value(s.pending !== NOTPENDING ? s.pending : s.tValue);else value = value(s.pending !== NOTPENDING ? s.pending : s.value);
|
|
189
190
|
}
|
|
190
191
|
return writeSignal(s, value);
|
|
191
|
-
}
|
|
192
|
+
};
|
|
193
|
+
return [readSignal.bind(s), setter];
|
|
192
194
|
}
|
|
193
195
|
function createComputed(fn, value, options) {
|
|
194
196
|
const c = createComputation(fn, value, true, STALE, options );
|
|
@@ -230,6 +232,9 @@ function createResource(source, fetcher, options) {
|
|
|
230
232
|
fetcher = source;
|
|
231
233
|
source = true;
|
|
232
234
|
}
|
|
235
|
+
Resources || (Resources = new Set());
|
|
236
|
+
Resources.add(load);
|
|
237
|
+
onCleanup(() => Resources.delete(load));
|
|
233
238
|
const contexts = new Set(),
|
|
234
239
|
[s, set] = createSignal((options || {}).initialValue),
|
|
235
240
|
[track, trigger] = createSignal(undefined, {
|
|
@@ -245,12 +250,7 @@ function createResource(source, fetcher, options) {
|
|
|
245
250
|
dynamic = typeof source === "function";
|
|
246
251
|
if (sharedConfig.context) {
|
|
247
252
|
id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
|
|
248
|
-
if (sharedConfig.
|
|
249
|
-
initP = sharedConfig.context.loadResource(id);
|
|
250
|
-
} else if (sharedConfig.resources && id && id in sharedConfig.resources) {
|
|
251
|
-
initP = sharedConfig.resources[id];
|
|
252
|
-
delete sharedConfig.resources[id];
|
|
253
|
-
}
|
|
253
|
+
if (sharedConfig.load) initP = sharedConfig.load(id);
|
|
254
254
|
}
|
|
255
255
|
function loadEnd(p, v, e) {
|
|
256
256
|
if (pr === p) {
|
|
@@ -296,7 +296,7 @@ function createResource(source, fetcher, options) {
|
|
|
296
296
|
}
|
|
297
297
|
return v;
|
|
298
298
|
}
|
|
299
|
-
function load() {
|
|
299
|
+
function load(refetching = true) {
|
|
300
300
|
setError(err = undefined);
|
|
301
301
|
const lookup = dynamic ? source() : source;
|
|
302
302
|
loadedUnderTransition = Transition && Transition.running;
|
|
@@ -305,7 +305,10 @@ function createResource(source, fetcher, options) {
|
|
|
305
305
|
return;
|
|
306
306
|
}
|
|
307
307
|
if (Transition && pr) Transition.promises.delete(pr);
|
|
308
|
-
const p = initP || untrack(() => fetcher(lookup,
|
|
308
|
+
const p = initP || untrack(() => fetcher(lookup, {
|
|
309
|
+
value: s(),
|
|
310
|
+
refetching
|
|
311
|
+
}));
|
|
309
312
|
initP = null;
|
|
310
313
|
if (typeof p !== "object" || !("then" in p)) {
|
|
311
314
|
loadEnd(pr, p);
|
|
@@ -330,12 +333,16 @@ function createResource(source, fetcher, options) {
|
|
|
330
333
|
}
|
|
331
334
|
}
|
|
332
335
|
});
|
|
333
|
-
if (dynamic) createComputed(load);else load();
|
|
336
|
+
if (dynamic) createComputed(() => load(false));else load(false);
|
|
334
337
|
return [read, {
|
|
335
338
|
refetch: load,
|
|
336
339
|
mutate: set
|
|
337
340
|
}];
|
|
338
341
|
}
|
|
342
|
+
let Resources;
|
|
343
|
+
function refetchResources(info) {
|
|
344
|
+
Resources && Resources.forEach(fn => fn(info));
|
|
345
|
+
}
|
|
339
346
|
function createDeferred(source, options) {
|
|
340
347
|
let t,
|
|
341
348
|
timeout = options ? options.timeoutMs : undefined;
|
|
@@ -354,7 +361,7 @@ function createSelector(source, fn = equalFn, options) {
|
|
|
354
361
|
const subs = new Map();
|
|
355
362
|
const node = createComputation(p => {
|
|
356
363
|
const v = source();
|
|
357
|
-
for (const key of subs.keys()) if (fn(key, v)
|
|
364
|
+
for (const key of subs.keys()) if (fn(key, v) !== (p !== undefined && fn(key, p))) {
|
|
358
365
|
const l = subs.get(key);
|
|
359
366
|
for (const c of l.values()) {
|
|
360
367
|
c.state = STALE;
|
|
@@ -405,7 +412,8 @@ function untrack(fn) {
|
|
|
405
412
|
Listener = listener;
|
|
406
413
|
return result;
|
|
407
414
|
}
|
|
408
|
-
function on(deps, fn,
|
|
415
|
+
function on(deps, fn,
|
|
416
|
+
options) {
|
|
409
417
|
const isArray = Array.isArray(deps);
|
|
410
418
|
let prevInput;
|
|
411
419
|
let defer = options && options.defer;
|
|
@@ -553,6 +561,24 @@ let SuspenseContext;
|
|
|
553
561
|
function getSuspenseContext() {
|
|
554
562
|
return SuspenseContext || (SuspenseContext = createContext({}));
|
|
555
563
|
}
|
|
564
|
+
function enableExternalSource(factory) {
|
|
565
|
+
if (ExternalSourceFactory) {
|
|
566
|
+
const oldFactory = ExternalSourceFactory;
|
|
567
|
+
ExternalSourceFactory = (fn, trigger) => {
|
|
568
|
+
const oldSource = oldFactory(fn, trigger);
|
|
569
|
+
const source = factory(x => oldSource.track(x), trigger);
|
|
570
|
+
return {
|
|
571
|
+
track: x => source.track(x),
|
|
572
|
+
dispose() {
|
|
573
|
+
source.dispose();
|
|
574
|
+
oldSource.dispose();
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
};
|
|
578
|
+
} else {
|
|
579
|
+
ExternalSourceFactory = factory;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
556
582
|
function readSignal() {
|
|
557
583
|
const runningTransition = Transition && Transition.running;
|
|
558
584
|
if (this.sources && (!runningTransition && this.state || runningTransition && this.tState)) {
|
|
@@ -681,6 +707,19 @@ function createComputation(fn, init, pure, state = STALE, options) {
|
|
|
681
707
|
}
|
|
682
708
|
c.name = options && options.name || `${Owner.name || "c"}-${(Owner.owned || Owner.tOwned).length}`;
|
|
683
709
|
}
|
|
710
|
+
if (ExternalSourceFactory) {
|
|
711
|
+
const [track, trigger] = createSignal(undefined, {
|
|
712
|
+
equals: false
|
|
713
|
+
});
|
|
714
|
+
const ordinary = ExternalSourceFactory(c.fn, trigger);
|
|
715
|
+
onCleanup(() => ordinary.dispose());
|
|
716
|
+
const triggerInTransition = () => startTransition(trigger, () => inTransition.dispose());
|
|
717
|
+
const inTransition = ExternalSourceFactory(c.fn, triggerInTransition);
|
|
718
|
+
c.fn = x => {
|
|
719
|
+
track();
|
|
720
|
+
return Transition && Transition.running ? inTransition.track(x) : ordinary.track(x);
|
|
721
|
+
};
|
|
722
|
+
}
|
|
684
723
|
return c;
|
|
685
724
|
}
|
|
686
725
|
function runTop(node) {
|
|
@@ -707,7 +746,7 @@ function runTop(node) {
|
|
|
707
746
|
} else if (!runningTransition && node.state === PENDING || runningTransition && node.tState === PENDING) {
|
|
708
747
|
const updates = Updates;
|
|
709
748
|
Updates = null;
|
|
710
|
-
lookDownstream(node);
|
|
749
|
+
lookDownstream(node, ancestors[0]);
|
|
711
750
|
Updates = updates;
|
|
712
751
|
}
|
|
713
752
|
}
|
|
@@ -806,13 +845,15 @@ function runUserEffects(queue) {
|
|
|
806
845
|
for (i = 0; i < userLength; i++) runTop(queue[i]);
|
|
807
846
|
for (i = resume; i < queue.length; i++) runTop(queue[i]);
|
|
808
847
|
}
|
|
809
|
-
function lookDownstream(node) {
|
|
848
|
+
function lookDownstream(node, ignore) {
|
|
810
849
|
node.state = 0;
|
|
811
850
|
const runningTransition = Transition && Transition.running;
|
|
812
851
|
for (let i = 0; i < node.sources.length; i += 1) {
|
|
813
852
|
const source = node.sources[i];
|
|
814
853
|
if (source.sources) {
|
|
815
|
-
if (!runningTransition && source.state === STALE || runningTransition && source.tState === STALE)
|
|
854
|
+
if (!runningTransition && source.state === STALE || runningTransition && source.tState === STALE) {
|
|
855
|
+
if (source !== ignore) runTop(source);
|
|
856
|
+
} else if (!runningTransition && source.state === PENDING || runningTransition && source.tState === PENDING) lookDownstream(source, ignore);
|
|
816
857
|
}
|
|
817
858
|
}
|
|
818
859
|
}
|
|
@@ -1136,13 +1177,19 @@ function indexArray(list, mapFn, options = {}) {
|
|
|
1136
1177
|
};
|
|
1137
1178
|
}
|
|
1138
1179
|
|
|
1180
|
+
let hydrationEnabled = false;
|
|
1181
|
+
function enableHydration() {
|
|
1182
|
+
hydrationEnabled = true;
|
|
1183
|
+
}
|
|
1139
1184
|
function createComponent(Comp, props) {
|
|
1140
|
-
if (
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1185
|
+
if (hydrationEnabled) {
|
|
1186
|
+
if (sharedConfig.context) {
|
|
1187
|
+
const c = sharedConfig.context;
|
|
1188
|
+
setHydrateContext(nextHydrateContext());
|
|
1189
|
+
const r = devComponent(Comp, props) ;
|
|
1190
|
+
setHydrateContext(c);
|
|
1191
|
+
return r;
|
|
1192
|
+
}
|
|
1146
1193
|
}
|
|
1147
1194
|
return devComponent(Comp, props);
|
|
1148
1195
|
}
|
|
@@ -1231,19 +1278,20 @@ function splitProps(props, ...keys) {
|
|
|
1231
1278
|
}
|
|
1232
1279
|
function lazy(fn) {
|
|
1233
1280
|
let comp;
|
|
1281
|
+
let p;
|
|
1234
1282
|
const wrap = props => {
|
|
1235
1283
|
const ctx = sharedConfig.context;
|
|
1236
|
-
if (ctx
|
|
1284
|
+
if (ctx) {
|
|
1237
1285
|
ctx.count++;
|
|
1238
1286
|
const [s, set] = createSignal();
|
|
1239
|
-
fn().then(mod => {
|
|
1287
|
+
(p || (p = fn())).then(mod => {
|
|
1240
1288
|
setHydrateContext(ctx);
|
|
1241
1289
|
set(() => mod.default);
|
|
1242
|
-
setHydrateContext(
|
|
1290
|
+
setHydrateContext();
|
|
1243
1291
|
});
|
|
1244
1292
|
comp = s;
|
|
1245
1293
|
} else if (!comp) {
|
|
1246
|
-
const [s] = createResource(() => fn().then(mod => mod.default));
|
|
1294
|
+
const [s] = createResource(() => (p || (p = fn())).then(mod => mod.default));
|
|
1247
1295
|
comp = s;
|
|
1248
1296
|
} else {
|
|
1249
1297
|
const c = comp();
|
|
@@ -1259,7 +1307,7 @@ function lazy(fn) {
|
|
|
1259
1307
|
return r;
|
|
1260
1308
|
}));
|
|
1261
1309
|
};
|
|
1262
|
-
wrap.preload = () =>
|
|
1310
|
+
wrap.preload = () => p || ((p = fn()).then(mod => comp = () => mod.default), p);
|
|
1263
1311
|
return wrap;
|
|
1264
1312
|
}
|
|
1265
1313
|
let counter = 0;
|
|
@@ -1306,7 +1354,7 @@ function Switch(props) {
|
|
|
1306
1354
|
}
|
|
1307
1355
|
return [-1];
|
|
1308
1356
|
}, undefined, {
|
|
1309
|
-
equals: (a, b) => a
|
|
1357
|
+
equals: (a, b) => a[0] === b[0] && (strictEqual ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]
|
|
1310
1358
|
});
|
|
1311
1359
|
return createMemo(() => {
|
|
1312
1360
|
const [index, when, cond] = evalConditions();
|
|
@@ -1319,7 +1367,11 @@ function Match(props) {
|
|
|
1319
1367
|
return props;
|
|
1320
1368
|
}
|
|
1321
1369
|
function ErrorBoundary(props) {
|
|
1322
|
-
|
|
1370
|
+
let err = undefined;
|
|
1371
|
+
if (sharedConfig.context && sharedConfig.load) {
|
|
1372
|
+
err = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count);
|
|
1373
|
+
}
|
|
1374
|
+
const [errored, setErrored] = createSignal(err);
|
|
1323
1375
|
let e;
|
|
1324
1376
|
return createMemo(() => {
|
|
1325
1377
|
if ((e = errored()) != null) {
|
|
@@ -1400,7 +1452,11 @@ function SuspenseList(props) {
|
|
|
1400
1452
|
function Suspense(props) {
|
|
1401
1453
|
let counter = 0,
|
|
1402
1454
|
showContent,
|
|
1403
|
-
showFallback
|
|
1455
|
+
showFallback,
|
|
1456
|
+
ctx,
|
|
1457
|
+
p,
|
|
1458
|
+
flicker,
|
|
1459
|
+
error;
|
|
1404
1460
|
const [inFallback, setFallback] = createSignal(false),
|
|
1405
1461
|
SuspenseContext = getSuspenseContext(),
|
|
1406
1462
|
store = {
|
|
@@ -1415,6 +1471,24 @@ function Suspense(props) {
|
|
|
1415
1471
|
resolved: false
|
|
1416
1472
|
},
|
|
1417
1473
|
owner = getOwner();
|
|
1474
|
+
if (sharedConfig.context) {
|
|
1475
|
+
const key = sharedConfig.context.id + sharedConfig.context.count;
|
|
1476
|
+
p = sharedConfig.load(key);
|
|
1477
|
+
if (p && typeof p === "object") {
|
|
1478
|
+
const [s, set] = createSignal(undefined, {
|
|
1479
|
+
equals: false
|
|
1480
|
+
});
|
|
1481
|
+
flicker = s;
|
|
1482
|
+
p.then(err => {
|
|
1483
|
+
if (error = err) return set();
|
|
1484
|
+
sharedConfig.gather(key);
|
|
1485
|
+
setHydrateContext(ctx);
|
|
1486
|
+
set();
|
|
1487
|
+
setHydrateContext();
|
|
1488
|
+
p = undefined;
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1418
1492
|
const listContext = useContext(SuspenseListContext);
|
|
1419
1493
|
if (listContext) [showContent, showFallback] = listContext.register(store.inFallback);
|
|
1420
1494
|
let dispose;
|
|
@@ -1422,28 +1496,43 @@ function Suspense(props) {
|
|
|
1422
1496
|
return createComponent(SuspenseContext.Provider, {
|
|
1423
1497
|
value: store,
|
|
1424
1498
|
get children() {
|
|
1425
|
-
const rendered = untrack(() => props.children);
|
|
1426
1499
|
return createMemo(() => {
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
store.resolved = true;
|
|
1433
|
-
resumeEffects(store.effects);
|
|
1434
|
-
return rendered;
|
|
1500
|
+
if (error) throw error;
|
|
1501
|
+
ctx = sharedConfig.context;
|
|
1502
|
+
if (flicker) {
|
|
1503
|
+
flicker();
|
|
1504
|
+
return flicker = undefined;
|
|
1435
1505
|
}
|
|
1436
|
-
if (
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1506
|
+
if (ctx && p === undefined) setHydrateContext();
|
|
1507
|
+
const rendered = untrack(() => props.children);
|
|
1508
|
+
return createMemo(() => {
|
|
1509
|
+
const inFallback = store.inFallback(),
|
|
1510
|
+
visibleContent = showContent ? showContent() : true,
|
|
1511
|
+
visibleFallback = showFallback ? showFallback() : true;
|
|
1512
|
+
dispose && dispose();
|
|
1513
|
+
if ((!inFallback || p !== undefined) && visibleContent) {
|
|
1514
|
+
store.resolved = true;
|
|
1515
|
+
resumeEffects(store.effects);
|
|
1516
|
+
return rendered;
|
|
1517
|
+
}
|
|
1518
|
+
if (!visibleFallback) return;
|
|
1519
|
+
return createRoot(disposer => {
|
|
1520
|
+
dispose = disposer;
|
|
1521
|
+
if (ctx) {
|
|
1522
|
+
setHydrateContext({
|
|
1523
|
+
id: ctx.id + "f",
|
|
1524
|
+
count: 0
|
|
1525
|
+
});
|
|
1526
|
+
ctx = undefined;
|
|
1527
|
+
}
|
|
1528
|
+
return props.fallback;
|
|
1529
|
+
}, owner);
|
|
1530
|
+
});
|
|
1441
1531
|
});
|
|
1442
1532
|
}
|
|
1443
1533
|
});
|
|
1444
1534
|
}
|
|
1445
1535
|
|
|
1446
|
-
function awaitSuspense() {}
|
|
1447
1536
|
let DEV;
|
|
1448
1537
|
{
|
|
1449
1538
|
DEV = {
|
|
@@ -1457,4 +1546,4 @@ if (globalThis) {
|
|
|
1457
1546
|
if (!globalThis.Solid$$) globalThis.Solid$$ = true;else console.warn("You appear to have multiple instances of Solid. This can lead to unexpected behavior.");
|
|
1458
1547
|
}
|
|
1459
1548
|
|
|
1460
|
-
export { $PROXY, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch,
|
|
1549
|
+
export { $PROXY, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, batch, cancelCallback, children, createComponent, createComputed, createContext, createDeferred, createEffect, createMemo, createRenderEffect, createResource, createRoot, createSelector, createSignal, createUniqueId, enableExternalSource, enableHydration, enableScheduling, equalFn, from, getListener, getOwner, indexArray, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, refetchResources, requestCallback, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition };
|
package/dist/server.cjs
CHANGED
|
@@ -41,8 +41,15 @@ function createComputed(fn, value) {
|
|
|
41
41
|
owner: Owner,
|
|
42
42
|
context: null
|
|
43
43
|
};
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
try {
|
|
45
|
+
fn(value);
|
|
46
|
+
} catch (err) {
|
|
47
|
+
const fns = lookup(Owner, ERROR);
|
|
48
|
+
if (!fns) throw err;
|
|
49
|
+
fns.forEach(f => f(err));
|
|
50
|
+
} finally {
|
|
51
|
+
Owner = Owner.owner;
|
|
52
|
+
}
|
|
46
53
|
}
|
|
47
54
|
const createRenderEffect = createComputed;
|
|
48
55
|
function createEffect(fn, value) {}
|
|
@@ -51,8 +58,16 @@ function createMemo(fn, value) {
|
|
|
51
58
|
owner: Owner,
|
|
52
59
|
context: null
|
|
53
60
|
};
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
let v;
|
|
62
|
+
try {
|
|
63
|
+
v = fn(value);
|
|
64
|
+
} catch (err) {
|
|
65
|
+
const fns = lookup(Owner, ERROR);
|
|
66
|
+
if (!fns) throw err;
|
|
67
|
+
fns.forEach(f => f(err));
|
|
68
|
+
} finally {
|
|
69
|
+
Owner = Owner.owner;
|
|
70
|
+
}
|
|
56
71
|
return () => v;
|
|
57
72
|
}
|
|
58
73
|
function createDeferred(source) {
|
|
@@ -193,6 +208,7 @@ function from(producer) {
|
|
|
193
208
|
}
|
|
194
209
|
return s;
|
|
195
210
|
}
|
|
211
|
+
function enableExternalSource(factory) {}
|
|
196
212
|
|
|
197
213
|
function resolveSSRNode(node) {
|
|
198
214
|
const t = typeof node;
|
|
@@ -219,7 +235,7 @@ function createUniqueId() {
|
|
|
219
235
|
return `${ctx.id}${ctx.count++}`;
|
|
220
236
|
}
|
|
221
237
|
function createComponent(Comp, props) {
|
|
222
|
-
if (sharedConfig.context) {
|
|
238
|
+
if (sharedConfig.context && !sharedConfig.context.noHydrate) {
|
|
223
239
|
const c = sharedConfig.context;
|
|
224
240
|
setHydrateContext(nextHydrateContext());
|
|
225
241
|
const r = Comp(props);
|
|
@@ -290,7 +306,20 @@ function Match(props) {
|
|
|
290
306
|
return props;
|
|
291
307
|
}
|
|
292
308
|
function ErrorBoundary(props) {
|
|
293
|
-
|
|
309
|
+
let error, res;
|
|
310
|
+
const ctx = sharedConfig.context;
|
|
311
|
+
const id = ctx.id + ctx.count;
|
|
312
|
+
onError(err => error = err);
|
|
313
|
+
createMemo(() => res = props.children);
|
|
314
|
+
if (error) {
|
|
315
|
+
ctx.writeResource(id, error, true);
|
|
316
|
+
setHydrateContext({ ...ctx,
|
|
317
|
+
count: 0
|
|
318
|
+
});
|
|
319
|
+
const f = props.fallback;
|
|
320
|
+
return typeof f === "function" && f.length ? f(error, () => {}) : f;
|
|
321
|
+
}
|
|
322
|
+
return res;
|
|
294
323
|
}
|
|
295
324
|
const SuspenseContext = createContext();
|
|
296
325
|
let resourceContext = null;
|
|
@@ -310,6 +339,7 @@ function createResource(fn, fetcher, options = {}) {
|
|
|
310
339
|
let resource = {};
|
|
311
340
|
let value = options.initialValue;
|
|
312
341
|
let p;
|
|
342
|
+
let error;
|
|
313
343
|
if (sharedConfig.context.async) {
|
|
314
344
|
resource = sharedConfig.context.resources[id] || (sharedConfig.context.resources[id] = {});
|
|
315
345
|
if (resource.ref) {
|
|
@@ -318,9 +348,10 @@ function createResource(fn, fetcher, options = {}) {
|
|
|
318
348
|
}
|
|
319
349
|
}
|
|
320
350
|
const read = () => {
|
|
351
|
+
if (error) throw error;
|
|
321
352
|
if (resourceContext && p) resourceContext.push(p);
|
|
322
353
|
const resolved = sharedConfig.context.async && sharedConfig.context.resources[id].data;
|
|
323
|
-
if (
|
|
354
|
+
if (!resolved && read.loading) {
|
|
324
355
|
const ctx = useContext(SuspenseContext);
|
|
325
356
|
if (ctx) {
|
|
326
357
|
ctx.resources.set(id, read);
|
|
@@ -332,7 +363,7 @@ function createResource(fn, fetcher, options = {}) {
|
|
|
332
363
|
read.loading = false;
|
|
333
364
|
function load() {
|
|
334
365
|
const ctx = sharedConfig.context;
|
|
335
|
-
if (!ctx.async
|
|
366
|
+
if (!ctx.async) return read.loading = !!(typeof fn === "function" ? fn() : fn);
|
|
336
367
|
if (ctx.resources && id in ctx.resources && ctx.resources[id].data) {
|
|
337
368
|
value = ctx.resources[id].data;
|
|
338
369
|
return;
|
|
@@ -349,21 +380,18 @@ function createResource(fn, fetcher, options = {}) {
|
|
|
349
380
|
}
|
|
350
381
|
read.loading = true;
|
|
351
382
|
if ("then" in p) {
|
|
352
|
-
if (ctx.writeResource)
|
|
353
|
-
ctx.writeResource(id, p);
|
|
354
|
-
p.then(v => {
|
|
355
|
-
value = v;
|
|
356
|
-
read.loading = false;
|
|
357
|
-
p = null;
|
|
358
|
-
});
|
|
359
|
-
return;
|
|
360
|
-
}
|
|
383
|
+
if (ctx.writeResource) ctx.writeResource(id, p);
|
|
361
384
|
p.then(res => {
|
|
362
385
|
read.loading = false;
|
|
363
386
|
ctx.resources[id].data = res;
|
|
364
387
|
p = null;
|
|
365
388
|
notifySuspense(contexts);
|
|
366
389
|
return res;
|
|
390
|
+
}).catch(err => {
|
|
391
|
+
read.loading = false;
|
|
392
|
+
error = err;
|
|
393
|
+
p = null;
|
|
394
|
+
notifySuspense(contexts);
|
|
367
395
|
});
|
|
368
396
|
return;
|
|
369
397
|
}
|
|
@@ -392,13 +420,13 @@ function lazy(fn) {
|
|
|
392
420
|
ctx.resources.set(id, track);
|
|
393
421
|
contexts.add(ctx);
|
|
394
422
|
}
|
|
395
|
-
p.then(() => {
|
|
423
|
+
if (sharedConfig.context.async) p.then(() => {
|
|
396
424
|
track.loading = false;
|
|
397
425
|
notifySuspense(contexts);
|
|
398
426
|
});
|
|
399
427
|
return "";
|
|
400
428
|
};
|
|
401
|
-
wrap.preload = () =>
|
|
429
|
+
wrap.preload = () => p;
|
|
402
430
|
return wrap;
|
|
403
431
|
}
|
|
404
432
|
function suspenseComplete(c) {
|
|
@@ -425,15 +453,10 @@ function useTransition() {
|
|
|
425
453
|
function SuspenseList(props) {
|
|
426
454
|
return props.children;
|
|
427
455
|
}
|
|
428
|
-
const SUSPENSE_GLOBAL = Symbol("suspense-global");
|
|
429
456
|
function Suspense(props) {
|
|
457
|
+
let done;
|
|
430
458
|
const ctx = sharedConfig.context;
|
|
431
|
-
if (!ctx.async) return createComponent(() => {
|
|
432
|
-
props.children;
|
|
433
|
-
return props.fallback;
|
|
434
|
-
}, {});
|
|
435
459
|
const id = ctx.id + ctx.count;
|
|
436
|
-
const done = ctx.async ? lookup(Owner, SUSPENSE_GLOBAL)(id) : () => {};
|
|
437
460
|
const o = Owner;
|
|
438
461
|
const value = ctx.suspense[id] || (ctx.suspense[id] = {
|
|
439
462
|
resources: new Map(),
|
|
@@ -459,43 +482,30 @@ function Suspense(props) {
|
|
|
459
482
|
}
|
|
460
483
|
const res = runSuspense();
|
|
461
484
|
if (suspenseComplete(value)) {
|
|
462
|
-
|
|
485
|
+
ctx.writeResource(id, true);
|
|
463
486
|
return res;
|
|
464
487
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
if (value) cache[key] = value;
|
|
485
|
-
registry.delete(key);
|
|
486
|
-
if (!registry.size) Promise.resolve().then(() => {
|
|
487
|
-
let source = resolveSSRNode(res());
|
|
488
|
-
let final = "";
|
|
489
|
-
let match;
|
|
490
|
-
while (match = source.match(SUSPENSE_REPLACE)) {
|
|
491
|
-
final += source.substring(0, match.index);
|
|
492
|
-
source = cache[match[1]] + source.substring(match.index + match[0].length);
|
|
493
|
-
}
|
|
494
|
-
resolve(final + source);
|
|
495
|
-
});
|
|
496
|
-
};
|
|
497
|
-
}
|
|
488
|
+
onError(err => {
|
|
489
|
+
if (!done || !done(undefined, err)) throw err;
|
|
490
|
+
});
|
|
491
|
+
done = ctx.async ? ctx.registerFragment(id) : undefined;
|
|
492
|
+
if (ctx.streaming) {
|
|
493
|
+
setHydrateContext(undefined);
|
|
494
|
+
const res = {
|
|
495
|
+
t: `<span id="pl${id}">${resolveSSRNode(props.fallback)}</span>`
|
|
496
|
+
};
|
|
497
|
+
setHydrateContext(ctx);
|
|
498
|
+
return res;
|
|
499
|
+
} else if (ctx.async) {
|
|
500
|
+
return {
|
|
501
|
+
t: `<![${id}]>`
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
setHydrateContext({ ...ctx,
|
|
505
|
+
count: 0,
|
|
506
|
+
id: ctx.id + "0.f"
|
|
498
507
|
});
|
|
508
|
+
return props.fallback;
|
|
499
509
|
}
|
|
500
510
|
|
|
501
511
|
exports.$PROXY = $PROXY;
|
|
@@ -508,7 +518,6 @@ exports.Show = Show;
|
|
|
508
518
|
exports.Suspense = Suspense;
|
|
509
519
|
exports.SuspenseList = SuspenseList;
|
|
510
520
|
exports.Switch = Switch;
|
|
511
|
-
exports.awaitSuspense = awaitSuspense;
|
|
512
521
|
exports.batch = batch;
|
|
513
522
|
exports.children = children;
|
|
514
523
|
exports.createComponent = createComponent;
|
|
@@ -523,6 +532,7 @@ exports.createRoot = createRoot;
|
|
|
523
532
|
exports.createSelector = createSelector;
|
|
524
533
|
exports.createSignal = createSignal;
|
|
525
534
|
exports.createUniqueId = createUniqueId;
|
|
535
|
+
exports.enableExternalSource = enableExternalSource;
|
|
526
536
|
exports.enableScheduling = enableScheduling;
|
|
527
537
|
exports.equalFn = equalFn;
|
|
528
538
|
exports.from = from;
|