@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.
@@ -37362,6 +37362,44 @@ var getRouteCallsiteStorage = () => {
37362
37362
  };
37363
37363
  var getCurrentRouteRegistrationCallsite = () => getRouteCallsiteStorage()?.getStore()?.callsite;
37364
37364
 
37365
+ // src/core/pageResponseCache.ts
37366
+ import { createHash } from "crypto";
37367
+ var STREAMING_PAGE_HEADER = "x-absolute-stream";
37368
+ var HTML_CONTENT_TYPE = "text/html";
37369
+ var streamingPageHeaders = (extra) => {
37370
+ const headers = new Headers(extra);
37371
+ headers.set("content-type", HTML_CONTENT_TYPE);
37372
+ headers.set(STREAMING_PAGE_HEADER, "1");
37373
+ return headers;
37374
+ };
37375
+ var computeEtag = (html) => `W/"${createHash("sha1").update(html).digest("base64url")}"`;
37376
+ var withPageCacheHeaders = async (response, request) => {
37377
+ const contentType = response.headers.get("content-type") ?? "";
37378
+ if (!contentType.includes(HTML_CONTENT_TYPE))
37379
+ return response;
37380
+ if (response.headers.get(STREAMING_PAGE_HEADER) === "1" || !response.body) {
37381
+ response.headers.delete(STREAMING_PAGE_HEADER);
37382
+ response.headers.set("cache-control", "no-cache");
37383
+ return response;
37384
+ }
37385
+ const html = await response.text();
37386
+ const etag = computeEtag(html);
37387
+ if (request?.headers.get("if-none-match") === etag) {
37388
+ return new Response(null, {
37389
+ headers: { "cache-control": "no-cache", etag },
37390
+ status: 304
37391
+ });
37392
+ }
37393
+ const headers = new Headers(response.headers);
37394
+ headers.set("cache-control", "no-cache");
37395
+ headers.set("etag", etag);
37396
+ return new Response(html, {
37397
+ headers,
37398
+ status: response.status,
37399
+ statusText: response.statusText
37400
+ });
37401
+ };
37402
+
37365
37403
  // src/client/streamSwap.ts
37366
37404
  var streamSwapRuntime = () => {
37367
37405
  const absoluteWindow = window;
@@ -38095,8 +38133,10 @@ var enhanceHtmlResponseWithStreamingSlots = (response, {
38095
38133
  runtimePlacement,
38096
38134
  runtimePreludeScript
38097
38135
  });
38136
+ const headers = cloneHeaders(response);
38137
+ headers.set(STREAMING_PAGE_HEADER, "1");
38098
38138
  return new Response(body, {
38099
- headers: cloneHeaders(response),
38139
+ headers,
38100
38140
  status: response.status,
38101
38141
  statusText: response.statusText
38102
38142
  });
@@ -38565,19 +38605,21 @@ var handleReactPageRequest = async (input) => {
38565
38605
  });
38566
38606
  }
38567
38607
  return new Response(htmlStream, {
38568
- headers: { "Content-Type": "text/html" }
38608
+ headers: streamingPageHeaders()
38569
38609
  });
38570
38610
  };
38571
- return await runWithStreamingSlotWarningScope(() => options?.collectStreamingSlots === true ? withRegisteredStreamingSlots(renderPageResponse, options) : renderPageResponse(), { handlerCallsite });
38611
+ const pageResponse = await runWithStreamingSlotWarningScope(() => options?.collectStreamingSlots === true ? withRegisteredStreamingSlots(renderPageResponse, options) : renderPageResponse(), { handlerCallsite });
38612
+ return withPageCacheHeaders(pageResponse, input.request);
38572
38613
  } catch (error) {
38573
38614
  console.error("[SSR] React render error:", error);
38574
38615
  const conventionResponse = await renderConventionError("react", pageName, error);
38575
- if (conventionResponse)
38576
- return conventionResponse;
38577
- return new Response(ssrErrorPage("react", error), {
38616
+ if (conventionResponse) {
38617
+ return withPageCacheHeaders(conventionResponse, input.request);
38618
+ }
38619
+ return withPageCacheHeaders(new Response(ssrErrorPage("react", error), {
38578
38620
  headers: { "Content-Type": "text/html" },
38579
38621
  status: 500
38580
- });
38622
+ }), input.request);
38581
38623
  }
