hadars 0.1.24 → 0.1.25

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
@@ -1,11 +1,4 @@
1
1
  #!/usr/bin/env node
2
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
- }) : x)(function(x) {
5
- if (typeof require !== "undefined")
6
- return require.apply(this, arguments);
7
- throw Error('Dynamic require of "' + x + '" is not supported');
8
- });
9
2
 
10
3
  // cli.ts
11
4
  import { spawn as spawn2 } from "node:child_process";
@@ -167,39 +160,34 @@ function createElement(type, props, ...children) {
167
160
  }
168
161
 
169
162
  // src/slim-react/renderContext.ts
170
- var CONTEXT_STORE_KEY = "__slimReactContextStore";
163
+ var MAP_KEY = "__slimReactContextMap";
171
164
  var _g = globalThis;
172
- if (!_g[CONTEXT_STORE_KEY]) {
173
- try {
174
- const { AsyncLocalStorage } = __require("node:async_hooks");
175
- _g[CONTEXT_STORE_KEY] = new AsyncLocalStorage();
176
- } catch {
177
- _g[CONTEXT_STORE_KEY] = null;
178
- }
165
+ if (!("__slimReactContextMap" in _g))
166
+ _g[MAP_KEY] = null;
167
+ function swapContextMap(map) {
168
+ const prev = _g[MAP_KEY];
169
+ _g[MAP_KEY] = map;
170
+ return prev;
179
171
  }
180
- var _contextStore = _g[CONTEXT_STORE_KEY];
181
- function runWithContextStore(fn) {
182
- return _contextStore ? _contextStore.run(/* @__PURE__ */ new Map(), fn) : fn();
172
+ function captureMap() {
173
+ return _g[MAP_KEY];
183
174
  }
184
175
  function getContextValue(context) {
185
- const store = _contextStore?.getStore();
186
- if (store && store.has(context))
187
- return store.get(context);
176
+ const map = _g[MAP_KEY];
177
+ if (map && map.has(context))
178
+ return map.get(context);
188
179
  const c = context;
189
180
  return "_defaultValue" in c ? c._defaultValue : c._currentValue;
190
181
  }
191
182
  function pushContextValue(context, value) {
192
- const store = _contextStore?.getStore();
183
+ const map = _g[MAP_KEY];
193
184
  const c = context;
194
- const prev = store && store.has(context) ? store.get(context) : "_defaultValue" in c ? c._defaultValue : c._currentValue;
195
- if (store)
196
- store.set(context, value);
185
+ const prev = map && map.has(context) ? map.get(context) : "_defaultValue" in c ? c._defaultValue : c._currentValue;
186
+ map?.set(context, value);
197
187
  return prev;
198
188
  }
199
189
  function popContextValue(context, prev) {
200
- const store = _contextStore?.getStore();
201
- if (store)
202
- store.set(context, prev);
190
+ _g[MAP_KEY]?.set(context, prev);
203
191
  }
204
192
  var GLOBAL_KEY = "__slimReactRenderState";
205
193
  var EMPTY = { id: 0, overflow: "", bits: 0 };
@@ -639,10 +627,18 @@ function renderComponent(type, props, writer, isSvg) {
639
627
  };
640
628
  const r2 = renderChildren(props.children, writer, isSvg);
641
629
  if (r2 && typeof r2.then === "function") {
642
- return r2.then(finish2, (e) => {
643
- finish2();
644
- throw e;
645
- });
630
+ const m = captureMap();
631
+ return r2.then(
632
+ () => {
633
+ swapContextMap(m);
634
+ finish2();
635
+ },
636
+ (e) => {
637
+ swapContextMap(m);
638
+ finish2();
639
+ throw e;
640
+ }
641
+ );
646
642
  }
647
643
  finish2();
648
644
  return;
@@ -672,26 +668,45 @@ function renderComponent(type, props, writer, isSvg) {
672
668
  popContextValue(ctx, prevCtxValue);
673
669
  };
674
670
  if (result instanceof Promise) {
671
+ const m = captureMap();
675
672
  return result.then((resolved) => {
673
+ swapContextMap(m);
676
674
  const r2 = renderNode(resolved, writer, isSvg);
677
675
  if (r2 && typeof r2.then === "function") {
678
- return r2.then(finish, (e) => {
679
- finish();
680
- throw e;
681
- });
676
+ const m2 = captureMap();
677
+ return r2.then(
678
+ () => {
679
+ swapContextMap(m2);
680
+ finish();
681
+ },
682
+ (e) => {
683
+ swapContextMap(m2);
684
+ finish();
685
+ throw e;
686
+ }
687
+ );
682
688
  }
683
689
  finish();
684
690
  }, (e) => {
691
+ swapContextMap(m);
685
692
  finish();
686
693
  throw e;
687
694
  });
688
695
  }
689
696
  const r = renderNode(result, writer, isSvg);
690
697
  if (r && typeof r.then === "function") {
691
- return r.then(finish, (e) => {
692
- finish();
693
- throw e;
694
- });
698
+ const m = captureMap();
699
+ return r.then(
700
+ () => {
701
+ swapContextMap(m);
702
+ finish();
703
+ },
704
+ (e) => {
705
+ swapContextMap(m);
706
+ finish();
707
+ throw e;
708
+ }
709
+ );
695
710
  }
696
711
  finish();
697
712
  }
@@ -707,7 +722,9 @@ function renderChildArray(children, writer, isSvg) {
707
722
  const savedTree = pushTreeContext(totalChildren, i);
708
723
  const r = renderNode(children[i], writer, isSvg);
709
724
  if (r && typeof r.then === "function") {
725
+ const m = captureMap();
710
726
  return r.then(() => {
727
+ swapContextMap(m);
711
728
  popTreeContext(savedTree);
712
729
  return renderChildArrayFrom(children, i + 1, writer, isSvg);
713
730
  });
@@ -724,7 +741,9 @@ function renderChildArrayFrom(children, startIndex, writer, isSvg) {
724
741
  const savedTree = pushTreeContext(totalChildren, i);
725
742
  const r = renderNode(children[i], writer, isSvg);
726
743
  if (r && typeof r.then === "function") {
744
+ const m = captureMap();
727
745
  return r.then(() => {
746
+ swapContextMap(m);
728
747
  popTreeContext(savedTree);
729
748
  return renderChildArrayFrom(children, i + 1, writer, isSvg);
730
749
  });
@@ -751,7 +770,9 @@ async function renderSuspense(props, writer, isSvg = false) {
751
770
  const buffer = new BufferWriter();
752
771
  const r = renderNode(children, buffer, isSvg);
753
772
  if (r && typeof r.then === "function") {
773
+ const m = captureMap();
754
774
  await r;
775
+ swapContextMap(m);
755
776
  }
756
777
  writer.write("<!--$-->");
757
778
  buffer.flush(writer);
@@ -759,7 +780,9 @@ async function renderSuspense(props, writer, isSvg = false) {
759
780
  return;
760
781
  } catch (error) {
761
782
  if (error && typeof error.then === "function") {
783
+ const m = captureMap();
762
784
  await error;
785
+ swapContextMap(m);
763
786
  attempts++;
764
787
  } else {
765
788
  throw error;
@@ -770,15 +793,21 @@ async function renderSuspense(props, writer, isSvg = false) {
770
793
  writer.write("<!--$?-->");
771
794
  if (fallback) {
772
795
  const r = renderNode(fallback, writer, isSvg);
773
- if (r && typeof r.then === "function")
796
+ if (r && typeof r.then === "function") {
797
+ const m = captureMap();
774
798
  await r;
799
+ swapContextMap(m);
800
+ }
775
801
  }
776
802
  writer.write("<!--/$-->");
777
803
  }
778
- function renderToString(element) {
779
- return runWithContextStore(async () => {
804
+ async function renderToString(element) {
805
+ const contextMap = /* @__PURE__ */ new Map();
806
+ const prev = swapContextMap(contextMap);
807
+ try {
780
808
  for (let attempt = 0; attempt < MAX_SUSPENSE_RETRIES; attempt++) {
781
809
  resetRenderState();
810
+ swapContextMap(contextMap);
782
811
  const chunks = [];
783
812
  const writer = {
784
813
  lastWasText: false,
@@ -793,19 +822,26 @@ function renderToString(element) {
793
822
  };
794
823
  try {
795
824
  const r = renderNode(element, writer);
796
- if (r && typeof r.then === "function")
825
+ if (r && typeof r.then === "function") {
826
+ const m = captureMap();
797
827
  await r;
828
+ swapContextMap(m);
829
+ }
798
830
  return chunks.join("");
799
831
  } catch (error) {
800
832
  if (error && typeof error.then === "function") {
833
+ const m = captureMap();
801
834
  await error;
835
+ swapContextMap(m);
802
836
  continue;
803
837
  }
804
838
  throw error;
805
839
  }
806
840
  }
807
841
  throw new Error("[slim-react] renderToString exceeded maximum retries");
808
- });
842
+ } finally {
843
+ swapContextMap(prev);
844
+ }
809
845
  }
810
846
 
811
847
  // src/utils/response.tsx
@@ -1094,10 +1130,6 @@ var buildCompilerConfig = (entry, opts, includeHotPlugin) => {
1094
1130
  } : void 0;
1095
1131
  const externals = isServerBuild ? [
1096
1132
  // Node.js built-ins — must not be bundled; resolved by the runtime.
1097
- // Both the bare name and the node: prefix are listed because rspack
1098
- // may encounter either form depending on how the import is written.
1099
- "node:async_hooks",
1100
- "async_hooks",
1101
1133
  "node:fs",
1102
1134
  "node:path",
1103
1135
  "node:os",
package/dist/index.js CHANGED
@@ -1,5 +1,3 @@
1
- import "./chunk-EZUCZHGV.js";
2
-
3
1
  // src/utils/Head.tsx
4
2
  import React from "react";
5
3
  import { jsx } from "react/jsx-runtime";
@@ -100,39 +100,34 @@ function createElement(type, props, ...children) {
100
100
  }
101
101
 
102
102
  // src/slim-react/renderContext.ts
103
- var CONTEXT_STORE_KEY = "__slimReactContextStore";
103
+ var MAP_KEY = "__slimReactContextMap";
104
104
  var _g = globalThis;
105
- if (!_g[CONTEXT_STORE_KEY]) {
106
- try {
107
- const { AsyncLocalStorage } = require("async_hooks");
108
- _g[CONTEXT_STORE_KEY] = new AsyncLocalStorage();
109
- } catch {
110
- _g[CONTEXT_STORE_KEY] = null;
111
- }
105
+ if (!("__slimReactContextMap" in _g))
106
+ _g[MAP_KEY] = null;
107
+ function swapContextMap(map) {
108
+ const prev = _g[MAP_KEY];
109
+ _g[MAP_KEY] = map;
110
+ return prev;
112
111
  }
113
- var _contextStore = _g[CONTEXT_STORE_KEY];
114
- function runWithContextStore(fn) {
115
- return _contextStore ? _contextStore.run(/* @__PURE__ */ new Map(), fn) : fn();
112
+ function captureMap() {
113
+ return _g[MAP_KEY];
116
114
  }
117
115
  function getContextValue(context) {
118
- const store = _contextStore?.getStore();
119
- if (store && store.has(context))
120
- return store.get(context);
116
+ const map = _g[MAP_KEY];
117
+ if (map && map.has(context))
118
+ return map.get(context);
121
119
  const c = context;
122
120
  return "_defaultValue" in c ? c._defaultValue : c._currentValue;
123
121
  }
124
122
  function pushContextValue(context, value) {
125
- const store = _contextStore?.getStore();
123
+ const map = _g[MAP_KEY];
126
124
  const c = context;
127
- const prev = store && store.has(context) ? store.get(context) : "_defaultValue" in c ? c._defaultValue : c._currentValue;
128
- if (store)
129
- store.set(context, value);
125
+ const prev = map && map.has(context) ? map.get(context) : "_defaultValue" in c ? c._defaultValue : c._currentValue;
126
+ map?.set(context, value);
130
127
  return prev;
131
128
  }
132
129
  function popContextValue(context, prev) {
133
- const store = _contextStore?.getStore();
134
- if (store)
135
- store.set(context, prev);
130
+ _g[MAP_KEY]?.set(context, prev);
136
131
  }
137
132
  var GLOBAL_KEY = "__slimReactRenderState";
138
133
  var EMPTY = { id: 0, overflow: "", bits: 0 };
@@ -678,10 +673,18 @@ function renderComponent(type, props, writer, isSvg) {
678
673
  };
679
674
  const r2 = renderChildren(props.children, writer, isSvg);
680
675
  if (r2 && typeof r2.then === "function") {
681
- return r2.then(finish2, (e) => {
682
- finish2();
683
- throw e;
684
- });
676
+ const m = captureMap();
677
+ return r2.then(
678
+ () => {
679
+ swapContextMap(m);
680
+ finish2();
681
+ },
682
+ (e) => {
683
+ swapContextMap(m);
684
+ finish2();
685
+ throw e;
686
+ }
687
+ );
685
688
  }
686
689
  finish2();
687
690
  return;
@@ -711,26 +714,45 @@ function renderComponent(type, props, writer, isSvg) {
711
714
  popContextValue(ctx, prevCtxValue);
712
715
  };
713
716
  if (result instanceof Promise) {
717
+ const m = captureMap();
714
718
  return result.then((resolved) => {
719
+ swapContextMap(m);
715
720
  const r2 = renderNode(resolved, writer, isSvg);
716
721
  if (r2 && typeof r2.then === "function") {
717
- return r2.then(finish, (e) => {
718
- finish();
719
- throw e;
720
- });
722
+ const m2 = captureMap();
723
+ return r2.then(
724
+ () => {
725
+ swapContextMap(m2);
726
+ finish();
727
+ },
728
+ (e) => {
729
+ swapContextMap(m2);
730
+ finish();
731
+ throw e;
732
+ }
733
+ );
721
734
  }
722
735
  finish();
723
736
  }, (e) => {
737
+ swapContextMap(m);
724
738
  finish();
725
739
  throw e;
726
740
  });
727
741
  }
728
742
  const r = renderNode(result, writer, isSvg);
729
743
  if (r && typeof r.then === "function") {
730
- return r.then(finish, (e) => {
731
- finish();
732
- throw e;
733
- });
744
+ const m = captureMap();
745
+ return r.then(
746
+ () => {
747
+ swapContextMap(m);
748
+ finish();
749
+ },
750
+ (e) => {
751
+ swapContextMap(m);
752
+ finish();
753
+ throw e;
754
+ }
755
+ );
734
756
  }
735
757
  finish();
736
758
  }
@@ -746,7 +768,9 @@ function renderChildArray(children, writer, isSvg) {
746
768
  const savedTree = pushTreeContext(totalChildren, i);
747
769
  const r = renderNode(children[i], writer, isSvg);
748
770
  if (r && typeof r.then === "function") {
771
+ const m = captureMap();
749
772
  return r.then(() => {
773
+ swapContextMap(m);
750
774
  popTreeContext(savedTree);
751
775
  return renderChildArrayFrom(children, i + 1, writer, isSvg);
752
776
  });
@@ -763,7 +787,9 @@ function renderChildArrayFrom(children, startIndex, writer, isSvg) {
763
787
  const savedTree = pushTreeContext(totalChildren, i);
764
788
  const r = renderNode(children[i], writer, isSvg);
765
789
  if (r && typeof r.then === "function") {
790
+ const m = captureMap();
766
791
  return r.then(() => {
792
+ swapContextMap(m);
767
793
  popTreeContext(savedTree);
768
794
  return renderChildArrayFrom(children, i + 1, writer, isSvg);
769
795
  });
@@ -790,7 +816,9 @@ async function renderSuspense(props, writer, isSvg = false) {
790
816
  const buffer = new BufferWriter();
791
817
  const r = renderNode(children, buffer, isSvg);
792
818
  if (r && typeof r.then === "function") {
819
+ const m = captureMap();
793
820
  await r;
821
+ swapContextMap(m);
794
822
  }
795
823
  writer.write("<!--$-->");
796
824
  buffer.flush(writer);
@@ -798,7 +826,9 @@ async function renderSuspense(props, writer, isSvg = false) {
798
826
  return;
799
827
  } catch (error) {
800
828
  if (error && typeof error.then === "function") {
829
+ const m = captureMap();
801
830
  await error;
831
+ swapContextMap(m);
802
832
  attempts++;
803
833
  } else {
804
834
  throw error;
@@ -809,16 +839,21 @@ async function renderSuspense(props, writer, isSvg = false) {
809
839
  writer.write("<!--$?-->");
810
840
  if (fallback) {
811
841
  const r = renderNode(fallback, writer, isSvg);
812
- if (r && typeof r.then === "function")
842
+ if (r && typeof r.then === "function") {
843
+ const m = captureMap();
813
844
  await r;
845
+ swapContextMap(m);
846
+ }
814
847
  }
815
848
  writer.write("<!--/$-->");
816
849
  }
817
850
  function renderToStream(element) {
818
851
  const encoder = new TextEncoder();
819
- return runWithContextStore(() => new ReadableStream({
852
+ const contextMap = /* @__PURE__ */ new Map();
853
+ return new ReadableStream({
820
854
  async start(controller) {
821
855
  resetRenderState();
856
+ const prev = swapContextMap(contextMap);
822
857
  const writer = {
823
858
  lastWasText: false,
824
859
  write(chunk) {
@@ -832,19 +867,27 @@ function renderToStream(element) {
832
867
  };
833
868
  try {
834
869
  const r = renderNode(element, writer);
835
- if (r && typeof r.then === "function")
870
+ if (r && typeof r.then === "function") {
871
+ const m = captureMap();
836
872
  await r;
873
+ swapContextMap(m);
874
+ }
837
875
  controller.close();
838
876
  } catch (error) {
839
877
  controller.error(error);
878
+ } finally {
879
+ swapContextMap(prev);
840
880
  }
841
881
  }
842
- }));
882
+ });
843
883
  }
844
- function renderToString(element) {
845
- return runWithContextStore(async () => {
884
+ async function renderToString(element) {
885
+ const contextMap = /* @__PURE__ */ new Map();
886
+ const prev = swapContextMap(contextMap);
887
+ try {
846
888
  for (let attempt = 0; attempt < MAX_SUSPENSE_RETRIES; attempt++) {
847
889
  resetRenderState();
890
+ swapContextMap(contextMap);
848
891
  const chunks = [];
849
892
  const writer = {
850
893
  lastWasText: false,
@@ -859,19 +902,26 @@ function renderToString(element) {
859
902
  };
860
903
  try {
861
904
  const r = renderNode(element, writer);
862
- if (r && typeof r.then === "function")
905
+ if (r && typeof r.then === "function") {
906
+ const m = captureMap();
863
907
  await r;
908
+ swapContextMap(m);
909
+ }
864
910
  return chunks.join("");
865
911
  } catch (error) {
866
912
  if (error && typeof error.then === "function") {
913
+ const m = captureMap();
867
914
  await error;
915
+ swapContextMap(m);
868
916
  continue;
869
917
  }
870
918
  throw error;
871
919
  }
872
920
  }
873
921
  throw new Error("[slim-react] renderToString exceeded maximum retries");
874
- });
922
+ } finally {
923
+ swapContextMap(prev);
924
+ }
875
925
  }
876
926
 
877
927
  // src/slim-react/index.ts
@@ -7,44 +7,36 @@ import {
7
7
  createElement,
8
8
  jsx
9
9
  } from "../chunk-OS3V4CPN.js";
10
- import {
11
- __require
12
- } from "../chunk-EZUCZHGV.js";
13
10
 
14
11
  // src/slim-react/renderContext.ts
15
- var CONTEXT_STORE_KEY = "__slimReactContextStore";
12
+ var MAP_KEY = "__slimReactContextMap";
16
13
  var _g = globalThis;
17
- if (!_g[CONTEXT_STORE_KEY]) {
18
- try {
19
- const { AsyncLocalStorage } = __require("node:async_hooks");
20
- _g[CONTEXT_STORE_KEY] = new AsyncLocalStorage();
21
- } catch {
22
- _g[CONTEXT_STORE_KEY] = null;
23
- }
14
+ if (!("__slimReactContextMap" in _g))
15
+ _g[MAP_KEY] = null;
16
+ function swapContextMap(map) {
17
+ const prev = _g[MAP_KEY];
18
+ _g[MAP_KEY] = map;
19
+ return prev;
24
20
  }
25
- var _contextStore = _g[CONTEXT_STORE_KEY];
26
- function runWithContextStore(fn) {
27
- return _contextStore ? _contextStore.run(/* @__PURE__ */ new Map(), fn) : fn();
21
+ function captureMap() {
22
+ return _g[MAP_KEY];
28
23
  }
29
24
  function getContextValue(context) {
30
- const store = _contextStore?.getStore();
31
- if (store && store.has(context))
32
- return store.get(context);
25
+ const map = _g[MAP_KEY];
26
+ if (map && map.has(context))
27
+ return map.get(context);
33
28
  const c = context;
34
29
  return "_defaultValue" in c ? c._defaultValue : c._currentValue;
35
30
  }
36
31
  function pushContextValue(context, value) {
37
- const store = _contextStore?.getStore();
32
+ const map = _g[MAP_KEY];
38
33
  const c = context;
39
- const prev = store && store.has(context) ? store.get(context) : "_defaultValue" in c ? c._defaultValue : c._currentValue;
40
- if (store)
41
- store.set(context, value);
34
+ const prev = map && map.has(context) ? map.get(context) : "_defaultValue" in c ? c._defaultValue : c._currentValue;
35
+ map?.set(context, value);
42
36
  return prev;
43
37
  }
44
38
  function popContextValue(context, prev) {
45
- const store = _contextStore?.getStore();
46
- if (store)
47
- store.set(context, prev);
39
+ _g[MAP_KEY]?.set(context, prev);
48
40
  }
49
41
  var GLOBAL_KEY = "__slimReactRenderState";
50
42
  var EMPTY = { id: 0, overflow: "", bits: 0 };
@@ -590,10 +582,18 @@ function renderComponent(type, props, writer, isSvg) {
590
582
  };
591
583
  const r2 = renderChildren(props.children, writer, isSvg);
592
584
  if (r2 && typeof r2.then === "function") {
593
- return r2.then(finish2, (e) => {
594
- finish2();
595
- throw e;
596
- });
585
+ const m = captureMap();
586
+ return r2.then(
587
+ () => {
588
+ swapContextMap(m);
589
+ finish2();
590
+ },
591
+ (e) => {
592
+ swapContextMap(m);
593
+ finish2();
594
+ throw e;
595
+ }
596
+ );
597
597
  }
598
598
  finish2();
599
599
  return;
@@ -623,26 +623,45 @@ function renderComponent(type, props, writer, isSvg) {
623
623
  popContextValue(ctx, prevCtxValue);
624
624
  };
625
625
  if (result instanceof Promise) {
626
+ const m = captureMap();
626
627
  return result.then((resolved) => {
628
+ swapContextMap(m);
627
629
  const r2 = renderNode(resolved, writer, isSvg);
628
630
  if (r2 && typeof r2.then === "function") {
629
- return r2.then(finish, (e) => {
630
- finish();
631
- throw e;
632
- });
631
+ const m2 = captureMap();
632
+ return r2.then(
633
+ () => {
634
+ swapContextMap(m2);
635
+ finish();
636
+ },
637
+ (e) => {
638
+ swapContextMap(m2);
639
+ finish();
640
+ throw e;
641
+ }
642
+ );
633
643
  }
634
644
  finish();
635
645
  }, (e) => {
646
+ swapContextMap(m);
636
647
  finish();
637
648
  throw e;
638
649
  });
639
650
  }
640
651
  const r = renderNode(result, writer, isSvg);
641
652
  if (r && typeof r.then === "function") {
642
- return r.then(finish, (e) => {
643
- finish();
644
- throw e;
645
- });
653
+ const m = captureMap();
654
+ return r.then(
655
+ () => {
656
+ swapContextMap(m);
657
+ finish();
658
+ },
659
+ (e) => {
660
+ swapContextMap(m);
661
+ finish();
662
+ throw e;
663
+ }
664
+ );
646
665
  }
647
666
  finish();
648
667
  }
@@ -658,7 +677,9 @@ function renderChildArray(children, writer, isSvg) {
658
677
  const savedTree = pushTreeContext(totalChildren, i);
659
678
  const r = renderNode(children[i], writer, isSvg);
660
679
  if (r && typeof r.then === "function") {
680
+ const m = captureMap();
661
681
  return r.then(() => {
682
+ swapContextMap(m);
662
683
  popTreeContext(savedTree);
663
684
  return renderChildArrayFrom(children, i + 1, writer, isSvg);
664
685
  });
@@ -675,7 +696,9 @@ function renderChildArrayFrom(children, startIndex, writer, isSvg) {
675
696
  const savedTree = pushTreeContext(totalChildren, i);
676
697
  const r = renderNode(children[i], writer, isSvg);
677
698
  if (r && typeof r.then === "function") {
699
+ const m = captureMap();
678
700
  return r.then(() => {
701
+ swapContextMap(m);
679
702
  popTreeContext(savedTree);
680
703
  return renderChildArrayFrom(children, i + 1, writer, isSvg);
681
704
  });
@@ -702,7 +725,9 @@ async function renderSuspense(props, writer, isSvg = false) {
702
725
  const buffer = new BufferWriter();
703
726
  const r = renderNode(children, buffer, isSvg);
704
727
  if (r && typeof r.then === "function") {
728
+ const m = captureMap();
705
729
  await r;
730
+ swapContextMap(m);
706
731
  }
707
732
  writer.write("<!--$-->");
708
733
  buffer.flush(writer);
@@ -710,7 +735,9 @@ async function renderSuspense(props, writer, isSvg = false) {
710
735
  return;
711
736
  } catch (error) {
712
737
  if (error && typeof error.then === "function") {
738
+ const m = captureMap();
713
739
  await error;
740
+ swapContextMap(m);
714
741
  attempts++;
715
742
  } else {
716
743
  throw error;
@@ -721,16 +748,21 @@ async function renderSuspense(props, writer, isSvg = false) {
721
748
  writer.write("<!--$?-->");
722
749
  if (fallback) {
723
750
  const r = renderNode(fallback, writer, isSvg);
724
- if (r && typeof r.then === "function")
751
+ if (r && typeof r.then === "function") {
752
+ const m = captureMap();
725
753
  await r;
754
+ swapContextMap(m);
755
+ }
726
756
  }
727
757
  writer.write("<!--/$-->");
728
758
  }
729
759
  function renderToStream(element) {
730
760
  const encoder = new TextEncoder();
731
- return runWithContextStore(() => new ReadableStream({
761
+ const contextMap = /* @__PURE__ */ new Map();
762
+ return new ReadableStream({
732
763
  async start(controller) {
733
764
  resetRenderState();
765
+ const prev = swapContextMap(contextMap);
734
766
  const writer = {
735
767
  lastWasText: false,
736
768
  write(chunk) {
@@ -744,19 +776,27 @@ function renderToStream(element) {
744
776
  };
745
777
  try {
746
778
  const r = renderNode(element, writer);
747
- if (r && typeof r.then === "function")
779
+ if (r && typeof r.then === "function") {
780
+ const m = captureMap();
748
781
  await r;
782
+ swapContextMap(m);
783
+ }
749
784
  controller.close();
750
785
  } catch (error) {
751
786
  controller.error(error);
787
+ } finally {
788
+ swapContextMap(prev);
752
789
  }
753
790
  }
754
- }));
791
+ });
755
792
  }
756
- function renderToString(element) {
757
- return runWithContextStore(async () => {
793
+ async function renderToString(element) {
794
+ const contextMap = /* @__PURE__ */ new Map();
795
+ const prev = swapContextMap(contextMap);
796
+ try {
758
797
  for (let attempt = 0; attempt < MAX_SUSPENSE_RETRIES; attempt++) {
759
798
  resetRenderState();
799
+ swapContextMap(contextMap);
760
800
  const chunks = [];
761
801
  const writer = {
762
802
  lastWasText: false,
@@ -771,19 +811,26 @@ function renderToString(element) {
771
811
  };
772
812
  try {
773
813
  const r = renderNode(element, writer);
774
- if (r && typeof r.then === "function")
814
+ if (r && typeof r.then === "function") {
815
+ const m = captureMap();
775
816
  await r;
817
+ swapContextMap(m);
818
+ }
776
819
  return chunks.join("");
777
820
  } catch (error) {
778
821
  if (error && typeof error.then === "function") {
822
+ const m = captureMap();
779
823
  await error;
824
+ swapContextMap(m);
780
825
  continue;
781
826
  }
782
827
  throw error;
783
828
  }
784
829
  }
785
830
  throw new Error("[slim-react] renderToString exceeded maximum retries");
786
- });
831
+ } finally {
832
+ swapContextMap(prev);
833
+ }
787
834
  }
788
835
 
789
836
  // src/slim-react/index.ts
@@ -2,7 +2,6 @@ import {
2
2
  Fragment,
3
3
  jsx
4
4
  } from "../chunk-OS3V4CPN.js";
5
- import "../chunk-EZUCZHGV.js";
6
5
  export {
7
6
  Fragment,
8
7
  jsx,
@@ -1,11 +1,3 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined")
5
- return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
-
9
1
  // src/ssr-render-worker.ts
10
2
  import { workerData, parentPort } from "node:worker_threads";
11
3
  import { pathToFileURL } from "node:url";
@@ -75,39 +67,34 @@ function createElement(type, props, ...children) {
75
67
  }
76
68
 
77
69
  // src/slim-react/renderContext.ts
78
- var CONTEXT_STORE_KEY = "__slimReactContextStore";
70
+ var MAP_KEY = "__slimReactContextMap";
79
71
  var _g = globalThis;
80
- if (!_g[CONTEXT_STORE_KEY]) {
81
- try {
82
- const { AsyncLocalStorage } = __require("node:async_hooks");
83
- _g[CONTEXT_STORE_KEY] = new AsyncLocalStorage();
84
- } catch {
85
- _g[CONTEXT_STORE_KEY] = null;
86
- }
72
+ if (!("__slimReactContextMap" in _g))
73
+ _g[MAP_KEY] = null;
74
+ function swapContextMap(map) {
75
+ const prev = _g[MAP_KEY];
76
+ _g[MAP_KEY] = map;
77
+ return prev;
87
78
  }
88
- var _contextStore = _g[CONTEXT_STORE_KEY];
89
- function runWithContextStore(fn) {
90
- return _contextStore ? _contextStore.run(/* @__PURE__ */ new Map(), fn) : fn();
79
+ function captureMap() {
80
+ return _g[MAP_KEY];
91
81
  }
92
82
  function getContextValue(context) {
93
- const store = _contextStore?.getStore();
94
- if (store && store.has(context))
95
- return store.get(context);
83
+ const map = _g[MAP_KEY];
84
+ if (map && map.has(context))
85
+ return map.get(context);
96
86
  const c = context;
97
87
  return "_defaultValue" in c ? c._defaultValue : c._currentValue;
98
88
  }
99
89
  function pushContextValue(context, value) {
100
- const store = _contextStore?.getStore();
90
+ const map = _g[MAP_KEY];
101
91
  const c = context;
102
- const prev = store && store.has(context) ? store.get(context) : "_defaultValue" in c ? c._defaultValue : c._currentValue;
103
- if (store)
104
- store.set(context, value);
92
+ const prev = map && map.has(context) ? map.get(context) : "_defaultValue" in c ? c._defaultValue : c._currentValue;
93
+ map?.set(context, value);
105
94
  return prev;
106
95
  }
107
96
  function popContextValue(context, prev) {
108
- const store = _contextStore?.getStore();
109
- if (store)
110
- store.set(context, prev);
97
+ _g[MAP_KEY]?.set(context, prev);
111
98
  }
112
99
  var GLOBAL_KEY = "__slimReactRenderState";
113
100
  var EMPTY = { id: 0, overflow: "", bits: 0 };
@@ -547,10 +534,18 @@ function renderComponent(type, props, writer, isSvg) {
547
534
  };
548
535
  const r2 = renderChildren(props.children, writer, isSvg);
549
536
  if (r2 && typeof r2.then === "function") {
550
- return r2.then(finish2, (e) => {
551
- finish2();
552
- throw e;
553
- });
537
+ const m = captureMap();
538
+ return r2.then(
539
+ () => {
540
+ swapContextMap(m);
541
+ finish2();
542
+ },
543
+ (e) => {
544
+ swapContextMap(m);
545
+ finish2();
546
+ throw e;
547
+ }
548
+ );
554
549
  }
555
550
  finish2();
556
551
  return;
@@ -580,26 +575,45 @@ function renderComponent(type, props, writer, isSvg) {
580
575
  popContextValue(ctx, prevCtxValue);
581
576
  };
582
577
  if (result instanceof Promise) {
578
+ const m = captureMap();
583
579
  return result.then((resolved) => {
580
+ swapContextMap(m);
584
581
  const r2 = renderNode(resolved, writer, isSvg);
585
582
  if (r2 && typeof r2.then === "function") {
586
- return r2.then(finish, (e) => {
587
- finish();
588
- throw e;
589
- });
583
+ const m2 = captureMap();
584
+ return r2.then(
585
+ () => {
586
+ swapContextMap(m2);
587
+ finish();
588
+ },
589
+ (e) => {
590
+ swapContextMap(m2);
591
+ finish();
592
+ throw e;
593
+ }
594
+ );
590
595
  }
591
596
  finish();
592
597
  }, (e) => {
598
+ swapContextMap(m);
593
599
  finish();
594
600
  throw e;
595
601
  });
596
602
  }
597
603
  const r = renderNode(result, writer, isSvg);
598
604
  if (r && typeof r.then === "function") {
599
- return r.then(finish, (e) => {
600
- finish();
601
- throw e;
602
- });
605
+ const m = captureMap();
606
+ return r.then(
607
+ () => {
608
+ swapContextMap(m);
609
+ finish();
610
+ },
611
+ (e) => {
612
+ swapContextMap(m);
613
+ finish();
614
+ throw e;
615
+ }
616
+ );
603
617
  }
604
618
  finish();
605
619
  }
@@ -615,7 +629,9 @@ function renderChildArray(children, writer, isSvg) {
615
629
  const savedTree = pushTreeContext(totalChildren, i);
616
630
  const r = renderNode(children[i], writer, isSvg);
617
631
  if (r && typeof r.then === "function") {
632
+ const m = captureMap();
618
633
  return r.then(() => {
634
+ swapContextMap(m);
619
635
  popTreeContext(savedTree);
620
636
  return renderChildArrayFrom(children, i + 1, writer, isSvg);
621
637
  });
@@ -632,7 +648,9 @@ function renderChildArrayFrom(children, startIndex, writer, isSvg) {
632
648
  const savedTree = pushTreeContext(totalChildren, i);
633
649
  const r = renderNode(children[i], writer, isSvg);
634
650
  if (r && typeof r.then === "function") {
651
+ const m = captureMap();
635
652
  return r.then(() => {
653
+ swapContextMap(m);
636
654
  popTreeContext(savedTree);
637
655
  return renderChildArrayFrom(children, i + 1, writer, isSvg);
638
656
  });
@@ -659,7 +677,9 @@ async function renderSuspense(props, writer, isSvg = false) {
659
677
  const buffer = new BufferWriter();
660
678
  const r = renderNode(children, buffer, isSvg);
661
679
  if (r && typeof r.then === "function") {
680
+ const m = captureMap();
662
681
  await r;
682
+ swapContextMap(m);
663
683
  }
664
684
  writer.write("<!--$-->");
665
685
  buffer.flush(writer);
@@ -667,7 +687,9 @@ async function renderSuspense(props, writer, isSvg = false) {
667
687
  return;
668
688
  } catch (error) {
669
689
  if (error && typeof error.then === "function") {
690
+ const m = captureMap();
670
691
  await error;
692
+ swapContextMap(m);
671
693
  attempts++;
672
694
  } else {
673
695
  throw error;
@@ -678,15 +700,21 @@ async function renderSuspense(props, writer, isSvg = false) {
678
700
  writer.write("<!--$?-->");
679
701
  if (fallback) {
680
702
  const r = renderNode(fallback, writer, isSvg);
681
- if (r && typeof r.then === "function")
703
+ if (r && typeof r.then === "function") {
704
+ const m = captureMap();
682
705
  await r;
706
+ swapContextMap(m);
707
+ }
683
708
  }
684
709
  writer.write("<!--/$-->");
685
710
  }
686
- function renderToString(element) {
687
- return runWithContextStore(async () => {
711
+ async function renderToString(element) {
712
+ const contextMap = /* @__PURE__ */ new Map();
713
+ const prev = swapContextMap(contextMap);
714
+ try {
688
715
  for (let attempt = 0; attempt < MAX_SUSPENSE_RETRIES; attempt++) {
689
716
  resetRenderState();
717
+ swapContextMap(contextMap);
690
718
  const chunks = [];
691
719
  const writer = {
692
720
  lastWasText: false,
@@ -701,19 +729,26 @@ function renderToString(element) {
701
729
  };
702
730
  try {
703
731
  const r = renderNode(element, writer);
704
- if (r && typeof r.then === "function")
732
+ if (r && typeof r.then === "function") {
733
+ const m = captureMap();
705
734
  await r;
735
+ swapContextMap(m);
736
+ }
706
737
  return chunks.join("");
707
738
  } catch (error) {
708
739
  if (error && typeof error.then === "function") {
740
+ const m = captureMap();
709
741
  await error;
742
+ swapContextMap(m);
710
743
  continue;
711
744
  }
712
745
  throw error;
713
746
  }
714
747
  }
715
748
  throw new Error("[slim-react] renderToString exceeded maximum retries");
716
- });
749
+ } finally {
750
+ swapContextMap(prev);
751
+ }
717
752
  }
718
753
 
719
754
  // src/ssr-render-worker.ts
package/dist/ssr-watch.js CHANGED
@@ -180,10 +180,6 @@ var buildCompilerConfig = (entry2, opts, includeHotPlugin) => {
180
180
  } : void 0;
181
181
  const externals = isServerBuild ? [
182
182
  // Node.js built-ins — must not be bundled; resolved by the runtime.
183
- // Both the bare name and the node: prefix are listed because rspack
184
- // may encounter either form depending on how the import is written.
185
- "node:async_hooks",
186
- "async_hooks",
187
183
  "node:fs",
188
184
  "node:path",
189
185
  "node:os",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hadars",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "description": "Minimal SSR framework for React — rspack, HMR, TypeScript, Bun/Node/Deno",
5
5
  "module": "./dist/index.js",
6
6
  "type": "module",
@@ -33,7 +33,8 @@ import {
33
33
  pushContextValue,
34
34
  popContextValue,
35
35
  getContextValue,
36
- runWithContextStore,
36
+ swapContextMap,
37
+ captureMap,
37
38
  } from "./renderContext";
38
39
 
39
40
  // ---------------------------------------------------------------------------
@@ -613,7 +614,11 @@ function renderComponent(
613
614
  };
614
615
  const r = renderChildren(props.children, writer, isSvg);
615
616
  if (r && typeof (r as any).then === "function") {
616
- return (r as Promise<void>).then(finish, (e) => { finish(); throw e; });
617
+ const m = captureMap();
618
+ return (r as Promise<void>).then(
619
+ () => { swapContextMap(m); finish(); },
620
+ (e) => { swapContextMap(m); finish(); throw e; },
621
+ );
617
622
  }
618
623
  finish();
619
624
  return;
@@ -645,19 +650,29 @@ function renderComponent(
645
650
 
646
651
  // Async component
647
652
  if (result instanceof Promise) {
653
+ const m = captureMap();
648
654
  return result.then((resolved) => {
655
+ swapContextMap(m);
649
656
  const r = renderNode(resolved, writer, isSvg);
650
657
  if (r && typeof (r as any).then === "function") {
651
- return (r as Promise<void>).then(finish, (e) => { finish(); throw e; });
658
+ const m2 = captureMap();
659
+ return (r as Promise<void>).then(
660
+ () => { swapContextMap(m2); finish(); },
661
+ (e) => { swapContextMap(m2); finish(); throw e; },
662
+ );
652
663
  }
653
664
  finish();
654
- }, (e) => { finish(); throw e; });
665
+ }, (e) => { swapContextMap(m); finish(); throw e; });
655
666
  }
656
667
 
657
668
  const r = renderNode(result, writer, isSvg);
658
669
 
659
670
  if (r && typeof (r as any).then === "function") {
660
- return (r as Promise<void>).then(finish, (e) => { finish(); throw e; });
671
+ const m = captureMap();
672
+ return (r as Promise<void>).then(
673
+ () => { swapContextMap(m); finish(); },
674
+ (e) => { swapContextMap(m); finish(); throw e; },
675
+ );
661
676
  }
662
677
  finish();
663
678
  }
@@ -691,7 +706,9 @@ function renderChildArray(
691
706
  const r = renderNode(children[i], writer, isSvg);
692
707
  if (r && typeof (r as any).then === "function") {
693
708
  // One child went async – continue the rest asynchronously
709
+ const m = captureMap();
694
710
  return (r as Promise<void>).then(() => {
711
+ swapContextMap(m);
695
712
  popTreeContext(savedTree);
696
713
  // Continue with remaining children
697
714
  return renderChildArrayFrom(children, i + 1, writer, isSvg);
@@ -716,7 +733,9 @@ function renderChildArrayFrom(
716
733
  const savedTree = pushTreeContext(totalChildren, i);
717
734
  const r = renderNode(children[i], writer, isSvg);
718
735
  if (r && typeof (r as any).then === "function") {
736
+ const m = captureMap();
719
737
  return (r as Promise<void>).then(() => {
738
+ swapContextMap(m);
720
739
  popTreeContext(savedTree);
721
740
  return renderChildArrayFrom(children, i + 1, writer, isSvg);
722
741
  });
@@ -765,7 +784,7 @@ async function renderSuspense(
765
784
  const buffer = new BufferWriter();
766
785
  const r = renderNode(children, buffer, isSvg);
767
786
  if (r && typeof (r as any).then === "function") {
768
- await r;
787
+ const m = captureMap(); await r; swapContextMap(m);
769
788
  }
770
789
  // Success – wrap with React's Suspense boundary markers so hydrateRoot
771
790
  // can locate the boundary in the DOM (<!--$--> … <!--/$-->).
@@ -775,7 +794,7 @@ async function renderSuspense(
775
794
  return;
776
795
  } catch (error: unknown) {
777
796
  if (error && typeof (error as any).then === "function") {
778
- await (error as Promise<unknown>);
797
+ const m = captureMap(); await (error as Promise<unknown>); swapContextMap(m);
779
798
  attempts++;
780
799
  } else {
781
800
  throw error;
@@ -788,7 +807,9 @@ async function renderSuspense(
788
807
  writer.write("<!--$?-->");
789
808
  if (fallback) {
790
809
  const r = renderNode(fallback, writer, isSvg);
791
- if (r && typeof (r as any).then === "function") await r;
810
+ if (r && typeof (r as any).then === "function") {
811
+ const m = captureMap(); await r; swapContextMap(m);
812
+ }
792
813
  }
793
814
  writer.write("<!--/$-->");
794
815
  }
@@ -806,9 +827,11 @@ async function renderSuspense(
806
827
  export function renderToStream(element: SlimNode): ReadableStream<Uint8Array> {
807
828
  const encoder = new TextEncoder();
808
829
 
809
- return runWithContextStore(() => new ReadableStream({
830
+ const contextMap = new Map<object, unknown>();
831
+ return new ReadableStream({
810
832
  async start(controller) {
811
833
  resetRenderState();
834
+ const prev = swapContextMap(contextMap);
812
835
 
813
836
  const writer: Writer = {
814
837
  lastWasText: false,
@@ -824,13 +847,17 @@ export function renderToStream(element: SlimNode): ReadableStream<Uint8Array> {
824
847
 
825
848
  try {
826
849
  const r = renderNode(element, writer);
827
- if (r && typeof (r as any).then === "function") await r;
850
+ if (r && typeof (r as any).then === "function") {
851
+ const m = captureMap(); await r; swapContextMap(m);
852
+ }
828
853
  controller.close();
829
854
  } catch (error) {
830
855
  controller.error(error);
856
+ } finally {
857
+ swapContextMap(prev);
831
858
  }
832
859
  },
833
- }));
860
+ });
834
861
  }
835
862
 
836
863
  /**
@@ -838,10 +865,13 @@ export function renderToStream(element: SlimNode): ReadableStream<Uint8Array> {
838
865
  * Retries the full tree when a component throws a Promise (Suspense protocol),
839
866
  * so useServerData and similar hooks work without requiring explicit <Suspense>.
840
867
  */
841
- export function renderToString(element: SlimNode): Promise<string> {
842
- return runWithContextStore(async () => {
868
+ export async function renderToString(element: SlimNode): Promise<string> {
869
+ const contextMap = new Map<object, unknown>();
870
+ const prev = swapContextMap(contextMap);
871
+ try {
843
872
  for (let attempt = 0; attempt < MAX_SUSPENSE_RETRIES; attempt++) {
844
873
  resetRenderState();
874
+ swapContextMap(contextMap); // re-activate our map on each retry
845
875
  const chunks: string[] = [];
846
876
  const writer: Writer = {
847
877
  lastWasText: false,
@@ -850,18 +880,22 @@ export function renderToString(element: SlimNode): Promise<string> {
850
880
  };
851
881
  try {
852
882
  const r = renderNode(element, writer);
853
- if (r && typeof (r as any).then === "function") await r;
883
+ if (r && typeof (r as any).then === "function") {
884
+ const m = captureMap(); await r; swapContextMap(m);
885
+ }
854
886
  return chunks.join("");
855
887
  } catch (error) {
856
888
  if (error && typeof (error as any).then === "function") {
857
- await (error as Promise<unknown>);
889
+ const m = captureMap(); await (error as Promise<unknown>); swapContextMap(m);
858
890
  continue;
859
891
  }
860
892
  throw error;
861
893
  }
862
894
  }
863
895
  throw new Error("[slim-react] renderToString exceeded maximum retries");
864
- });
896
+ } finally {
897
+ swapContextMap(prev);
898
+ }
865
899
  }
866
900
 
867
901
  /** Alias matching React 18+ server API naming. */
@@ -5,66 +5,62 @@
5
5
  * multiple slim-react instances (the render worker's direct import and the
6
6
  * SSR bundle's bundled copy) share the same singletons without coordination.
7
7
  *
8
- * Context values are stored in an AsyncLocalStorage<Map> so each concurrent
9
- * SSR request gets its own isolated scope that propagates through all awaits.
10
- * Call `runWithContextStore` at the start of every render to establish the scope.
8
+ * Context values are stored in a plain Map that is created per render call.
9
+ * Node.js is single-threaded: only one render is executing between any two
10
+ * await points. The renderer captures the map reference before every await
11
+ * and restores it in the continuation, so concurrent renders stay isolated
12
+ * without any external dependencies.
11
13
  */
12
14
 
13
- // Shared AsyncLocalStorage instance kept on globalThis so both copies of
14
- // slim-react (direct import + SSR bundle) use the same store.
15
- // The import is done with require() inside a try/catch so that bundlers that
16
- // cannot resolve node:async_hooks (e.g. rspack without target:node set) do
17
- // not fail at build time — the SSR render process always runs in Node.js and
18
- // will find the module at runtime regardless.
19
- const CONTEXT_STORE_KEY = "__slimReactContextStore";
15
+ // The context map for the render that is currently executing (between awaits).
16
+ // Kept on globalThis so both slim-react instances share the same slot.
17
+ const MAP_KEY = "__slimReactContextMap";
20
18
  const _g = globalThis as any;
21
- if (!_g[CONTEXT_STORE_KEY]) {
22
- try {
23
- // eslint-disable-next-line @typescript-eslint/no-require-imports
24
- const { AsyncLocalStorage } = require("node:async_hooks") as typeof import("node:async_hooks");
25
- _g[CONTEXT_STORE_KEY] = new AsyncLocalStorage<Map<object, unknown>>();
26
- } catch {
27
- // Fallback: no-op store — context values fall back to _defaultValue.
28
- // This should never happen in a real SSR environment.
29
- _g[CONTEXT_STORE_KEY] = null;
30
- }
19
+ if (!("__slimReactContextMap" in _g)) _g[MAP_KEY] = null;
20
+
21
+ /**
22
+ * Swap in a new context map and return the previous one.
23
+ * Called at render entry-points and at every await/then continuation to
24
+ * restore the correct map for the resuming render.
25
+ */
26
+ export function swapContextMap(
27
+ map: Map<object, unknown> | null,
28
+ ): Map<object, unknown> | null {
29
+ const prev: Map<object, unknown> | null = _g[MAP_KEY];
30
+ _g[MAP_KEY] = map;
31
+ return prev;
31
32
  }
32
- const _contextStore: { run<T>(store: Map<object,unknown>, fn: () => T): T; getStore(): Map<object,unknown> | undefined } | null = _g[CONTEXT_STORE_KEY];
33
33
 
34
- /** Wrap a render entry-point so it gets its own isolated context-value scope. */
35
- export function runWithContextStore<T>(fn: () => T): T {
36
- return _contextStore ? _contextStore.run(new Map(), fn) : fn();
34
+ /** Return the active map without changing it (used to capture before an await). */
35
+ export function captureMap(): Map<object, unknown> | null {
36
+ return _g[MAP_KEY];
37
37
  }
38
38
 
39
- /**
40
- * Read the current value for a context within the active render.
41
- * Falls back to `_defaultValue` (or `_currentValue` for external contexts).
42
- */
39
+ /** Read the current value for a context within the active render. */
43
40
  export function getContextValue<T>(context: object): T {
44
- const store = _contextStore?.getStore();
45
- if (store && store.has(context)) return store.get(context) as T;
41
+ const map: Map<object, unknown> | null = _g[MAP_KEY];
42
+ if (map && map.has(context)) return map.get(context) as T;
46
43
  const c = context as any;
47
44
  return ("_defaultValue" in c ? c._defaultValue : c._currentValue) as T;
48
45
  }
49
46
 
50
47
  /**
51
- * Push a new value for a context Provider onto the per-request store.
52
- * Returns the previous value so the caller can restore it later.
48
+ * Push a new Provider value into the active map.
49
+ * Returns the previous value so the caller can restore it on exit.
53
50
  */
54
51
  export function pushContextValue(context: object, value: unknown): unknown {
55
- const store = _contextStore?.getStore();
52
+ const map: Map<object, unknown> | null = _g[MAP_KEY];
56
53
  const c = context as any;
57
- const prev = store && store.has(context)
58
- ? store.get(context)
54
+ const prev = map && map.has(context)
55
+ ? map.get(context)
59
56
  : ("_defaultValue" in c ? c._defaultValue : c._currentValue);
60
- if (store) store.set(context, value);
57
+ map?.set(context, value);
61
58
  return prev;
62
59
  }
63
60
 
64
61
  /** Restore a previously saved context value (called by Provider on exit). */
65
62
  export function popContextValue(context: object, prev: unknown): void {
66
- const store = _contextStore?.getStore();
67
- if (store) store.set(context, prev);
63
+ (_g[MAP_KEY] as Map<object, unknown> | null)?.set(context, prev);
68
64
  }
69
65
 
70
66
  export interface TreeContext {
@@ -227,9 +227,6 @@ const buildCompilerConfig = (
227
227
 
228
228
  const externals = isServerBuild ? [
229
229
  // Node.js built-ins — must not be bundled; resolved by the runtime.
230
- // Both the bare name and the node: prefix are listed because rspack
231
- // may encounter either form depending on how the import is written.
232
- 'node:async_hooks', 'async_hooks',
233
230
  'node:fs', 'node:path', 'node:os', 'node:stream', 'node:util',
234
231
  // react / react-dom are replaced by slim-react via alias above — not external.
235
232
  // emotion should be external on server builds to avoid client/browser code
@@ -1,11 +0,0 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined")
5
- return require.apply(this, arguments);
6
- throw new Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
-
9
- export {
10
- __require
11
- };