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