hadars 0.3.0 → 0.3.2

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/cli.js CHANGED
@@ -271,7 +271,16 @@ function componentCalledUseId() {
271
271
  function snapshotContext() {
272
272
  const st = s();
273
273
  const ctx = st.currentTreeContext;
274
- return { tree: { id: ctx.id, overflow: ctx.overflow }, localId: st.localIdCounter, treeDepth: _treeDepth };
274
+ const depth = _treeDepth;
275
+ return {
276
+ tree: { id: ctx.id, overflow: ctx.overflow },
277
+ localId: st.localIdCounter,
278
+ treeDepth: depth,
279
+ // Snapshot the live stack so that popTreeContext reads correct saved values
280
+ // even if another concurrent render's resetRenderState stomped the arrays.
281
+ idStack: _treeIdStack.slice(0, depth),
282
+ ovStack: _treeOvStack.slice(0, depth)
283
+ };
275
284
  }
276
285
  function restoreContext(snap) {
277
286
  const st = s();
@@ -280,6 +289,10 @@ function restoreContext(snap) {
280
289
  ctx.overflow = snap.tree.overflow;
281
290
  st.localIdCounter = snap.localId;
282
291
  _treeDepth = snap.treeDepth;
292
+ for (let i = 0; i < snap.treeDepth; i++) {
293
+ _treeIdStack[i] = snap.idStack[i];
294
+ _treeOvStack[i] = snap.ovStack[i];
295
+ }
283
296
  }
284
297
  function getTreeId() {
285
298
  const { id, overflow } = s().currentTreeContext;
@@ -393,6 +406,14 @@ function restoreDispatcher(prev) {
393
406
  }
394
407
 
395
408
  // src/slim-react/render.ts
409
+ function captureRenderCtx() {
410
+ return { m: captureMap(), u: captureUnsuspend(), t: snapshotContext() };
411
+ }
412
+ function restoreRenderCtx(ctx) {
413
+ swapContextMap(ctx.m);
414
+ restoreUnsuspend(ctx.u);
415
+ restoreContext(ctx.t);
416
+ }
396
417
  var VOID_ELEMENTS = /* @__PURE__ */ new Set([
397
418
  "area",
398
419
  "base",
@@ -836,11 +857,9 @@ function renderComponent(type, props, writer, isSvg, _suspenseRetries = 0) {
836
857
  if (e && typeof e.then === "function") {
837
858
  if (_suspenseRetries + 1 >= MAX_COMPONENT_SUSPENSE_RETRIES) throw SUSPENSE_RETRY_LIMIT;
838
859
  patchPromiseStatus(e);
839
- const m = captureMap();
840
- const u = captureUnsuspend();
860
+ const rctx = captureRenderCtx();
841
861
  return e.then(() => {
842
- swapContextMap(m);
843
- restoreUnsuspend(u);
862
+ restoreRenderCtx(rctx);
844
863
  return renderComponent(type, props, writer, isSvg, _suspenseRetries + 1);
845
864
  });
846
865
  }
@@ -877,17 +896,14 @@ function renderComponent(type, props, writer, isSvg, _suspenseRetries = 0) {
877
896
  };
878
897
  const r2 = renderChildren(props.children, writer, isSvg);
879
898
  if (r2 && typeof r2.then === "function") {
880
- const m = captureMap();
881
- const u = captureUnsuspend();
899
+ const rctx = captureRenderCtx();
882
900
  return r2.then(
883
901
  () => {
884
- swapContextMap(m);
885
- restoreUnsuspend(u);
902
+ restoreRenderCtx(rctx);
886
903
  finish();
887
904
  },
888
905
  (e) => {
889
- swapContextMap(m);
890
- restoreUnsuspend(u);
906
+ restoreRenderCtx(rctx);
891
907
  finish();
892
908
  throw e;
893
909
  }
@@ -916,11 +932,9 @@ function renderComponent(type, props, writer, isSvg, _suspenseRetries = 0) {
916
932
  if (e && typeof e.then === "function") {
917
933
  if (_suspenseRetries + 1 >= MAX_COMPONENT_SUSPENSE_RETRIES) throw SUSPENSE_RETRY_LIMIT;
918
934
  patchPromiseStatus(e);
919
- const m = captureMap();
920
- const u = captureUnsuspend();
935
+ const rctx = captureRenderCtx();
921
936
  return e.then(() => {
922
- swapContextMap(m);
923
- restoreUnsuspend(u);
937
+ restoreRenderCtx(rctx);
924
938
  return renderComponent(type, props, writer, isSvg, _suspenseRetries + 1);
925
939
  });
926
940
  }
@@ -932,30 +946,25 @@ function renderComponent(type, props, writer, isSvg, _suspenseRetries = 0) {
932
946
  savedIdTree = pushTreeContext(1, 0);
933
947
  }
934
948
  if (result instanceof Promise) {
935
- const m = captureMap();
936
- const u = captureUnsuspend();
949
+ const rctx = captureRenderCtx();
937
950
  return result.then((resolved) => {
938
- swapContextMap(m);
939
- restoreUnsuspend(u);
951
+ restoreRenderCtx(rctx);
940
952
  let asyncSavedIdTree;
941
953
  if (componentCalledUseId()) {
942
954
  asyncSavedIdTree = pushTreeContext(1, 0);
943
955
  }
944
956
  const r2 = renderNode(resolved, writer, isSvg);
945
957
  if (r2 && typeof r2.then === "function") {
946
- const m2 = captureMap();
947
- const u2 = captureUnsuspend();
958
+ const rctx2 = captureRenderCtx();
948
959
  return r2.then(
949
960
  () => {
950
- swapContextMap(m2);
951
- restoreUnsuspend(u2);
961
+ restoreRenderCtx(rctx2);
952
962
  if (asyncSavedIdTree !== void 0) popTreeContext(asyncSavedIdTree);
953
963
  popComponentScope(savedScope);
954
964
  if (isProvider) popContextValue(ctx, prevCtxValue);
955
965
  },
956
966
  (e) => {
957
- swapContextMap(m2);
958
- restoreUnsuspend(u2);
967
+ restoreRenderCtx(rctx2);
959
968
  if (asyncSavedIdTree !== void 0) popTreeContext(asyncSavedIdTree);
960
969
  popComponentScope(savedScope);
961
970
  if (isProvider) popContextValue(ctx, prevCtxValue);
@@ -967,8 +976,7 @@ function renderComponent(type, props, writer, isSvg, _suspenseRetries = 0) {
967
976
  popComponentScope(savedScope);
968
977
  if (isProvider) popContextValue(ctx, prevCtxValue);
969
978
  }, (e) => {
970
- swapContextMap(m);
971
- restoreUnsuspend(u);
979
+ restoreRenderCtx(rctx);
972
980
  popComponentScope(savedScope);
973
981
  if (isProvider) popContextValue(ctx, prevCtxValue);
974
982
  throw e;
@@ -976,19 +984,16 @@ function renderComponent(type, props, writer, isSvg, _suspenseRetries = 0) {
976
984
  }
977
985
  const r = renderNode(result, writer, isSvg);
978
986
  if (r && typeof r.then === "function") {
979
- const m = captureMap();
980
- const u = captureUnsuspend();
987
+ const rctx = captureRenderCtx();
981
988
  return r.then(
982
989
  () => {
983
- swapContextMap(m);
984
- restoreUnsuspend(u);
990
+ restoreRenderCtx(rctx);
985
991
  if (savedIdTree !== void 0) popTreeContext(savedIdTree);
986
992
  popComponentScope(savedScope);
987
993
  if (isProvider) popContextValue(ctx, prevCtxValue);
988
994
  },
989
995
  (e) => {
990
- swapContextMap(m);
991
- restoreUnsuspend(u);
996
+ restoreRenderCtx(rctx);
992
997
  if (savedIdTree !== void 0) popTreeContext(savedIdTree);
993
998
  popComponentScope(savedScope);
994
999
  if (isProvider) popContextValue(ctx, prevCtxValue);
@@ -1013,11 +1018,9 @@ function renderChildArrayFrom(children, startIndex, writer, isSvg) {
1013
1018
  const savedTree = pushTreeContext(totalChildren, i);
1014
1019
  const r = renderNode(child, writer, isSvg);
1015
1020
  if (r && typeof r.then === "function") {
1016
- const m = captureMap();
1017
- const u = captureUnsuspend();
1021
+ const rctx = captureRenderCtx();
1018
1022
  return r.then(() => {
1019
- swapContextMap(m);
1020
- restoreUnsuspend(u);
1023
+ restoreRenderCtx(rctx);
1021
1024
  popTreeContext(savedTree);
1022
1025
  return renderChildArrayFrom(children, i + 1, writer, isSvg);
1023
1026
  });
@@ -1041,11 +1044,9 @@ async function renderSuspense(props, writer, isSvg = false) {
1041
1044
  try {
1042
1045
  const r = renderNode(children, buffer, isSvg);
1043
1046
  if (r && typeof r.then === "function") {
1044
- const m = captureMap();
1045
- const u = captureUnsuspend();
1047
+ const rctx = captureRenderCtx();
1046
1048
  await r;
1047
- swapContextMap(m);
1048
- restoreUnsuspend(u);
1049
+ restoreRenderCtx(rctx);
1049
1050
  }
1050
1051
  writer.write("<!--$-->");
1051
1052
  buffer.flushTo(writer);
@@ -1059,11 +1060,9 @@ async function renderSuspense(props, writer, isSvg = false) {
1059
1060
  if (fallback) {
1060
1061
  const r = renderNode(fallback, writer, isSvg);
1061
1062
  if (r && typeof r.then === "function") {
1062
- const m = captureMap();
1063
- const u = captureUnsuspend();
1063
+ const rctx = captureRenderCtx();
1064
1064
  await r;
1065
- swapContextMap(m);
1066
- restoreUnsuspend(u);
1065
+ restoreRenderCtx(rctx);
1067
1066
  }
1068
1067
  }
1069
1068
  writer.write("<!--/$-->");
@@ -1088,9 +1087,9 @@ async function renderPreflight(element, options) {
1088
1087
  NULL_WRITER.lastWasText = false;
1089
1088
  const r = renderNode(element, NULL_WRITER);
1090
1089
  if (r && typeof r.then === "function") {
1091
- const m = captureMap();
1090
+ const rctx = captureRenderCtx();
1092
1091
  await r;
1093
- swapContextMap(m);
1092
+ restoreRenderCtx(rctx);
1094
1093
  }
1095
1094
  } finally {
1096
1095
  swapContextMap(prev);
@@ -1115,9 +1114,9 @@ async function renderToString(element, options) {
1115
1114
  resetRenderState(idPrefix);
1116
1115
  const r = renderNode(element, writer);
1117
1116
  if (r && typeof r.then === "function") {
1118
- const m = captureMap();
1117
+ const rctx = captureRenderCtx();
1119
1118
  await r;
1120
- swapContextMap(m);
1119
+ restoreRenderCtx(rctx);
1121
1120
  }
1122
1121
  return output;
1123
1122
  } finally {
@@ -1484,6 +1483,12 @@ var buildCompilerConfig = (entry, opts, includeHotPlugin) => {
1484
1483
  // changed files, making repeat dev starts significantly faster.
1485
1484
  cache: true,
1486
1485
  externals,
1486
+ // externalsPresets.node externalises ALL Node.js built-ins (bare names
1487
+ // and the node: prefix) for both static and dynamic imports. This
1488
+ // complements the explicit `externals` array: the preset handles the
1489
+ // node: URI scheme that rspack cannot resolve as a file, while the
1490
+ // array keeps '@emotion/server' as an explicit external.
1491
+ ...isServerBuild ? { externalsPresets: { node: true } } : {},
1487
1492
  ...optimization !== void 0 ? { optimization } : {},
1488
1493
  plugins: [
1489
1494
  !isServerBuild && new rspack.HtmlRspackPlugin({
@@ -1536,7 +1541,7 @@ var buildCompilerConfig = (entry, opts, includeHotPlugin) => {
1536
1541
  // SSR watcher writing .hadars/index.ssr.js triggers the client compiler
1537
1542
  // and vice versa, causing an infinite rebuild loop.
1538
1543
  watchOptions: {
1539
- ignored: ["**/node_modules/**", "**/.hadars/**"]
1544
+ ignored: ["**/node_modules/**", "**/.hadars/**", "/tmp/**"]
1540
1545
  }
1541
1546
  };
1542
1547
  };
@@ -1548,7 +1553,7 @@ var compileEntry = async (entry, opts) => {
1548
1553
  if (opts.watch) {
1549
1554
  await new Promise((resolve2, reject) => {
1550
1555
  let first = true;
1551
- compiler.watch({ ignored: ["**/node_modules/**", "**/.hadars/**"] }, (err, stats) => {
1556
+ compiler.watch({ ignored: ["**/node_modules/**", "**/.hadars/**", "/tmp/**"] }, (err, stats) => {
1552
1557
  if (err) {
1553
1558
  if (first) {
1554
1559
  first = false;
@@ -1581,10 +1586,7 @@ var compileEntry = async (entry, opts) => {
1581
1586
  }
1582
1587
  console.log(stats?.toString({
1583
1588
  colors: true,
1584
- modules: true,
1585
- children: true,
1586
- chunks: true,
1587
- chunkModules: true
1589
+ preset: "minimal"
1588
1590
  }));
1589
1591
  resolve2(stats);
1590
1592
  });
@@ -1626,27 +1628,8 @@ function withRequestLogging(handler) {
1626
1628
  return res;
1627
1629
  };
1628
1630
  }
1629
- var COMPRESSIBLE_RE = /^text\/|\/json|\/javascript|\/xml|\/wasm/;
1630
- function withCompression(handler) {
1631
- return async (req, ctx) => {
1632
- const res = await handler(req, ctx);
1633
- if (!res || !res.body) return res;
1634
- const accept = req.headers.get("Accept-Encoding") ?? "";
1635
- if (!accept.includes("gzip")) return res;
1636
- if (res.headers.has("content-encoding")) return res;
1637
- const ct = res.headers.get("content-type") ?? "";
1638
- if (!COMPRESSIBLE_RE.test(ct)) return res;
1639
- const compressed = res.body.pipeThrough(
1640
- new globalThis.CompressionStream("gzip")
1641
- );
1642
- const headers = new Headers(res.headers);
1643
- headers.set("content-encoding", "gzip");
1644
- headers.delete("content-length");
1645
- return new Response(compressed, { status: res.status, headers });
1646
- };
1647
- }
1648
1631
  async function serve(port, fetchHandler, websocket) {
1649
- fetchHandler = withCompression(withRequestLogging(fetchHandler));
1632
+ fetchHandler = withRequestLogging(fetchHandler);
1650
1633
  if (isBun) {
1651
1634
  globalThis.Bun.serve({
1652
1635
  port,
@@ -1805,18 +1788,18 @@ var makePrecontentHtmlGetter = (htmlFilePromise) => {
1805
1788
  let preHead = null;
1806
1789
  let postHead = null;
1807
1790
  let postContent = null;
1791
+ const primed = htmlFilePromise.then((html) => {
1792
+ const headEnd = html.indexOf(HEAD_MARKER);
1793
+ const contentStart = html.indexOf(BODY_MARKER);
1794
+ preHead = html.slice(0, headEnd);
1795
+ postHead = html.slice(headEnd + HEAD_MARKER.length, contentStart);
1796
+ postContent = html.slice(contentStart + BODY_MARKER.length);
1797
+ });
1808
1798
  return (headHtml) => {
1809
1799
  if (preHead !== null) {
1810
1800
  return [preHead + headHtml + postHead, postContent];
1811
1801
  }
1812
- return htmlFilePromise.then((html) => {
1813
- const headEnd = html.indexOf(HEAD_MARKER);
1814
- const contentStart = html.indexOf(BODY_MARKER);
1815
- preHead = html.slice(0, headEnd);
1816
- postHead = html.slice(headEnd + HEAD_MARKER.length, contentStart);
1817
- postContent = html.slice(contentStart + BODY_MARKER.length);
1818
- return [preHead + headHtml + postHead, postContent];
1819
- });
1802
+ return primed.then(() => [preHead + headHtml + postHead, postContent]);
1820
1803
  };
1821
1804
  };
1822
1805
  async function transformStream(data, stream) {
@@ -1839,8 +1822,18 @@ async function transformStream(data, stream) {
1839
1822
  }
1840
1823
  return out;
1841
1824
  }
1842
- var gzipCompress = (d) => transformStream(d, new globalThis.CompressionStream("gzip"));
1843
- var gzipDecompress = (d) => transformStream(d, new globalThis.DecompressionStream("gzip"));
1825
+ async function zlibGzip(d) {
1826
+ const zlib = await import("node:zlib");
1827
+ const { promisify } = await import("node:util");
1828
+ return promisify(zlib.gzip)(d);
1829
+ }
1830
+ async function zlibGunzip(d) {
1831
+ const zlib = await import("node:zlib");
1832
+ const { promisify } = await import("node:util");
1833
+ return promisify(zlib.gunzip)(d);
1834
+ }
1835
+ var gzipCompress = (d) => globalThis.CompressionStream ? transformStream(d, new globalThis.CompressionStream("gzip")) : zlibGzip(d);
1836
+ var gzipDecompress = (d) => globalThis.DecompressionStream ? transformStream(d, new globalThis.DecompressionStream("gzip")) : zlibGunzip(d);
1844
1837
  async function buildCacheEntry(res, ttl) {
1845
1838
  const buf = await res.arrayBuffer();
1846
1839
  const body = await gzipCompress(new Uint8Array(buf));
@@ -2842,6 +2835,10 @@ var run = async (options) => {
2842
2835
  const getPrecontentHtml = makePrecontentHtmlGetter(
2843
2836
  fs.readFile(pathMod2.join(__dirname2, StaticPath, "out.html"), "utf-8")
2844
2837
  );
2838
+ const componentPath = pathToFileURL(
2839
+ pathMod2.resolve(__dirname2, HadarsFolder, SSR_FILENAME)
2840
+ ).href;
2841
+ const ssrModulePromise = import(componentPath);
2845
2842
  const runHandler = async (req, ctx) => {
2846
2843
  const request = parseRequest(req);
2847
2844
  if (handler) {
@@ -2865,15 +2862,12 @@ var run = async (options) => {
2865
2862
  );
2866
2863
  if (routeRes) return routeRes;
2867
2864
  }
2868
- const componentPath = pathToFileURL(
2869
- pathMod2.resolve(__dirname2, HadarsFolder, SSR_FILENAME)
2870
- ).href;
2871
2865
  try {
2872
2866
  const {
2873
2867
  default: Component,
2874
2868
  getInitProps,
2875
2869
  getFinalProps
2876
- } = await import(componentPath);
2870
+ } = await ssrModulePromise;
2877
2871
  if (renderPool && request.headers.get("Accept") !== "application/json") {
2878
2872
  const serialReq = await serializeRequest(request);
2879
2873
  const { html, headHtml: wHead, status: wStatus } = await renderPool.renderFull(serialReq);
@@ -283,7 +283,16 @@ function componentCalledUseId() {
283
283
  function snapshotContext() {
284
284
  const st = s();
285
285
  const ctx = st.currentTreeContext;
286
- return { tree: { id: ctx.id, overflow: ctx.overflow }, localId: st.localIdCounter, treeDepth: _treeDepth };
286
+ const depth = _treeDepth;
287
+ return {
288
+ tree: { id: ctx.id, overflow: ctx.overflow },
289
+ localId: st.localIdCounter,
290
+ treeDepth: depth,
291
+ // Snapshot the live stack so that popTreeContext reads correct saved values
292
+ // even if another concurrent render's resetRenderState stomped the arrays.
293
+ idStack: _treeIdStack.slice(0, depth),
294
+ ovStack: _treeOvStack.slice(0, depth)
295
+ };
287
296
  }
288
297
  function restoreContext(snap) {
289
298
  const st = s();
@@ -292,6 +301,10 @@ function restoreContext(snap) {
292
301
  ctx.overflow = snap.tree.overflow;
293
302
  st.localIdCounter = snap.localId;
294
303
  _treeDepth = snap.treeDepth;
304
+ for (let i = 0; i < snap.treeDepth; i++) {
305
+ _treeIdStack[i] = snap.idStack[i];
306
+ _treeOvStack[i] = snap.ovStack[i];
307
+ }
295
308
  }
296
309
  function getTreeId() {
297
310
  const { id, overflow } = s().currentTreeContext;
@@ -405,6 +418,14 @@ function restoreDispatcher(prev) {
405
418
  }
406
419
 
407
420
  // src/slim-react/render.ts
421
+ function captureRenderCtx() {
422
+ return { m: captureMap(), u: captureUnsuspend(), t: snapshotContext() };
423
+ }
424
+ function restoreRenderCtx(ctx) {
425
+ swapContextMap(ctx.m);
426
+ restoreUnsuspend(ctx.u);
427
+ restoreContext(ctx.t);
428
+ }
408
429
  var VOID_ELEMENTS = /* @__PURE__ */ new Set([
409
430
  "area",
410
431
  "base",
@@ -848,11 +869,9 @@ function renderComponent(type, props, writer, isSvg, _suspenseRetries = 0) {
848
869
  if (e && typeof e.then === "function") {
849
870
  if (_suspenseRetries + 1 >= MAX_COMPONENT_SUSPENSE_RETRIES) throw SUSPENSE_RETRY_LIMIT;
850
871
  patchPromiseStatus(e);
851
- const m = captureMap();
852
- const u = captureUnsuspend();
872
+ const rctx = captureRenderCtx();
853
873
  return e.then(() => {
854
- swapContextMap(m);
855
- restoreUnsuspend(u);
874
+ restoreRenderCtx(rctx);
856
875
  return renderComponent(type, props, writer, isSvg, _suspenseRetries + 1);
857
876
  });
858
877
  }
@@ -889,17 +908,14 @@ function renderComponent(type, props, writer, isSvg, _suspenseRetries = 0) {
889
908
  };
890
909
  const r2 = renderChildren(props.children, writer, isSvg);
891
910
  if (r2 && typeof r2.then === "function") {
892
- const m = captureMap();
893
- const u = captureUnsuspend();
911
+ const rctx = captureRenderCtx();
894
912
  return r2.then(
895
913
  () => {
896
- swapContextMap(m);
897
- restoreUnsuspend(u);
914
+ restoreRenderCtx(rctx);
898
915
  finish();
899
916
  },
900
917
  (e) => {
901
- swapContextMap(m);
902
- restoreUnsuspend(u);
918
+ restoreRenderCtx(rctx);
903
919
  finish();
904
920
  throw e;
905
921
  }
@@ -928,11 +944,9 @@ function renderComponent(type, props, writer, isSvg, _suspenseRetries = 0) {
928
944
  if (e && typeof e.then === "function") {
929
945
  if (_suspenseRetries + 1 >= MAX_COMPONENT_SUSPENSE_RETRIES) throw SUSPENSE_RETRY_LIMIT;
930
946
  patchPromiseStatus(e);
931
- const m = captureMap();
932
- const u = captureUnsuspend();
947
+ const rctx = captureRenderCtx();
933
948
  return e.then(() => {
934
- swapContextMap(m);
935
- restoreUnsuspend(u);
949
+ restoreRenderCtx(rctx);
936
950
  return renderComponent(type, props, writer, isSvg, _suspenseRetries + 1);
937
951
  });
938
952
  }
@@ -944,30 +958,25 @@ function renderComponent(type, props, writer, isSvg, _suspenseRetries = 0) {
944
958
  savedIdTree = pushTreeContext(1, 0);
945
959
  }
946
960
  if (result instanceof Promise) {
947
- const m = captureMap();
948
- const u = captureUnsuspend();
961
+ const rctx = captureRenderCtx();
949
962
  return result.then((resolved) => {
950
- swapContextMap(m);
951
- restoreUnsuspend(u);
963
+ restoreRenderCtx(rctx);
952
964
  let asyncSavedIdTree;
953
965
  if (componentCalledUseId()) {
954
966
  asyncSavedIdTree = pushTreeContext(1, 0);
955
967
  }
956
968
  const r2 = renderNode(resolved, writer, isSvg);
957
969
  if (r2 && typeof r2.then === "function") {
958
- const m2 = captureMap();
959
- const u2 = captureUnsuspend();
970
+ const rctx2 = captureRenderCtx();
960
971
  return r2.then(
961
972
  () => {
962
- swapContextMap(m2);
963
- restoreUnsuspend(u2);
973
+ restoreRenderCtx(rctx2);
964
974
  if (asyncSavedIdTree !== void 0) popTreeContext(asyncSavedIdTree);
965
975
  popComponentScope(savedScope);
966
976
  if (isProvider) popContextValue(ctx, prevCtxValue);
967
977
  },
968
978
  (e) => {
969
- swapContextMap(m2);
970
- restoreUnsuspend(u2);
979
+ restoreRenderCtx(rctx2);
971
980
  if (asyncSavedIdTree !== void 0) popTreeContext(asyncSavedIdTree);
972
981
  popComponentScope(savedScope);
973
982
  if (isProvider) popContextValue(ctx, prevCtxValue);
@@ -979,8 +988,7 @@ function renderComponent(type, props, writer, isSvg, _suspenseRetries = 0) {
979
988
  popComponentScope(savedScope);
980
989
  if (isProvider) popContextValue(ctx, prevCtxValue);
981
990
  }, (e) => {
982
- swapContextMap(m);
983
- restoreUnsuspend(u);
991
+ restoreRenderCtx(rctx);
984
992
  popComponentScope(savedScope);
985
993
  if (isProvider) popContextValue(ctx, prevCtxValue);
986
994
  throw e;
@@ -988,19 +996,16 @@ function renderComponent(type, props, writer, isSvg, _suspenseRetries = 0) {
988
996
  }
989
997
  const r = renderNode(result, writer, isSvg);
990
998
  if (r && typeof r.then === "function") {
991
- const m = captureMap();
992
- const u = captureUnsuspend();
999
+ const rctx = captureRenderCtx();
993
1000
  return r.then(
994
1001
  () => {
995
- swapContextMap(m);
996
- restoreUnsuspend(u);
1002
+ restoreRenderCtx(rctx);
997
1003
  if (savedIdTree !== void 0) popTreeContext(savedIdTree);
998
1004
  popComponentScope(savedScope);
999
1005
  if (isProvider) popContextValue(ctx, prevCtxValue);
1000
1006
  },
1001
1007
  (e) => {
1002
- swapContextMap(m);
1003
- restoreUnsuspend(u);
1008
+ restoreRenderCtx(rctx);
1004
1009
  if (savedIdTree !== void 0) popTreeContext(savedIdTree);
1005
1010
  popComponentScope(savedScope);
1006
1011
  if (isProvider) popContextValue(ctx, prevCtxValue);
@@ -1025,11 +1030,9 @@ function renderChildArrayFrom(children, startIndex, writer, isSvg) {
1025
1030
  const savedTree = pushTreeContext(totalChildren, i);
1026
1031
  const r = renderNode(child, writer, isSvg);
1027
1032
  if (r && typeof r.then === "function") {
1028
- const m = captureMap();
1029
- const u = captureUnsuspend();
1033
+ const rctx = captureRenderCtx();
1030
1034
  return r.then(() => {
1031
- swapContextMap(m);
1032
- restoreUnsuspend(u);
1035
+ restoreRenderCtx(rctx);
1033
1036
  popTreeContext(savedTree);
1034
1037
  return renderChildArrayFrom(children, i + 1, writer, isSvg);
1035
1038
  });
@@ -1053,11 +1056,9 @@ async function renderSuspense(props, writer, isSvg = false) {
1053
1056
  try {
1054
1057
  const r = renderNode(children, buffer, isSvg);
1055
1058
  if (r && typeof r.then === "function") {
1056
- const m = captureMap();
1057
- const u = captureUnsuspend();
1059
+ const rctx = captureRenderCtx();
1058
1060
  await r;
1059
- swapContextMap(m);
1060
- restoreUnsuspend(u);
1061
+ restoreRenderCtx(rctx);
1061
1062
  }
1062
1063
  writer.write("<!--$-->");
1063
1064
  buffer.flushTo(writer);
@@ -1071,11 +1072,9 @@ async function renderSuspense(props, writer, isSvg = false) {
1071
1072
  if (fallback) {
1072
1073
  const r = renderNode(fallback, writer, isSvg);
1073
1074
  if (r && typeof r.then === "function") {
1074
- const m = captureMap();
1075
- const u = captureUnsuspend();
1075
+ const rctx = captureRenderCtx();
1076
1076
  await r;
1077
- swapContextMap(m);
1078
- restoreUnsuspend(u);
1077
+ restoreRenderCtx(rctx);
1079
1078
  }
1080
1079
  }
1081
1080
  writer.write("<!--/$-->");
@@ -1100,9 +1099,9 @@ async function renderPreflight(element, options) {
1100
1099
  NULL_WRITER.lastWasText = false;
1101
1100
  const r = renderNode(element, NULL_WRITER);
1102
1101
  if (r && typeof r.then === "function") {
1103
- const m = captureMap();
1102
+ const rctx = captureRenderCtx();
1104
1103
  await r;
1105
- swapContextMap(m);
1104
+ restoreRenderCtx(rctx);
1106
1105
  }
1107
1106
  } finally {
1108
1107
  swapContextMap(prev);
@@ -1127,9 +1126,9 @@ async function renderToString(element, options) {
1127
1126
  resetRenderState(idPrefix);
1128
1127
  const r = renderNode(element, writer);
1129
1128
  if (r && typeof r.then === "function") {
1130
- const m = captureMap();
1129
+ const rctx = captureRenderCtx();
1131
1130
  await r;
1132
- swapContextMap(m);
1131
+ restoreRenderCtx(rctx);
1133
1132
  }
1134
1133
  return output;
1135
1134
  } finally {
@@ -1245,18 +1244,18 @@ var makePrecontentHtmlGetter = (htmlFilePromise) => {
1245
1244
  let preHead = null;
1246
1245
  let postHead = null;
1247
1246
  let postContent = null;
1247
+ const primed = htmlFilePromise.then((html) => {
1248
+ const headEnd = html.indexOf(HEAD_MARKER);
1249
+ const contentStart = html.indexOf(BODY_MARKER);
1250
+ preHead = html.slice(0, headEnd);
1251
+ postHead = html.slice(headEnd + HEAD_MARKER.length, contentStart);
1252
+ postContent = html.slice(contentStart + BODY_MARKER.length);
1253
+ });
1248
1254
  return (headHtml) => {
1249
1255
  if (preHead !== null) {
1250
1256
  return [preHead + headHtml + postHead, postContent];
1251
1257
  }
1252
- return htmlFilePromise.then((html) => {
1253
- const headEnd = html.indexOf(HEAD_MARKER);
1254
- const contentStart = html.indexOf(BODY_MARKER);
1255
- preHead = html.slice(0, headEnd);
1256
- postHead = html.slice(headEnd + HEAD_MARKER.length, contentStart);
1257
- postContent = html.slice(contentStart + BODY_MARKER.length);
1258
- return [preHead + headHtml + postHead, postContent];
1259
- });
1258
+ return primed.then(() => [preHead + headHtml + postHead, postContent]);
1260
1259
  };
1261
1260
  };
1262
1261
  async function transformStream(data, stream) {
@@ -1279,8 +1278,18 @@ async function transformStream(data, stream) {
1279
1278
  }
1280
1279
  return out;
1281
1280
  }
1282
- var gzipCompress = (d) => transformStream(d, new globalThis.CompressionStream("gzip"));
1283
- var gzipDecompress = (d) => transformStream(d, new globalThis.DecompressionStream("gzip"));
1281
+ async function zlibGzip(d) {
1282
+ const zlib = await import("zlib");
1283
+ const { promisify } = await import("util");
1284
+ return promisify(zlib.gzip)(d);
1285
+ }
1286
+ async function zlibGunzip(d) {
1287
+ const zlib = await import("zlib");
1288
+ const { promisify } = await import("util");
1289
+ return promisify(zlib.gunzip)(d);
1290
+ }
1291
+ var gzipCompress = (d) => globalThis.CompressionStream ? transformStream(d, new globalThis.CompressionStream("gzip")) : zlibGzip(d);
1292
+ var gzipDecompress = (d) => globalThis.DecompressionStream ? transformStream(d, new globalThis.DecompressionStream("gzip")) : zlibGunzip(d);
1284
1293
  async function buildCacheEntry(res, ttl) {
1285
1294
  const buf = await res.arrayBuffer();
1286
1295
  const body = await gzipCompress(new Uint8Array(buf));
@@ -6,8 +6,8 @@ import {
6
6
  getReactResponse,
7
7
  makePrecontentHtmlGetter,
8
8
  parseRequest
9
- } from "./chunk-H72BZXOA.js";
10
- import "./chunk-LY5MTHFV.js";
9
+ } from "./chunk-2J2L2H3H.js";
10
+ import "./chunk-TV37IMRB.js";
11
11
  import "./chunk-OS3V4CPN.js";
12
12
 
13
13
  // src/cloudflare.ts