@void/isr 1.12.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.
Files changed (2) hide show
  1. package/dist/runtime.mjs +9 -5
  2. package/package.json +2 -2
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.12.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": {
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@cloudflare/workers-types": "^5.20261125.1",
38
- "@void/edge": "1.12.0"
38
+ "@void/edge": "1.12.1"
39
39
  },
40
40
  "devDependencies": {
41
41
  "tsrs": "7.1.0-beta.tsrs4",