@void/isr 1.11.0 → 1.12.1

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/core.d.mts CHANGED
@@ -83,9 +83,13 @@ export type IsrPageTtl = Readonly<{
83
83
  * Only requests that match no page fall back to the flattened revalidate config.
84
84
  */
85
85
  export declare function resolvePageTtl(pages: ReadonlyArray<IsrPageTtl> | undefined, revalidate: number | Record<string, number> | undefined, pathRevalidate: Record<string, number> | undefined, pathname: string): number;
86
+ interface SerializedHeaders {
87
+ [name: string]: string;
88
+ }
86
89
  /** Extract response headers while removing ISR-managed and private headers. */
87
- export declare function serializeHeaders(response: Response): Record<string, string>;
90
+ export declare function serializeHeaders(response: Response): SerializedHeaders;
88
91
  /** Validate page data before storing it as the JSON ISR variant. */
89
92
  export declare function normalizePageDataForJsonCache(raw: string): string | null;
90
93
  /** Extract validated Void Pages data embedded in an HTML response. */
91
- export declare function extractPageDataFromHtml(html: string): string | null;
94
+ export declare function extractPageDataFromHtml(html: string): string | null;
95
+ export {};
package/dist/core.mjs CHANGED
@@ -190,7 +190,7 @@ function isSharedCacheableResponse(response) {
190
190
  }
191
191
  /** Resolve the first matching path TTL using Void route-pattern semantics. */
192
192
  function resolvePathTtl(revalidate, pathname) {
193
- if (revalidate == null) return 0;
193
+ if (revalidate === null || revalidate === void 0) return 0;
194
194
  if (typeof revalidate === "number") return revalidate;
195
195
  for (const [pattern, ttl] of Object.entries(revalidate)) if (matchSegmentPattern(pattern, pathname)) return ttl;
196
196
  return 0;
@@ -221,7 +221,8 @@ function serializeHeaders(response) {
221
221
  function normalizePageDataForJsonCache(raw) {
222
222
  try {
223
223
  const parsed = JSON.parse(raw);
224
- return parsed.deferred === void 0 && parsed.deferredKeys === void 0 ? raw : null;
224
+ if (parsed === null || typeof parsed === "object" && ("deferred" in parsed && parsed.deferred !== void 0 || "deferredKeys" in parsed && parsed.deferredKeys !== void 0)) return null;
225
+ return raw;
225
226
  } catch {
226
227
  return null;
227
228
  }
package/dist/index.d.mts CHANGED
@@ -61,15 +61,16 @@ export declare function isrLegacyCacheVariantPrefix(projectId: string, deploymen
61
61
  * original URLs or their query strings. Not cryptographic.
62
62
  */
63
63
  export declare function hashOriginalUrl(originalUrl: string): string;
64
+ type IsrCacheKeyParts = {
65
+ normalizedPath: string;
66
+ variantToken: string | null;
67
+ };
64
68
  /**
65
69
  * Split an ISR KV key into its normalized path and its `#rw=` variant token
66
70
  * (`null` for a direct hit). Pass the token to `isrEdgeCacheUrlForToken` to
67
71
  * rebuild the matching edge-cache URL.
68
72
  */
69
- export declare function splitIsrCacheKey(fullKey: string): {
70
- normalizedPath: string;
71
- variantToken: string | null;
72
- };
73
+ export declare function splitIsrCacheKey(fullKey: string): IsrCacheKeyParts;
73
74
  /**
74
75
  * Edge-cache (`caches.default`) URL for an ISR page. It carries the deployment
75
76
  * id so a new deploy never reads older HTML, and the `json` variant keeps
package/dist/runtime.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { SHARED_CACHE_POLICY_HEADER, SHARED_CACHE_POLICY_VERSION, buildVariantOriginalUrl, decodeIsrCacheEntry, extractPageDataFromHtml, hasCurrentSharedCachePolicy, hasSharedCacheOptOut, hasUnlistedQueryParams, isFrameworkDocumentRequest, isSharedCacheableResponse, isStale, isrCacheResponse, markSharedCachePolicy, normalizePageDataForJsonCache, packIsrValue, resolvePageTtl, resolvePathTtl, resolveRevalidateTtl, serializeHeaders, shouldBypassIsr, unpackIsrValue } from "./core.mjs";
2
2
  import { canonicalIsrPathname, denormalizeIsrPath, isrCacheKey, isrCachePrefix, isrCacheVariantPrefix, isrEdgeCacheUrl, normalizeIsrPath } from "./index.mjs";
3
- import { PAGES_PROTOCOL_VERSION, matchSegmentPattern } from "@void/edge";
3
+ import { PAGES_BUILD_HEADER, PAGES_PROTOCOL_VERSION, isStaleBuildReload, matchSegmentPattern, pagesPayloadFitsBuild } from "@void/edge";
4
4
  // src/runtime.ts
5
5
  const MAX_ISR_VARIANTS_PER_PATH = 200;
6
6
  const ISR_STALE_EVICT_GRACE_MS = 864e5;
@@ -167,11 +167,12 @@ function sharedHtmlCacheHeaders(response, ttl, state) {
167
167
  headers.delete("x-void-page-data");
168
168
  return headers;
169
169
  }
170
- function jsonCacheResponse(pageData, ttl, state) {
170
+ function jsonCacheResponse(pageData, ttl, state, build) {
171
171
  const response = new Response(pageData, { headers: {
172
172
  "content-type": "application/json",
173
173
  "X-VoidPages": "true",
174
174
  "X-VoidPages-Version": PAGES_PROTOCOL_VERSION,
175
+ ...build ? { [PAGES_BUILD_HEADER]: build } : {},
175
176
  Vary: "X-VoidPages, X-VoidPages-Version",
176
177
  "Cache-Control": `public, s-maxage=${ttl}, max-age=0, must-revalidate`,
177
178
  "x-isr-cache": state
@@ -187,10 +188,11 @@ function jsonCacheResponse(pageData, ttl, state) {
187
188
  async function populateJsonEdgeCache(cache, cacheKey, response, ttl, state) {
188
189
  if (!cache) return;
189
190
  try {
191
+ const build = response.headers.get(PAGES_BUILD_HEADER);
190
192
  const fromHeader = response.headers.get("x-void-page-data");
191
193
  const pageData = fromHeader ? normalizePageDataForJsonCache(fromHeader) : extractPageDataFromHtml(await response.clone().text());
192
194
  if (!pageData) return;
193
- await cache.put(cacheKey, jsonCacheResponse(pageData, ttl, state));
195
+ await cache.put(cacheKey, jsonCacheResponse(pageData, ttl, state, build));
194
196
  } catch {}
195
197
  }
196
198
  /** `caches.default`, or `undefined` when reading it throws (for example, with no Cache API). */
@@ -301,9 +303,11 @@ async function handleIsrInternal(request, env, ctx, options, render, htmlOnly) {
301
303
  } catch {
302
304
  return null;
303
305
  }
304
- if (jsonCached && hasCurrentSharedCachePolicy(jsonCached)) return clientRevalidateResponse(jsonCached);
305
- if (jsonCached) await safeCacheDelete(cache, jsonKey);
306
+ if (jsonCached && hasCurrentSharedCachePolicy(jsonCached)) {
307
+ if (pagesPayloadFitsBuild(jsonCached.headers.get(PAGES_BUILD_HEADER), request.headers.get(PAGES_BUILD_HEADER))) return clientRevalidateResponse(jsonCached);
308
+ } else if (jsonCached) await safeCacheDelete(cache, jsonKey);
306
309
  const response = await render(request);
310
+ if (isStaleBuildReload(request, response)) return response;
307
311
  if (isUncacheableRender(response, resolveRevalidateTtl(response, isrTtl), false)) ctx.waitUntil(deleteSharedIsrVariants(env, cache, host, pathname, {
308
312
  htmlKey,
309
313
  jsonKey
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@void/isr",
3
- "version": "1.11.0",
3
+ "version": "1.12.1",
4
4
  "description": "Incremental revalidation and cache helpers for Void runtimes.",
5
5
  "homepage": "https://void.cloud",
6
6
  "bugs": {
@@ -34,16 +34,17 @@
34
34
  "access": "public"
35
35
  },
36
36
  "dependencies": {
37
- "@cloudflare/workers-types": "^5.20261117.1",
38
- "@void/edge": "1.11.0"
37
+ "@cloudflare/workers-types": "^5.20261125.1",
38
+ "@void/edge": "1.12.1"
39
39
  },
40
40
  "devDependencies": {
41
+ "tsrs": "7.1.0-beta.tsrs4",
41
42
  "typescript": "7.0.2",
42
- "vite-plus": "1.7.0"
43
+ "vite-plus": "1.8.0"
43
44
  },
44
45
  "scripts": {
45
46
  "build": "vp pack",
46
47
  "dev": "vp pack --watch",
47
- "typecheck": "tsc --noEmit"
48
+ "typecheck": "tsrs --noEmit"
48
49
  }
49
50
  }