38582
38624
  };
38583
38625
 
package/dist/index.js CHANGED
@@ -8678,6 +8678,41 @@ var init_staticIslandPages = __esm(() => {
8678
8678
  HTMX_STREAM_SLOT_TAG_RE = /<abs-htmx-stream-slot\b([^>]*?)(?:\/>|>([\s\S]*?)<\/abs-htmx-stream-slot>)/gi;
8679
8679
  });
8680
8680
 
8681
+ // src/core/pageResponseCache.ts
8682
+ import { createHash as createHash3 } from "crypto";
8683
+ var STREAMING_PAGE_HEADER = "x-absolute-stream", HTML_CONTENT_TYPE = "text/html", streamingPageHeaders = (extra) => {
8684
+ const headers = new Headers(extra);
8685
+ headers.set("content-type", HTML_CONTENT_TYPE);
8686
+ headers.set(STREAMING_PAGE_HEADER, "1");
8687
+ return headers;
8688
+ }, computeEtag = (html) => `W/"${createHash3("sha1").update(html).digest("base64url")}"`, withPageCacheHeaders = async (response, request) => {
8689
+ const contentType = response.headers.get("content-type") ?? "";
8690
+ if (!contentType.includes(HTML_CONTENT_TYPE))
8691
+ return response;
8692
+ if (response.headers.get(STREAMING_PAGE_HEADER) === "1" || !response.body) {
8693
+ response.headers.delete(STREAMING_PAGE_HEADER);
8694
+ response.headers.set("cache-control", "no-cache");
8695
+ return response;
8696
+ }
8697
+ const html = await response.text();
8698
+ const etag = computeEtag(html);
8699
+ if (request?.headers.get("if-none-match") === etag) {
8700
+ return new Response(null, {
8701
+ headers: { "cache-control": "no-cache", etag },
8702
+ status: 304
8703
+ });
8704
+ }
8705
+ const headers = new Headers(response.headers);
8706
+ headers.set("cache-control", "no-cache");
8707
+ headers.set("etag", etag);
8708
+ return new Response(html, {
8709
+ headers,
8710
+ status: response.status,
8711
+ statusText: response.statusText
8712
+ });
8713
+ };
8714
+ var init_pageResponseCache = () => {};
8715
+
8681
8716
  // node_modules/@elysiajs/openapi/dist/index.mjs
8682
8717
  var exports_dist = {};
