@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.
package/dist/vue/index.js CHANGED
@@ -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;
@@ -2401,7 +2438,7 @@ __export(exports_stylePreprocessor, {
2401
2438
  compileStyleFileIfNeeded: () => compileStyleFileIfNeeded,
2402
2439
  addStyleImporter: () => addStyleImporter
2403
2440
  });
2404
- import { createHash } from "crypto";
2441
+ import { createHash as createHash2 } from "crypto";
2405
2442
  import { existsSync as existsSync6, readFileSync as readFileSync5 } from "fs";
2406
2443
  import { readFile as readFile2 } from "fs/promises";
2407
2444
  import { createRequire } from "module";
@@ -2734,7 +2771,7 @@ ${contents}` : contents, normalizePostcssModule = (mod) => {
2734
2771
  return importers;
2735
2772
  }, recordStyleOutput = (entry, css) => {
2736
2773
  const key = resolve6(entry);
2737
- const hash = createHash("sha1").update(css).digest("hex");
2774
+ const hash = createHash2("sha1").update(css).digest("hex");
2738
2775
  const previous = styleOutputHashes.get(key);
2739
2776
  styleOutputHashes.set(key, hash);
2740
2777
  return previous !== hash;
@@ -4283,9 +4320,11 @@ var setCurrentIslandManifest = (manifest) => {
4283
4320
 
4284
4321
  // src/vue/pageHandler.ts
4285
4322
  init_devRouteRegistrationCallsite();
4323
+ init_pageResponseCache();
4286
4324
 
4287
4325
  // src/core/responseEnhancers.ts
4288
4326
  init_streamingSlots();
4327
+ init_pageResponseCache();
4289
4328
  var toResponse = async (responseLike) => responseLike;
4290
4329
  var cloneHeaders = (response) => {
4291
4330
  const headers = new Headers(response.headers);
@@ -4309,8 +4348,10 @@ var enhanceHtmlResponseWithStreamingSlots = (response, {
4309
4348
  runtimePlacement,
4310
4349
  runtimePreludeScript
4311
4350
  });
4351
+ const headers = cloneHeaders(response);
4352
+ headers.set(STREAMING_PAGE_HEADER, "1");
4312
4353
  return new Response(body, {
4313
- headers: cloneHeaders(response),
4354
+ headers,
4314
4355
  status: response.status,
4315
4356
  statusText: response.statusText
4316
4357
  });
@@ -4845,20 +4886,24 @@ var handleVuePageRequest = async (input) => {
4845
4886
  hasIslands: resolvedPage.hasIslands
4846
4887
  });
4847
4888
  return new Response(htmlStream, {
4848
- headers: { "Content-Type": "text/html" }
4889
+ headers: streamingPageHeaders()
4849
4890
  });
4850
4891
  };
4851
- return await runWithStreamingSlotWarningScope(() => resolvedOptions?.collectStreamingSlots === true ? withRegisteredStreamingSlots(renderPageResponse, resolvedOptions) : renderPageResponse(), { handlerCallsite });
4892
+ const pageResponse = await runWithStreamingSlotWarningScope(() => resolvedOptions?.collectStreamingSlots === true ? withRegisteredStreamingSlots(renderPageResponse, resolvedOptions) : renderPageResponse(), { handlerCallsite });
4893
+ return withPageCacheHeaders(pageResponse, input.request, {
4894
+ bufferStreamForEtag: input.bufferStreamForEtag
4895
+ });
4852
4896
  } catch (error) {
4853
4897
  console.error("[SSR] Vue render error:", error);
4854
4898
  const pageName = derivePageName(resolvedPagePath);
4855
4899
  const conventionResponse = await renderConventionError("vue", pageName, error);
4856
- if (conventionResponse)
4857
- return conventionResponse;
4858
- return new Response(ssrErrorPage("vue", error), {
4900
+ if (conventionResponse) {
4901
+ return withPageCacheHeaders(conventionResponse, input.request);
4902
+ }
4903
+ return withPageCacheHeaders(new Response(ssrErrorPage("vue", error), {
4859
4904
  headers: { "Content-Type": "text/html" },
4860
4905
  status: 500
4861
- });
4906
+ }), input.request);
4862
4907
  }
4863
4908
  };
4864
4909
  // src/vue/routerRedirectProviders.ts
@@ -5317,5 +5362,5 @@ export {
5317
5362
  Image
5318
5363
  };
5319
5364
 
5320
- //# debugId=36CE6B63A2D1DAFF64756E2164756E21
5365
+ //# debugId=047227623E0628A564756E2164756E21
5321
5366
  //# sourceMappingURL=index.js.map