@vesk/runtime 0.2.30 → 0.2.31
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/resource.d.ts +2 -0
- package/dist/resource.d.ts.map +1 -1
- package/dist/resource.js +43 -1
- package/package.json +2 -2
package/dist/resource.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export interface UseFetchOptions<T> extends Omit<RequestInit, 'body'> {
|
|
|
13
13
|
into?: Tracked<T>;
|
|
14
14
|
body?: unknown;
|
|
15
15
|
staleTime?: number;
|
|
16
|
+
/** Server-only TTL in ms for caching a FAILED fetch per key. Default `10000`. `0` disables. */
|
|
17
|
+
failureTtl?: number;
|
|
16
18
|
keepPreviousData?: boolean;
|
|
17
19
|
retry?: number;
|
|
18
20
|
retryDelay?: number;
|
package/dist/resource.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAQhE,MAAM,WAAW,QAAQ,CAAC,CAAC,CAAE,SAAQ,WAAW,CAAC,CAAC,CAAC;IAClD,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,CAAC,GAAG,SAAS,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,KAAK,EAAE,MAAM,IAAI,CAAC;CAClB;AAED,MAAM,WAAW,eAAe,CAAC,CAAC,CAAE,SAAQ,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC;IACpE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gGAAgG;IAChG,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,C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AiBnB,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAU5E"}
|
package/dist/resource.js
CHANGED
|
@@ -38,6 +38,26 @@ function getInflight() {
|
|
|
38
38
|
g().__vsk_fetch_inflight = map;
|
|
39
39
|
return map;
|
|
40
40
|
}
|
|
41
|
+
// Cross-request negative cache, keyed by resource `key` exactly like the SSR
|
|
42
|
+
// success store. A FAILED server fetch is recorded here so separate SSR
|
|
43
|
+
// requests (dev hot reloads, or any component sharing the key at any call
|
|
44
|
+
// site) settle from the cached error within the TTL instead of re-hitting a
|
|
45
|
+
// flaky/failing upstream on every render. Successes and explicit
|
|
46
|
+
// refresh()/skipCache clear or bypass it; aborts are never recorded.
|
|
47
|
+
const DEFAULT_FAILURE_TTL = 10_000;
|
|
48
|
+
function getServerFailureCache() {
|
|
49
|
+
const value = g().__vsk_ssr_failure_cache;
|
|
50
|
+
if (value)
|
|
51
|
+
return value;
|
|
52
|
+
const map = new Map();
|
|
53
|
+
g().__vsk_ssr_failure_cache = map;
|
|
54
|
+
return map;
|
|
55
|
+
}
|
|
56
|
+
function clearFailureCache(key) {
|
|
57
|
+
if (!isServer())
|
|
58
|
+
return;
|
|
59
|
+
g().__vsk_ssr_failure_cache?.delete(key);
|
|
60
|
+
}
|
|
41
61
|
function getRegistry() {
|
|
42
62
|
const value = g().__vsk_fetch_registry;
|
|
43
63
|
if (value)
|
|
@@ -385,6 +405,22 @@ function startRequest(handle, skipCache) {
|
|
|
385
405
|
const key = handle.key;
|
|
386
406
|
const options = handle.options;
|
|
387
407
|
if (isServer()) {
|
|
408
|
+
const failureTtl = options.failureTtl ?? DEFAULT_FAILURE_TTL;
|
|
409
|
+
if (!skipCache && failureTtl > 0) {
|
|
410
|
+
// Cross-request negative cache: a fetch that failed on an earlier
|
|
411
|
+
// render is still failing — settle from the recorded error instead of
|
|
412
|
+
// re-hitting the upstream on every render until the TTL lapses.
|
|
413
|
+
const failed = getServerFailureCache().get(key);
|
|
414
|
+
if (failed && failed.ttl > 0 && Date.now() - failed.failedAt < failed.ttl) {
|
|
415
|
+
getSsrFailures()?.set(key, failed.error);
|
|
416
|
+
settleError(handle, failed.error);
|
|
417
|
+
const settled = handle.settled.then(() => {
|
|
418
|
+
throw failed.error;
|
|
419
|
+
});
|
|
420
|
+
settled.catch(() => { });
|
|
421
|
+
return settled;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
388
424
|
const recorded = !skipCache ? getSsrFailures()?.get(key) : undefined;
|
|
389
425
|
if (recorded !== undefined) {
|
|
390
426
|
settleError(handle, recorded);
|
|
@@ -406,9 +442,13 @@ function startRequest(handle, skipCache) {
|
|
|
406
442
|
getInflight().set(key, prom);
|
|
407
443
|
prom.then(data => {
|
|
408
444
|
setSsrData(key, data, startToken);
|
|
445
|
+
clearFailureCache(key);
|
|
409
446
|
settle(handle, data);
|
|
410
447
|
}, error => {
|
|
411
448
|
getSsrFailures()?.set(key, error);
|
|
449
|
+
if (isServer() && !isAbortError(error) && failureTtl > 0) {
|
|
450
|
+
getServerFailureCache().set(key, { error, failedAt: Date.now(), ttl: failureTtl });
|
|
451
|
+
}
|
|
412
452
|
settleError(handle, error);
|
|
413
453
|
}).finally(() => {
|
|
414
454
|
if (getInflight().get(key) === prom)
|
|
@@ -584,8 +624,10 @@ export function createResource(fn, key, into, options = {}) {
|
|
|
584
624
|
// render is a different channel (per-request sink / per-token slot), so
|
|
585
625
|
// re-emit the value into the current render — otherwise snapshot() comes
|
|
586
626
|
// back empty and the page ships without its ssr-data script.
|
|
587
|
-
if (isServer())
|
|
627
|
+
if (isServer()) {
|
|
588
628
|
setSsrData(resourceKey, ssrData);
|
|
629
|
+
clearFailureCache(resourceKey);
|
|
630
|
+
}
|
|
589
631
|
settle(handle, ssrData);
|
|
590
632
|
writeCache(resourceKey, ssrData);
|
|
591
633
|
return accessor;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vesk/runtime",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.31",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Vesk runtime — reactivity, blocks, DOM operations, hydration",
|
|
6
6
|
"main": "./dist/index-client.js",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@vesk/compiler": "^0.2.
|
|
54
|
+
"@vesk/compiler": "^0.2.31"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"typecheck": "tsc --noEmit",
|