8683
8718
  __export(exports_dist, {
@@ -21379,7 +21414,7 @@ var devVendorPaths = null, getDevVendorPaths = () => devVendorPaths, setDevVendo
21379
21414
  // src/build/angularLinkerPlugin.ts
21380
21415
  import { existsSync as existsSync21, mkdirSync as mkdirSync5, readFileSync as readFileSync15, writeFileSync as writeFileSync6 } from "fs";
21381
21416
  import { dirname as dirname11, join as join23, relative as relative7, resolve as resolve17 } from "path";
21382
- import { createHash as createHash3 } from "crypto";
21417
+ import { createHash as createHash4 } from "crypto";
21383
21418
  var CACHE_ROOT, ANGULAR_LINKER_CANDIDATE_RE, createAngularLinkerPlugin = (linkerJitMode) => ({
21384
21419
  name: "angular-linker",
21385
21420
  setup(bld) {
@@ -21398,7 +21433,7 @@ var CACHE_ROOT, ANGULAR_LINKER_CANDIDATE_RE, createAngularLinkerPlugin = (linker
21398
21433
  if (!checkLink || !checkLink(args.path, source)) {
21399
21434
  return;
21400
21435
  }
21401
- const hash = createHash3("md5").update(source).digest("hex");
21436
+ const hash = createHash4("md5").update(source).digest("hex");
21402
21437
  const cachePath = join23(cacheDir, `${hash}.js`);
21403
21438
  if (existsSync21(cachePath)) {
21404
21439
  return {
@@ -34264,18 +34299,20 @@ var resolveRequestPathname = (request) => {
34264
34299
  }
34265
34300
  const innerHtml = bundle.renderToHTML(props ?? {});
34266
34301
  const html = buildHtmlShell(resolvedHeadTag, innerHtml.replace(/^<div>|<\/div>$/g, ""), indexPath, props);
34267
- return new Response(html, {
34302
+ return withPageCacheHeaders(new Response(html, {
34268
34303
  headers: { "Content-Type": "text/html" }
34269
- });
34304
+ }), input.request);
34270
34305
  } catch (error) {
34271
34306
  console.error("[SSR] Ember render error:", error);
34272
- return new Response(ssrErrorPage("ember", error), {
34307
+ return withPageCacheHeaders(new Response(ssrErrorPage("ember", error), {
34273
34308
  headers: { "Content-Type": "text/html" },
34274
34309
  status: 500
34275
- });
34310
+ }), input.request);
34276
34311
  }
34277
34312
  };
34278
- var init_pageHandler = () => {};
34313
+ var init_pageHandler = __esm(() => {
34314
+ init_pageResponseCache();
34315
+ });
34279
34316
 
34280
34317
  // src/ember/index.ts
34281
34318
  var exports_ember = {};
@@ -38965,10 +39002,12 @@ var setCurrentIslandManifest = (manifest) => {
38965
39002
  };
38966
39003
 
38967
39004
  // src/core/pageHandlers.ts
39005
+ init_pageResponseCache();
38968
39006
  init_staticStreaming();
38969
39007
 
38970
39008
  // src/core/responseEnhancers.ts
38971
39009
  init_streamingSlots();
39010
+ init_pageResponseCache();
38972
39011
  var toResponse = async (responseLike) => responseLike;
38973
39012
  var cloneHeaders = (response) => {
38974
39013
  const headers = new Headers(response.headers);
@@ -38992,8 +39031,10 @@ var enhanceHtmlResponseWithStreamingSlots = (response, {
38992
39031
  runtimePlacement,
38993
39032
  runtimePreludeScript
38994
39033
  });
39034
+ const headers = cloneHeaders(response);
39035
+ headers.set(STREAMING_PAGE_HEADER, "1");
38995
39036
  return new Response(body, {
38996
- headers: cloneHeaders(response),
39037
+ headers,
38997
39038
  status: response.status,
38998
39039
  statusText: response.statusText
38999
39040
  });
@@ -39020,12 +39061,12 @@ var withRegisteredStreamingSlots = async (renderResponse, options = {}) => {
39020
39061
  var handleStaticPageRequest = async (pagePath, options = {}, settings = {}) => {
39021
39062
  const html = await file(pagePath).text();
39022
39063
  const transformedHtml = await transformCurrentStaticPageHtml(html, settings);
39023
- return withStreamingSlots(new Response(injectIslandPageContext(transformedHtml), {
39064
+ return withPageCacheHeaders(await withStreamingSlots(new Response(injectIslandPageContext(transformedHtml), {
39024
39065
  headers: { "Content-Type": "text/html" }
39025
39066
  }), {
39026
39067
  ...options,
39027
39068
  streamingSlots: options.streamingSlots ?? []
39028
- });
39069
+ }));
39029
39070
  };
39030
39071
  var handleHTMLPageRequest = (pagePath, options) => {
39031
39072
  const htmlFile = file(pagePath);
@@ -46670,5 +46711,5 @@ export {
46670
46711
  ANGULAR_INIT_TIMEOUT_MS
46671
46712
  };
46672
46713
 
46673
- //# debugId=C9D8370D5AE5318964756E2164756E21
46714
+ //# debugId=2D1E98E62AB63D3064756E2164756E21
46674
46715
  //# sourceMappingURL=index.js.map