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

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.
@@ -184,6 +184,41 @@ var init_devRouteRegistrationCallsite = __esm(() => {
184
184
  pageHandlerWrappers = new WeakMap;
185
185
  });
186
186
 
187
+ // src/core/pageResponseCache.ts
188
+ import { createHash } from "crypto";
189
+ var STREAMING_PAGE_HEADER = "x-absolute-stream", HTML_CONTENT_TYPE = "text/html", streamingPageHeaders = (extra) => {
190
+ const headers = new Headers(extra);
191
+ headers.set("content-type", HTML_CONTENT_TYPE);
192
+ headers.set(STREAMING_PAGE_HEADER, "1");
193
+ return headers;
194
+ }, computeEtag = (html) => `W/"${createHash("sha1").update(html).digest("base64url")}"`, withPageCacheHeaders = async (response, request) => {
195
+ const contentType = response.headers.get("content-type") ?? "";
196
+ if (!contentType.includes(HTML_CONTENT_TYPE))
197
+ return response;
198
+ if (response.headers.get(STREAMING_PAGE_HEADER) === "1" || !response.body) {
199
+ response.headers.delete(STREAMING_PAGE_HEADER);
200
+ response.headers.set("cache-control", "no-cache");
201
+ return response;
202
+ }
203
+ const html = await response.text();
204
+ const etag = computeEtag(html);
205
+ if (request?.headers.get("if-none-match") === etag) {
206
+ return new Response(null, {
207
+ headers: { "cache-control": "no-cache", etag },
208
+ status: 304
209
+ });
210
+ }
211
+ const headers = new Headers(response.headers);
212
+ headers.set("cache-control", "no-cache");
213
+ headers.set("etag", etag);
214
+ return new Response(html, {
215
+ headers,
216
+ status: response.status,
217
+ statusText: response.statusText
218
+ });
219
+ };
220
+ var init_pageResponseCache = () => {};
221
+
187
222
  // src/client/streamSwap.ts
188
223
  var streamSwapRuntime = () => {
189
224
  const absoluteWindow = window;
@@ -2276,7 +2311,7 @@ __export(exports_stylePreprocessor, {
2276
2311
  compileStyleFileIfNeeded: () => compileStyleFileIfNeeded,
2277
2312
  addStyleImporter: () => addStyleImporter
2278
2313
  });
2279
- import { createHash } from "crypto";
2314
+ import { createHash as createHash2 } from "crypto";
2280
2315
  import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
2281
2316
  import { readFile } from "fs/promises";
2282
2317
  import { createRequire } from "module";
@@ -2609,7 +2644,7 @@ ${contents}` : contents, normalizePostcssModule = (mod) => {
2609
2644
  return importers;
2610
2645
  }, recordStyleOutput = (entry, css) => {
2611
2646
  const key = resolve4(entry);
2612
- const hash = createHash("sha1").update(css).digest("hex");
2647
+ const hash = createHash2("sha1").update(css).digest("hex");
2613
2648
  const previous = styleOutputHashes.get(key);
2614
2649
  styleOutputHashes.set(key, hash);
2615
2650
  return previous !== hash;
@@ -3624,9 +3659,11 @@ var setCurrentIslandManifest = (manifest) => {
3624
3659
 
3625
3660
  // src/react/pageHandler.ts
3626
3661
  init_devRouteRegistrationCallsite();
3662
+ init_pageResponseCache();
3627
3663
 
3628
3664
  // src/core/responseEnhancers.ts
3629
3665
  init_streamingSlots();
3666
+ init_pageResponseCache();
3630
3667
  var toResponse = async (responseLike) => responseLike;
3631
3668
  var cloneHeaders = (response) => {
3632
3669
  const headers = new Headers(response.headers);
@@ -3650,8 +3687,10 @@ var enhanceHtmlResponseWithStreamingSlots = (response, {
3650
3687
  runtimePlacement,
3651
3688
  runtimePreludeScript
3652
3689
  });
3690
+ const headers = cloneHeaders(response);
3691
+ headers.set(STREAMING_PAGE_HEADER, "1");
3653
3692
  return new Response(body, {
3654
- headers: cloneHeaders(response),
3693
+ headers,
3655
3694
  status: response.status,
3656
3695
  statusText: response.statusText
3657
3696
  });
@@ -4076,19 +4115,21 @@ var handleReactPageRequest = async (input) => {
4076
4115
  });
4077
4116
  }
4078
4117
  return new Response(htmlStream, {
4079
- headers: { "Content-Type": "text/html" }
4118
+ headers: streamingPageHeaders()
4080
4119
  });
4081
4120
  };
4082
- return await runWithStreamingSlotWarningScope(() => options?.collectStreamingSlots === true ? withRegisteredStreamingSlots(renderPageResponse, options) : renderPageResponse(), { handlerCallsite });
4121
+ const pageResponse = await runWithStreamingSlotWarningScope(() => options?.collectStreamingSlots === true ? withRegisteredStreamingSlots(renderPageResponse, options) : renderPageResponse(), { handlerCallsite });
4122
+ return withPageCacheHeaders(pageResponse, input.request);
4083
4123
  } catch (error) {
4084
4124
  console.error("[SSR] React render error:", error);
4085
4125
  const conventionResponse = await renderConventionError("react", pageName, error);
4086
- if (conventionResponse)
4087
- return conventionResponse;
4088
- return new Response(ssrErrorPage("react", error), {
4126
+ if (conventionResponse) {
4127
+ return withPageCacheHeaders(conventionResponse, input.request);
4128
+ }
4129
+ return withPageCacheHeaders(new Response(ssrErrorPage("react", error), {
4089
4130
  headers: { "Content-Type": "text/html" },
4090
4131
  status: 500
4091
- });
4132
+ }), input.request);
4092
4133
  }
4093
4134
  };
4094
4135
  // src/react/Island.tsx
@@ -4255,5 +4296,5 @@ export {
4255
4296
  Island
4256
4297
  };
4257
4298
 
4258
- //# debugId=7006DCA84EC7515E64756E2164756E21
4299
+ //# debugId=F2CC8AF56565368C64756E2164756E21
4259
4300
  //# sourceMappingURL=index.js.map