@torpor/view 1.2.0 → 1.2.2
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/compile.cjs +14 -1
- package/dist/compile.mjs +14 -1
- package/dist/compile.mjs.map +1 -1
- package/dist/index.cjs +66 -15
- package/dist/index.d.cts +15 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +15 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +66 -15
- package/dist/index.mjs.map +1 -1
- package/dist/ssr.cjs +97 -49
- package/dist/ssr.d.cts +29 -14
- package/dist/ssr.d.cts.map +1 -1
- package/dist/ssr.d.mts +29 -14
- package/dist/ssr.d.mts.map +1 -1
- package/dist/ssr.mjs +97 -49
- package/dist/ssr.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -1504,6 +1504,24 @@ function formatKey(key) {
|
|
|
1504
1504
|
}
|
|
1505
1505
|
}
|
|
1506
1506
|
//#endregion
|
|
1507
|
+
//#region src/render/AwaitSuspend.ts
|
|
1508
|
+
/**
|
|
1509
|
+
* Thrown when content rendered speculatively inside an `@await` boundary
|
|
1510
|
+
* dereferences (or calls) a first-load pending `$async` value.
|
|
1511
|
+
*
|
|
1512
|
+
* `suspendRead` normally returns `staleValue` so refresh suspends can keep
|
|
1513
|
+
* stale content mounted. On a first load there is no stale value, so returning
|
|
1514
|
+
* `undefined` would let user code throw a `TypeError` before the boundary can
|
|
1515
|
+
* switch to its `with` branch. Throwing this sentinel aborts the speculative
|
|
1516
|
+
* render instead; `runAwait` catches it and renders the fallback.
|
|
1517
|
+
*/
|
|
1518
|
+
var AwaitSuspend = class extends Error {
|
|
1519
|
+
constructor() {
|
|
1520
|
+
super("Suspended async value");
|
|
1521
|
+
this.name = "AwaitSuspend";
|
|
1522
|
+
}
|
|
1523
|
+
};
|
|
1524
|
+
//#endregion
|
|
1507
1525
|
//#region src/watch/deepWrap.ts
|
|
1508
1526
|
/**
|
|
1509
1527
|
* Wraps a value with `$watch` if it is a plain object (or Date/Map/Set) that
|
|
@@ -1623,10 +1641,13 @@ function trackProxySignal(data, key) {
|
|
|
1623
1641
|
* (the computed has resolved before) returns the previously resolved value
|
|
1624
1642
|
* held in `staleValue`, so readers keep displaying the old content instead of
|
|
1625
1643
|
* a placeholder — an `@await` boundary thus keeps its content mounted
|
|
1626
|
-
* rather than flashing the `with` branch. On a first load (
|
|
1627
|
-
*
|
|
1628
|
-
* `
|
|
1629
|
-
*
|
|
1644
|
+
* rather than flashing the `with` branch. On a first load (or a retry after a
|
|
1645
|
+
* rejection, both of which have no stale value), inside an `@await` boundary,
|
|
1646
|
+
* throws `AwaitSuspend` to abort the speculative content render so the
|
|
1647
|
+
* boundary can show its `with` branch — a direct `undefined` return would
|
|
1648
|
+
* make user code that dereferences the value throw a `TypeError` first. In
|
|
1649
|
+
* peek mode (used by `$pending`) always returns `undefined` — the value isn't
|
|
1650
|
+
* needed, only the subscription.
|
|
1630
1651
|
*/
|
|
1631
1652
|
function suspendRead(signal) {
|
|
1632
1653
|
trackSignal(signal);
|
|
@@ -1651,6 +1672,7 @@ function suspendRead(signal) {
|
|
|
1651
1672
|
trackSignal(signal);
|
|
1652
1673
|
context.activeTarget = oldActive;
|
|
1653
1674
|
}
|
|
1675
|
+
if (!signal.hasResolved || signal.lastErrored) throw new AwaitSuspend();
|
|
1654
1676
|
}
|
|
1655
1677
|
return signal.staleValue;
|
|
1656
1678
|
}
|
|
@@ -2338,7 +2360,11 @@ const SERVER_VALUES_PREFIX = "t-await:";
|
|
|
2338
2360
|
/**
|
|
2339
2361
|
* Renders an `@await` boundary. On the first run, content is rendered
|
|
2340
2362
|
* speculatively; if any read inside suspends (`didSuspend`), the boundary
|
|
2341
|
-
* discards the partial render and shows the `with` branch instead.
|
|
2363
|
+
* discards the partial render and shows the `with` branch instead. If the
|
|
2364
|
+
* content dereferences a first-load pending value before the boundary can
|
|
2365
|
+
* check, `suspendRead` throws `AwaitSuspend`; it is caught here so the partial
|
|
2366
|
+
* render is cleared and the fallback is shown instead of surfacing a
|
|
2367
|
+
* `TypeError`.
|
|
2342
2368
|
*
|
|
2343
2369
|
* Hydration of a server-resolved boundary (ASYNC.md → "Server rendering"): when the server
|
|
2344
2370
|
* shipped resolved content, its values ride in a payload comment after the
|
|
@@ -2401,8 +2427,11 @@ function runAwait(region, anchor, renderContent, renderWith, name) {
|
|
|
2401
2427
|
runControlBranch(region, index, targetIndex);
|
|
2402
2428
|
context.previousRegion = region;
|
|
2403
2429
|
const oldR = pushRegion(newRegion(targetIndex === 0 ? "await_content" : "await_with"), true);
|
|
2404
|
-
|
|
2405
|
-
|
|
2430
|
+
try {
|
|
2431
|
+
fn(anchor);
|
|
2432
|
+
} finally {
|
|
2433
|
+
popRegion(oldR);
|
|
2434
|
+
}
|
|
2406
2435
|
index = targetIndex;
|
|
2407
2436
|
};
|
|
2408
2437
|
const attemptContent = () => {
|
|
@@ -2416,12 +2445,23 @@ function runAwait(region, anchor, renderContent, renderWith, name) {
|
|
|
2416
2445
|
index: 0
|
|
2417
2446
|
};
|
|
2418
2447
|
else if (savedHydration !== null) context.hydrationNode = null;
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2448
|
+
let aborted = false;
|
|
2449
|
+
try {
|
|
2450
|
+
renderBranch(0, renderContent);
|
|
2451
|
+
} catch (error) {
|
|
2452
|
+
if (!(error instanceof AwaitSuspend)) throw error;
|
|
2453
|
+
aborted = true;
|
|
2454
|
+
index = 0;
|
|
2455
|
+
} finally {
|
|
2456
|
+
context.hydrationNode = savedHydration;
|
|
2457
|
+
context.serverValues = savedServerValues;
|
|
2458
|
+
context.awaitBoundary = oldBoundary;
|
|
2459
|
+
}
|
|
2423
2460
|
if (boundary.suspended && renderWith !== null) renderBranch(1, renderWith);
|
|
2424
|
-
else if (
|
|
2461
|
+
else if (boundary.suspended && aborted) {
|
|
2462
|
+
runControlBranch(region, index, 1);
|
|
2463
|
+
index = 1;
|
|
2464
|
+
} else if (!boundary.suspended) hasContent = true;
|
|
2425
2465
|
};
|
|
2426
2466
|
if (theEffect === null) attemptContent();
|
|
2427
2467
|
else {
|
|
@@ -2631,7 +2671,15 @@ function $batch(fn) {
|
|
|
2631
2671
|
* so there's no re-fetch wait and no fallback flash.
|
|
2632
2672
|
*
|
|
2633
2673
|
* @param fn A thunk returning the Promise to await. Signal reads inside `fn`
|
|
2634
|
-
* are tracked, so the fetch re-runs when dependencies change.
|
|
2674
|
+
* are tracked, so the fetch re-runs when dependencies change. With
|
|
2675
|
+
* `source: "server"`, the thunk receives the server-resolved value (if any)
|
|
2676
|
+
* as its argument on the client's first (hydration) run, so it can return it
|
|
2677
|
+
* unchanged to skip expensive work the server already did. Later runs (a
|
|
2678
|
+
* dependency change, a `$refresh`, or a client-side navigation with no
|
|
2679
|
+
* server value) receive `undefined`. Reads still have to happen before any
|
|
2680
|
+
* early return for their changes to be tracked. Annotate the thunk's return
|
|
2681
|
+
* type (e.g. `async (server): Promise<string> => …`) when the result type
|
|
2682
|
+
* isn't inferable from the thunk's body alone.
|
|
2635
2683
|
* @param _options Accepted so the same getter source compiles into client and
|
|
2636
2684
|
* server builds (`source: "server"` fetches during SSR); ignored here.
|
|
2637
2685
|
*/
|
|
@@ -2655,8 +2703,12 @@ function $async(fn, _options) {
|
|
|
2655
2703
|
staleValue: void 0,
|
|
2656
2704
|
rollback: null
|
|
2657
2705
|
};
|
|
2706
|
+
const serverValues = context.serverValues;
|
|
2707
|
+
const serverValue = serverValues !== null && serverValues.index < serverValues.values.length ? serverValues.values[serverValues.index] : void 0;
|
|
2708
|
+
let firstRun = true;
|
|
2658
2709
|
computed.run = () => {
|
|
2659
|
-
const value = fn();
|
|
2710
|
+
const value = fn(firstRun ? serverValue : void 0);
|
|
2711
|
+
firstRun = false;
|
|
2660
2712
|
if (value !== null && value !== void 0 && typeof value.then === "function") {
|
|
2661
2713
|
const gen = ++computed.generation;
|
|
2662
2714
|
computed.didSuspend = true;
|
|
@@ -2688,7 +2740,6 @@ function $async(fn, _options) {
|
|
|
2688
2740
|
};
|
|
2689
2741
|
context.registerComputed(computed);
|
|
2690
2742
|
runComputed(computed);
|
|
2691
|
-
const serverValues = context.serverValues;
|
|
2692
2743
|
if (serverValues !== null && serverValues.index < serverValues.values.length) {
|
|
2693
2744
|
computed.generation++;
|
|
2694
2745
|
computed.didSuspend = false;
|
package/dist/index.d.cts
CHANGED
|
@@ -343,7 +343,11 @@ declare function runList(region: Region, parent: ParentNode, anchor: Node | null
|
|
|
343
343
|
/**
|
|
344
344
|
* Renders an `@await` boundary. On the first run, content is rendered
|
|
345
345
|
* speculatively; if any read inside suspends (`didSuspend`), the boundary
|
|
346
|
-
* discards the partial render and shows the `with` branch instead.
|
|
346
|
+
* discards the partial render and shows the `with` branch instead. If the
|
|
347
|
+
* content dereferences a first-load pending value before the boundary can
|
|
348
|
+
* check, `suspendRead` throws `AwaitSuspend`; it is caught here so the partial
|
|
349
|
+
* render is cleared and the fallback is shown instead of surfacing a
|
|
350
|
+
* `TypeError`.
|
|
347
351
|
*
|
|
348
352
|
* Hydration of a server-resolved boundary (ASYNC.md → "Server rendering"): when the server
|
|
349
353
|
* shipped resolved content, its values ride in a payload comment after the
|
|
@@ -494,11 +498,19 @@ declare function $batch<T>(fn: () => T): T;
|
|
|
494
498
|
* so there's no re-fetch wait and no fallback flash.
|
|
495
499
|
*
|
|
496
500
|
* @param fn A thunk returning the Promise to await. Signal reads inside `fn`
|
|
497
|
-
* are tracked, so the fetch re-runs when dependencies change.
|
|
501
|
+
* are tracked, so the fetch re-runs when dependencies change. With
|
|
502
|
+
* `source: "server"`, the thunk receives the server-resolved value (if any)
|
|
503
|
+
* as its argument on the client's first (hydration) run, so it can return it
|
|
504
|
+
* unchanged to skip expensive work the server already did. Later runs (a
|
|
505
|
+
* dependency change, a `$refresh`, or a client-side navigation with no
|
|
506
|
+
* server value) receive `undefined`. Reads still have to happen before any
|
|
507
|
+
* early return for their changes to be tracked. Annotate the thunk's return
|
|
508
|
+
* type (e.g. `async (server): Promise<string> => …`) when the result type
|
|
509
|
+
* isn't inferable from the thunk's body alone.
|
|
498
510
|
* @param _options Accepted so the same getter source compiles into client and
|
|
499
511
|
* server builds (`source: "server"` fetches during SSR); ignored here.
|
|
500
512
|
*/
|
|
501
|
-
declare function $async<T>(fn: () => Promise<T>, _options?: AsyncOptions): T;
|
|
513
|
+
declare function $async<T>(fn: (serverValue?: T) => Promise<T>, _options?: AsyncOptions): T;
|
|
502
514
|
//#endregion
|
|
503
515
|
//#region src/watch/$bind.d.ts
|
|
504
516
|
/**
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types/Animation.ts","../src/render/addAnimation.ts","../src/render/addEvent.ts","../src/render/addElement.ts","../src/render/addFragment.ts","../src/render/applyProps.ts","../src/render/clearLayoutSlot.ts","../src/render/fillLayoutSlot.ts","../src/render/formatText.ts","../src/render/firstInsideNode.ts","../src/render/getFragment.ts","../src/render/getElementFragment.ts","../src/render/hydrate.ts","../src/render/mount.ts","../src/render/unmount.ts","../src/types/ListItemSpec.ts","../src/types/ListItem.ts","../src/render/newListItem.ts","../src/render/newRegion.ts","../src/render/nodeAnchor.ts","../src/render/nodeChild.ts","../src/render/nodeNext.ts","../src/render/nodeRootElement.ts","../src/render/nodeRoot.ts","../src/render/nodeSkip.ts","../src/render/popRegion.ts","../src/render/pushRegion.ts","../src/render/rerunRegionEffects.ts","../src/render/restoreHydration.ts","../src/render/runControl.ts","../src/render/runControlBranch.ts","../src/render/runList.ts","../src/render/runAwait.ts","../src/render/runTry.ts","../src/render/saveHydration.ts","../src/render/headElement.ts","../src/render/setAttribute.ts","../src/render/setDynamicElement.ts","../src/types/Bindable.ts","../src/watch/$batch.ts","../src/watch/$async.ts","../src/watch/$bind.ts","../src/watch/$cache.ts","../src/watch/$onmount.ts","../src/watch/$peek.ts","../src/watch/$pending.ts","../src/watch/$refresh.ts","../src/watch/$run.ts","../src/watch/$stream.ts","../src/watch/$unwrap.ts","../src/types/WatchOptions.ts","../src/watch/$watch.ts"],"mappings":";;;;;UAAyB;EACxB,WAAW,aAAa;EACxB,mBAAmB;;;;iBCCI,aAAa,IAAI,aAAa,QAAQ,WAAW,OAAO;;;iBCDxD,SACvB,IAAI,SACJ,cACA,YAAA,MAAkB,SAAS;;;;;;;;;;;;;;;;;;;;;;iBCiBJ,WAAW,MAAM,SAAS,QAAQ,YAAY,QAAQ;;;iBCnBtD,YACvB,UAAU,kBACV,QAAQ,YACR,QAAQ,aACR,UAAU,WACV,YAAY;;;iBCLW,WACvB,IAAI,SACJ,OAAO,iCACP;;;;;;;;;;iBCKuB,gBAAgB,QAAQ;;;;;;;;;;;;;;;;;;iBCYxB,eACvB,WAAW,WACX,MAAM,YACN,QAAQ,YACR,QAAQ,aACR,SAAS,OAAO,mBAChB,WAAW,OAAO,oBAChB;;;iBC5BqB,WAAW;;;;;;;;iBCiBX,gBAAgB,QAAQ,YAAY;;;iBCnBpC,YACvB,UAAU,UACV,OAAO,oBACP,eACA,cACA,eACE;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCkBqB,mBACvB,UAAU,UACV,OAAO,WACP,eACA,cACA,eACE;;;;;;;;;iBCfqB,QACvB,QAAQ,YACR,WAAW,WACX,QAAQ,qBACR,QAAQ,eAAe;;;;;;;;;;iBCJA,MACvB,QAAQ,YACR,WAAW,WACX,QAAQ,qBACR,QAAQ,eAAe;;;;;;;;;;;;;;;iBCHA,QAAQ,QAAQ;;;;;;;;;;;;;;;;;;;UCAf;EACxB;EACA;;;;UCfwB,iBAAiB,QAAQ;;;iBCD1B,YACvB,MAAM,OAAO,mBACb,WACA,gBACE;;;iBCJqB,UAAU,gBAAgB;;;;;;;;;;;;;;;;;iBCkB1B,WAAW,MAAM,YAAY;;;;;;;;;;iBCX7B,UAAU,QAAQ,OAAO;;;;;;;;;;;iBCGzB,SAAS,MAAM,WAAW,iBAAe;;;;;;;;;;;;;;;;;iBCKzC,gBAAgB,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;iBCShC,SAAS,QAAQ,MAAM,iBAAe;;;;;;;;;;;iBCftC,SAAS,MAAM,WAAW,gBAAgB;;;iBCP1C,UAAU,WAAW;;;iBCArB,WAAW,QAAQ,QAAQ,qBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;iBCyB9C,mBAAmB,QAAQ,QAAQ;;;;;;;;;;;;;;;;;iBCbnC,iBAAiB,MAAM;;;;;;;iBCLvB,WACvB,QAAQ,QACR,QAAQ,aACR,SAAS,QAAQ,sBACjB;;;iBCZuB,iBAAiB,QAAQ,QAAQ,kBAAkB;;;;;;;;;;;;;;;iBCoBnD,QACvB,QAAQ,QACR,QAAQ,YACR,QAAQ,aACR,kBAAkB,gBAClB,SAAS,MAAM,UAAU,QAAQ,sBACjC,SAAS,SAAS,UAAU,SAAS,uBACrC
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types/Animation.ts","../src/render/addAnimation.ts","../src/render/addEvent.ts","../src/render/addElement.ts","../src/render/addFragment.ts","../src/render/applyProps.ts","../src/render/clearLayoutSlot.ts","../src/render/fillLayoutSlot.ts","../src/render/formatText.ts","../src/render/firstInsideNode.ts","../src/render/getFragment.ts","../src/render/getElementFragment.ts","../src/render/hydrate.ts","../src/render/mount.ts","../src/render/unmount.ts","../src/types/ListItemSpec.ts","../src/types/ListItem.ts","../src/render/newListItem.ts","../src/render/newRegion.ts","../src/render/nodeAnchor.ts","../src/render/nodeChild.ts","../src/render/nodeNext.ts","../src/render/nodeRootElement.ts","../src/render/nodeRoot.ts","../src/render/nodeSkip.ts","../src/render/popRegion.ts","../src/render/pushRegion.ts","../src/render/rerunRegionEffects.ts","../src/render/restoreHydration.ts","../src/render/runControl.ts","../src/render/runControlBranch.ts","../src/render/runList.ts","../src/render/runAwait.ts","../src/render/runTry.ts","../src/render/saveHydration.ts","../src/render/headElement.ts","../src/render/setAttribute.ts","../src/render/setDynamicElement.ts","../src/types/Bindable.ts","../src/watch/$batch.ts","../src/watch/$async.ts","../src/watch/$bind.ts","../src/watch/$cache.ts","../src/watch/$onmount.ts","../src/watch/$peek.ts","../src/watch/$pending.ts","../src/watch/$refresh.ts","../src/watch/$run.ts","../src/watch/$stream.ts","../src/watch/$unwrap.ts","../src/types/WatchOptions.ts","../src/watch/$watch.ts"],"mappings":";;;;;UAAyB;EACxB,WAAW,aAAa;EACxB,mBAAmB;;;;iBCCI,aAAa,IAAI,aAAa,QAAQ,WAAW,OAAO;;;iBCDxD,SACvB,IAAI,SACJ,cACA,YAAA,MAAkB,SAAS;;;;;;;;;;;;;;;;;;;;;;iBCiBJ,WAAW,MAAM,SAAS,QAAQ,YAAY,QAAQ;;;iBCnBtD,YACvB,UAAU,kBACV,QAAQ,YACR,QAAQ,aACR,UAAU,WACV,YAAY;;;iBCLW,WACvB,IAAI,SACJ,OAAO,iCACP;;;;;;;;;;iBCKuB,gBAAgB,QAAQ;;;;;;;;;;;;;;;;;;iBCYxB,eACvB,WAAW,WACX,MAAM,YACN,QAAQ,YACR,QAAQ,aACR,SAAS,OAAO,mBAChB,WAAW,OAAO,oBAChB;;;iBC5BqB,WAAW;;;;;;;;iBCiBX,gBAAgB,QAAQ,YAAY;;;iBCnBpC,YACvB,UAAU,UACV,OAAO,oBACP,eACA,cACA,eACE;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCkBqB,mBACvB,UAAU,UACV,OAAO,WACP,eACA,cACA,eACE;;;;;;;;;iBCfqB,QACvB,QAAQ,YACR,WAAW,WACX,QAAQ,qBACR,QAAQ,eAAe;;;;;;;;;;iBCJA,MACvB,QAAQ,YACR,WAAW,WACX,QAAQ,qBACR,QAAQ,eAAe;;;;;;;;;;;;;;;iBCHA,QAAQ,QAAQ;;;;;;;;;;;;;;;;;;;UCAf;EACxB;EACA;;;;UCfwB,iBAAiB,QAAQ;;;iBCD1B,YACvB,MAAM,OAAO,mB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U,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBC8BxB,OAAO,GAAG,KAAK,cAAc,MAAM,QAAQ,IAAI,WAAW,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCLzE,MACvB,OAAO,OAAO,mBACd,OAAO,OAAO,kCACX;;;;;;;;iBC5BoB,OAAO,GAAG,UAAU,IAAI;;;;;;;;;;;;;;;;;;;;;;;;iBCcxB,SAAS,UAAU;;;;;;;;;;;iBCdnB,MAAM,GAAG,UAAU,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;iBCcvB,SAAS;;;;;;UCZhB;;;;;;;;EAQhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4CuB,SAAS,eAAe,UAAU;;;;;;;;;;iBChDlC,KACvB,UAAU,gBACV,eACA,UAAU,KAAK,0CACb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCqBqB,QAAQ,GAC/B,QAAQ,aAAa,IACrB,UAAU,OAAO,YACjB;EAAY;;;;;;;;;iBCrCW,QAAQ,UAAU,OAAO,mBAAmB,QAAQ,IAAI;;;;;;UCJvD;;;;EAIxB;;;;;;;;;;;;;iBCoBuB,OAAO,kBAAkB,QAAQ,GAAG,UAAU,eAAe"}
|
package/dist/index.d.mts
CHANGED
|
@@ -343,7 +343,11 @@ declare function runList(region: Region, parent: ParentNode, anchor: Node | null
|
|
|
343
343
|
/**
|
|
344
344
|
* Renders an `@await` boundary. On the first run, content is rendered
|
|
345
345
|
* speculatively; if any read inside suspends (`didSuspend`), the boundary
|
|
346
|
-
* discards the partial render and shows the `with` branch instead.
|
|
346
|
+
* discards the partial render and shows the `with` branch instead. If the
|
|
347
|
+
* content dereferences a first-load pending value before the boundary can
|
|
348
|
+
* check, `suspendRead` throws `AwaitSuspend`; it is caught here so the partial
|
|
349
|
+
* render is cleared and the fallback is shown instead of surfacing a
|
|
350
|
+
* `TypeError`.
|
|
347
351
|
*
|
|
348
352
|
* Hydration of a server-resolved boundary (ASYNC.md → "Server rendering"): when the server
|
|
349
353
|
* shipped resolved content, its values ride in a payload comment after the
|
|
@@ -494,11 +498,19 @@ declare function $batch<T>(fn: () => T): T;
|
|
|
494
498
|
* so there's no re-fetch wait and no fallback flash.
|
|
495
499
|
*
|
|
496
500
|
* @param fn A thunk returning the Promise to await. Signal reads inside `fn`
|
|
497
|
-
* are tracked, so the fetch re-runs when dependencies change.
|
|
501
|
+
* are tracked, so the fetch re-runs when dependencies change. With
|
|
502
|
+
* `source: "server"`, the thunk receives the server-resolved value (if any)
|
|
503
|
+
* as its argument on the client's first (hydration) run, so it can return it
|
|
504
|
+
* unchanged to skip expensive work the server already did. Later runs (a
|
|
505
|
+
* dependency change, a `$refresh`, or a client-side navigation with no
|
|
506
|
+
* server value) receive `undefined`. Reads still have to happen before any
|
|
507
|
+
* early return for their changes to be tracked. Annotate the thunk's return
|
|
508
|
+
* type (e.g. `async (server): Promise<string> => …`) when the result type
|
|
509
|
+
* isn't inferable from the thunk's body alone.
|
|
498
510
|
* @param _options Accepted so the same getter source compiles into client and
|
|
499
511
|
* server builds (`source: "server"` fetches during SSR); ignored here.
|
|
500
512
|
*/
|
|
501
|
-
declare function $async<T>(fn: () => Promise<T>, _options?: AsyncOptions): T;
|
|
513
|
+
declare function $async<T>(fn: (serverValue?: T) => Promise<T>, _options?: AsyncOptions): T;
|
|
502
514
|
//#endregion
|
|
503
515
|
//#region src/watch/$bind.d.ts
|
|
504
516
|
/**
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/Animation.ts","../src/render/addAnimation.ts","../src/render/addEvent.ts","../src/render/addElement.ts","../src/render/addFragment.ts","../src/render/applyProps.ts","../src/render/clearLayoutSlot.ts","../src/render/fillLayoutSlot.ts","../src/render/formatText.ts","../src/render/firstInsideNode.ts","../src/render/getFragment.ts","../src/render/getElementFragment.ts","../src/render/hydrate.ts","../src/render/mount.ts","../src/render/unmount.ts","../src/types/ListItemSpec.ts","../src/types/ListItem.ts","../src/render/newListItem.ts","../src/render/newRegion.ts","../src/render/nodeAnchor.ts","../src/render/nodeChild.ts","../src/render/nodeNext.ts","../src/render/nodeRootElement.ts","../src/render/nodeRoot.ts","../src/render/nodeSkip.ts","../src/render/popRegion.ts","../src/render/pushRegion.ts","../src/render/rerunRegionEffects.ts","../src/render/restoreHydration.ts","../src/render/runControl.ts","../src/render/runControlBranch.ts","../src/render/runList.ts","../src/render/runAwait.ts","../src/render/runTry.ts","../src/render/saveHydration.ts","../src/render/headElement.ts","../src/render/setAttribute.ts","../src/render/setDynamicElement.ts","../src/types/Bindable.ts","../src/watch/$batch.ts","../src/watch/$async.ts","../src/watch/$bind.ts","../src/watch/$cache.ts","../src/watch/$onmount.ts","../src/watch/$peek.ts","../src/watch/$pending.ts","../src/watch/$refresh.ts","../src/watch/$run.ts","../src/watch/$stream.ts","../src/watch/$unwrap.ts","../src/types/WatchOptions.ts","../src/watch/$watch.ts"],"mappings":";;;;;UAAyB;EACxB,WAAW,aAAa;EACxB,mBAAmB;;;;iBCCI,aAAa,IAAI,aAAa,QAAQ,WAAW,OAAO;;;iBCDxD,SACvB,IAAI,SACJ,cACA,YAAA,MAAkB,SAAS;;;;;;;;;;;;;;;;;;;;;;iBCiBJ,WAAW,MAAM,SAAS,QAAQ,YAAY,QAAQ;;;iBCnBtD,YACvB,UAAU,kBACV,QAAQ,YACR,QAAQ,aACR,UAAU,WACV,YAAY;;;iBCLW,WACvB,IAAI,SACJ,OAAO,iCACP;;;;;;;;;;iBCKuB,gBAAgB,QAAQ;;;;;;;;;;;;;;;;;;iBCYxB,eACvB,WAAW,WACX,MAAM,YACN,QAAQ,YACR,QAAQ,aACR,SAAS,OAAO,mBAChB,WAAW,OAAO,oBAChB;;;iBC5BqB,WAAW;;;;;;;;iBCiBX,gBAAgB,QAAQ,YAAY;;;iBCnBpC,YACvB,UAAU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ts","../src/render/addElement.ts","../src/render/addFragment.ts","../src/render/applyProps.ts","../src/render/clearLayoutSlot.ts","../src/render/fillLayoutSlot.ts","../src/render/formatText.ts","../src/render/firstInsideNode.ts","../src/render/getFragment.ts","../src/render/getElementFragment.ts","../src/render/hydrate.ts","../src/render/mount.ts","../src/render/unmount.ts","../src/types/ListItemSpec.ts","../src/types/ListItem.ts","../src/render/newListItem.ts","../src/render/newRegion.ts","../src/render/nodeAnchor.ts","../src/render/nodeChild.ts","../src/render/nodeNext.ts","../src/render/nodeRootElement.ts","../src/render/nodeRoot.ts","../src/render/nodeSkip.ts","../src/render/popRegion.ts","../src/render/pushRegion.ts","../src/render/rerunRegionEffects.ts","../src/render/restoreHydration.ts","../src/render/runControl.ts","../src/render/runControlBranch.ts","../src/render/runList.ts","../src/render/runAwait.ts","../src/render/runTry.ts","../src/render/saveHydration.ts","../src/render/headElement.ts","../src/render/setAttribute.ts","../src/render/setDynamicElement.ts","../src/types/Bindable.ts","../src/watch/$batch.ts","../src/watch/$async.ts","../src/watch/$bind.ts","../src/watch/$cache.ts","../src/watch/$onmount.ts","../src/watch/$peek.ts","../src/watch/$pending.ts","../src/watch/$refresh.ts","../src/watch/$run.ts","../src/watch/$stream.ts","../src/watch/$unwrap.ts","../src/types/WatchOptions.ts","../src/watch/$watch.ts"],"mappings":";;;;;UAAyB;EACxB,WAAW,aAAa;EACxB,mBAAmB;;;;iBCCI,aAAa,IAAI,aAAa,QAAQ,WAAW,OAAO;;;iBCDxD,SACvB,IAAI,SACJ,cACA,YAAA,MAAkB,SAAS;;;;;;;;;;;;;;;;;;;;;;iBCiBJ,WAAW,MAAM,SAAS,QAAQ,YAAY,QAAQ;;;iBCnBtD,YACvB,UAAU,kBACV,QAAQ,YACR,QAAQ,aACR,UAAU,WACV,YAAY;;;iBCLW,WACvB,IAAI,SACJ,OAAO,iCACP;;;;;;;;;;iBCKuB,gBAAgB,QAAQ;;;;;;;;;;;;;;;;;;iBCYxB,eACvB,WAAW,W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CrCW,QAAQ,UAAU,OAAO,mBAAmB,QAAQ,IAAI;;;;;;UCJvD;;;;EAIxB;;;;;;;;;;;;;iBCoBuB,OAAO,kBAAkB,QAAQ,GAAG,UAAU,eAAe"}
|
package/dist/index.mjs
CHANGED
|
@@ -1503,6 +1503,24 @@ function formatKey(key) {
|
|
|
1503
1503
|
}
|
|
1504
1504
|
}
|
|
1505
1505
|
//#endregion
|
|
1506
|
+
//#region src/render/AwaitSuspend.ts
|
|
1507
|
+
/**
|
|
1508
|
+
* Thrown when content rendered speculatively inside an `@await` boundary
|
|
1509
|
+
* dereferences (or calls) a first-load pending `$async` value.
|
|
1510
|
+
*
|
|
1511
|
+
* `suspendRead` normally returns `staleValue` so refresh suspends can keep
|
|
1512
|
+
* stale content mounted. On a first load there is no stale value, so returning
|
|
1513
|
+
* `undefined` would let user code throw a `TypeError` before the boundary can
|
|
1514
|
+
* switch to its `with` branch. Throwing this sentinel aborts the speculative
|
|
1515
|
+
* render instead; `runAwait` catches it and renders the fallback.
|
|
1516
|
+
*/
|
|
1517
|
+
var AwaitSuspend = class extends Error {
|
|
1518
|
+
constructor() {
|
|
1519
|
+
super("Suspended async value");
|
|
1520
|
+
this.name = "AwaitSuspend";
|
|
1521
|
+
}
|
|
1522
|
+
};
|
|
1523
|
+
//#endregion
|
|
1506
1524
|
//#region src/watch/deepWrap.ts
|
|
1507
1525
|
/**
|
|
1508
1526
|
* Wraps a value with `$watch` if it is a plain object (or Date/Map/Set) that
|
|
@@ -1622,10 +1640,13 @@ function trackProxySignal(data, key) {
|
|
|
1622
1640
|
* (the computed has resolved before) returns the previously resolved value
|
|
1623
1641
|
* held in `staleValue`, so readers keep displaying the old content instead of
|
|
1624
1642
|
* a placeholder — an `@await` boundary thus keeps its content mounted
|
|
1625
|
-
* rather than flashing the `with` branch. On a first load (
|
|
1626
|
-
*
|
|
1627
|
-
* `
|
|
1628
|
-
*
|
|
1643
|
+
* rather than flashing the `with` branch. On a first load (or a retry after a
|
|
1644
|
+
* rejection, both of which have no stale value), inside an `@await` boundary,
|
|
1645
|
+
* throws `AwaitSuspend` to abort the speculative content render so the
|
|
1646
|
+
* boundary can show its `with` branch — a direct `undefined` return would
|
|
1647
|
+
* make user code that dereferences the value throw a `TypeError` first. In
|
|
1648
|
+
* peek mode (used by `$pending`) always returns `undefined` — the value isn't
|
|
1649
|
+
* needed, only the subscription.
|
|
1629
1650
|
*/
|
|
1630
1651
|
function suspendRead(signal) {
|
|
1631
1652
|
trackSignal(signal);
|
|
@@ -1650,6 +1671,7 @@ function suspendRead(signal) {
|
|
|
1650
1671
|
trackSignal(signal);
|
|
1651
1672
|
context.activeTarget = oldActive;
|
|
1652
1673
|
}
|
|
1674
|
+
if (!signal.hasResolved || signal.lastErrored) throw new AwaitSuspend();
|
|
1653
1675
|
}
|
|
1654
1676
|
return signal.staleValue;
|
|
1655
1677
|
}
|
|
@@ -2337,7 +2359,11 @@ const SERVER_VALUES_PREFIX = "t-await:";
|
|
|
2337
2359
|
/**
|
|
2338
2360
|
* Renders an `@await` boundary. On the first run, content is rendered
|
|
2339
2361
|
* speculatively; if any read inside suspends (`didSuspend`), the boundary
|
|
2340
|
-
* discards the partial render and shows the `with` branch instead.
|
|
2362
|
+
* discards the partial render and shows the `with` branch instead. If the
|
|
2363
|
+
* content dereferences a first-load pending value before the boundary can
|
|
2364
|
+
* check, `suspendRead` throws `AwaitSuspend`; it is caught here so the partial
|
|
2365
|
+
* render is cleared and the fallback is shown instead of surfacing a
|
|
2366
|
+
* `TypeError`.
|
|
2341
2367
|
*
|
|
2342
2368
|
* Hydration of a server-resolved boundary (ASYNC.md → "Server rendering"): when the server
|
|
2343
2369
|
* shipped resolved content, its values ride in a payload comment after the
|
|
@@ -2400,8 +2426,11 @@ function runAwait(region, anchor, renderContent, renderWith, name) {
|
|
|
2400
2426
|
runControlBranch(region, index, targetIndex);
|
|
2401
2427
|
context.previousRegion = region;
|
|
2402
2428
|
const oldR = pushRegion(newRegion(targetIndex === 0 ? "await_content" : "await_with"), true);
|
|
2403
|
-
|
|
2404
|
-
|
|
2429
|
+
try {
|
|
2430
|
+
fn(anchor);
|
|
2431
|
+
} finally {
|
|
2432
|
+
popRegion(oldR);
|
|
2433
|
+
}
|
|
2405
2434
|
index = targetIndex;
|
|
2406
2435
|
};
|
|
2407
2436
|
const attemptContent = () => {
|
|
@@ -2415,12 +2444,23 @@ function runAwait(region, anchor, renderContent, renderWith, name) {
|
|
|
2415
2444
|
index: 0
|
|
2416
2445
|
};
|
|
2417
2446
|
else if (savedHydration !== null) context.hydrationNode = null;
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2447
|
+
let aborted = false;
|
|
2448
|
+
try {
|
|
2449
|
+
renderBranch(0, renderContent);
|
|
2450
|
+
} catch (error) {
|
|
2451
|
+
if (!(error instanceof AwaitSuspend)) throw error;
|
|
2452
|
+
aborted = true;
|
|
2453
|
+
index = 0;
|
|
2454
|
+
} finally {
|
|
2455
|
+
context.hydrationNode = savedHydration;
|
|
2456
|
+
context.serverValues = savedServerValues;
|
|
2457
|
+
context.awaitBoundary = oldBoundary;
|
|
2458
|
+
}
|
|
2422
2459
|
if (boundary.suspended && renderWith !== null) renderBranch(1, renderWith);
|
|
2423
|
-
else if (
|
|
2460
|
+
else if (boundary.suspended && aborted) {
|
|
2461
|
+
runControlBranch(region, index, 1);
|
|
2462
|
+
index = 1;
|
|
2463
|
+
} else if (!boundary.suspended) hasContent = true;
|
|
2424
2464
|
};
|
|
2425
2465
|
if (theEffect === null) attemptContent();
|
|
2426
2466
|
else {
|
|
@@ -2630,7 +2670,15 @@ function $batch(fn) {
|
|
|
2630
2670
|
* so there's no re-fetch wait and no fallback flash.
|
|
2631
2671
|
*
|
|
2632
2672
|
* @param fn A thunk returning the Promise to await. Signal reads inside `fn`
|
|
2633
|
-
* are tracked, so the fetch re-runs when dependencies change.
|
|
2673
|
+
* are tracked, so the fetch re-runs when dependencies change. With
|
|
2674
|
+
* `source: "server"`, the thunk receives the server-resolved value (if any)
|
|
2675
|
+
* as its argument on the client's first (hydration) run, so it can return it
|
|
2676
|
+
* unchanged to skip expensive work the server already did. Later runs (a
|
|
2677
|
+
* dependency change, a `$refresh`, or a client-side navigation with no
|
|
2678
|
+
* server value) receive `undefined`. Reads still have to happen before any
|
|
2679
|
+
* early return for their changes to be tracked. Annotate the thunk's return
|
|
2680
|
+
* type (e.g. `async (server): Promise<string> => …`) when the result type
|
|
2681
|
+
* isn't inferable from the thunk's body alone.
|
|
2634
2682
|
* @param _options Accepted so the same getter source compiles into client and
|
|
2635
2683
|
* server builds (`source: "server"` fetches during SSR); ignored here.
|
|
2636
2684
|
*/
|
|
@@ -2654,8 +2702,12 @@ function $async(fn, _options) {
|
|
|
2654
2702
|
staleValue: void 0,
|
|
2655
2703
|
rollback: null
|
|
2656
2704
|
};
|
|
2705
|
+
const serverValues = context.serverValues;
|
|
2706
|
+
const serverValue = serverValues !== null && serverValues.index < serverValues.values.length ? serverValues.values[serverValues.index] : void 0;
|
|
2707
|
+
let firstRun = true;
|
|
2657
2708
|
computed.run = () => {
|
|
2658
|
-
const value = fn();
|
|
2709
|
+
const value = fn(firstRun ? serverValue : void 0);
|
|
2710
|
+
firstRun = false;
|
|
2659
2711
|
if (value !== null && value !== void 0 && typeof value.then === "function") {
|
|
2660
2712
|
const gen = ++computed.generation;
|
|
2661
2713
|
computed.didSuspend = true;
|
|
@@ -2687,7 +2739,6 @@ function $async(fn, _options) {
|
|
|
2687
2739
|
};
|
|
2688
2740
|
context.registerComputed(computed);
|
|
2689
2741
|
runComputed(computed);
|
|
2690
|
-
const serverValues = context.serverValues;
|
|
2691
2742
|
if (serverValues !== null && serverValues.index < serverValues.values.length) {
|
|
2692
2743
|
computed.generation++;
|
|
2693
2744
|
computed.didSuspend = false;
|