@absolutejs/absolute 0.19.0-beta.1073 → 0.19.0-beta.1075

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.
@@ -204,6 +204,43 @@ var init_devRouteRegistrationCallsite = __esm(() => {
204
204
  pageHandlerWrappers = new WeakMap;
205
205
  });
206
206
 
207
+ // src/core/pageResponseCache.ts
208
+ import { createHash } from "crypto";
209
+ var STREAMING_PAGE_HEADER = "x-absolute-stream", HTML_CONTENT_TYPE = "text/html", streamingPageHeaders = (extra) => {
210
+ const headers = new Headers(extra);
211
+ headers.set("content-type", HTML_CONTENT_TYPE);
212
+ headers.set(STREAMING_PAGE_HEADER, "1");
213
+ return headers;
214
+ }, computeEtag = (html) => `W/"${createHash("sha1").update(html).digest("base64url")}"`, withPageCacheHeaders = async (response, request, options) => {
215
+ const contentType = response.headers.get("content-type") ?? "";
216
+ if (!contentType.includes(HTML_CONTENT_TYPE))
217
+ return response;
218
+ const isStreaming = response.headers.get(STREAMING_PAGE_HEADER) === "1";
219
+ if (isStreaming && !options?.bufferStreamForEtag || !response.body) {
220
+ response.headers.delete(STREAMING_PAGE_HEADER);
221
+ response.headers.set("cache-control", "no-cache");
222
+ return response;
223
+ }
224
+ const html = await response.text();
225
+ const etag = computeEtag(html);
226
+ if (request?.headers.get("if-none-match") === etag) {
227
+ return new Response(null, {
228
+ headers: { "cache-control": "no-cache", etag },
229
+ status: 304
230
+ });
231
+ }
232
+ const headers = new Headers(response.headers);
233
+ headers.delete(STREAMING_PAGE_HEADER);
234
+ headers.set("cache-control", "no-cache");
235
+ headers.set("etag", etag);
236
+ return new Response(html, {
237
+ headers,
238
+ status: response.status,
239
+ statusText: response.statusText
240
+ });
241
+ };
242
+ var init_pageResponseCache = () => {};
243
+
207
244
  // src/client/streamSwap.ts
208
245
  var streamSwapRuntime = () => {
209
246
  const absoluteWindow = window;
@@ -1663,9 +1700,11 @@ var setCurrentIslandManifest = (manifest) => {
1663
1700
 
1664
1701
  // src/vue/pageHandler.ts
1665
1702
  init_devRouteRegistrationCallsite();
1703
+ init_pageResponseCache();
1666
1704
 
1667
1705
  // src/core/responseEnhancers.ts
1668
1706
  init_streamingSlots();
1707
+ init_pageResponseCache();
1669
1708
  var toResponse = async (responseLike) => responseLike;
1670
1709
  var cloneHeaders = (response) => {
1671
1710
  const headers = new Headers(response.headers);
@@ -1689,8 +1728,10 @@ var enhanceHtmlResponseWithStreamingSlots = (response, {
1689
1728
  runtimePlacement,
1690
1729
  runtimePreludeScript
1691
1730
  });
1731
+ const headers = cloneHeaders(response);
1732
+ headers.set(STREAMING_PAGE_HEADER, "1");
1692
1733
  return new Response(body, {
1693
- headers: cloneHeaders(response),
1734
+ headers,
1694
1735
  status: response.status,
1695
1736
  statusText: response.statusText
1696
1737
  });
@@ -2225,20 +2266,24 @@ var handleVuePageRequest = async (input) => {
2225
2266
  hasIslands: resolvedPage.hasIslands
2226
2267
  });
2227
2268
  return new Response(htmlStream, {
2228
- headers: { "Content-Type": "text/html" }
2269
+ headers: streamingPageHeaders()
2229
2270
  });
2230
2271
  };
2231
- return await runWithStreamingSlotWarningScope(() => resolvedOptions?.collectStreamingSlots === true ? withRegisteredStreamingSlots(renderPageResponse, resolvedOptions) : renderPageResponse(), { handlerCallsite });
2272
+ const pageResponse = await runWithStreamingSlotWarningScope(() => resolvedOptions?.collectStreamingSlots === true ? withRegisteredStreamingSlots(renderPageResponse, resolvedOptions) : renderPageResponse(), { handlerCallsite });
2273
+ return withPageCacheHeaders(pageResponse, input.request, {
2274
+ bufferStreamForEtag: input.bufferStreamForEtag
2275
+ });
2232
2276
  } catch (error) {
2233
2277
  console.error("[SSR] Vue render error:", error);
2234
2278
  const pageName = derivePageName(resolvedPagePath);
2235
2279
  const conventionResponse = await renderConventionError("vue", pageName, error);
2236
- if (conventionResponse)
2237
- return conventionResponse;
2238
- return new Response(ssrErrorPage("vue", error), {
2280
+ if (conventionResponse) {
2281
+ return withPageCacheHeaders(conventionResponse, input.request);
2282
+ }
2283
+ return withPageCacheHeaders(new Response(ssrErrorPage("vue", error), {
2239
2284
  headers: { "Content-Type": "text/html" },
2240
2285
  status: 500
2241
- });
2286
+ }), input.request);
2242
2287
  }
2243
2288
  };
2244
2289
  // src/vue/routerRedirectProviders.ts
@@ -2263,5 +2308,5 @@ export {
2263
2308
  applyVueRouterRedirect
2264
2309
  };
2265
2310
 
2266
- //# debugId=DF370BFB52D534FE64756E2164756E21
2311
+ //# debugId=640AF13916F4E0C664756E2164756E21
2267
2312
  //# sourceMappingURL=server.js.map