hadars 0.1.24 → 0.1.26
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 +93 -62
- package/dist/index.js +0 -2
- package/dist/slim-react/index.cjs +91 -41
- package/dist/slim-react/index.js +91 -44
- package/dist/slim-react/jsx-runtime.js +0 -1
- package/dist/ssr-render-worker.js +81 -46
- package/dist/ssr-watch.js +12 -17
- package/package.json +1 -1
- package/src/slim-react/render.ts +50 -16
- package/src/slim-react/renderContext.ts +34 -38
- package/src/utils/rspack.ts +9 -13
- package/dist/chunk-EZUCZHGV.js +0 -11
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
|
|
163
|
+
var MAP_KEY = "__slimReactContextMap";
|
|
171
164
|
var _g = globalThis;
|
|
172
|
-
if (!_g
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|
|
181
|
-
|
|
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
|
|
186
|
-
if (
|
|
187
|
-
return
|
|
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
|
|
183
|
+
const map = _g[MAP_KEY];
|
|
193
184
|
const c = context;
|
|
194
|
-
const prev =
|
|
195
|
-
|
|
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
|
-
|
|
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
|
-
|
|
643
|
-
|
|
644
|
-
|
|
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
|
-
|
|
679
|
-
|
|
680
|
-
|
|
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
|
-
|
|
692
|
-
|
|
693
|
-
|
|
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
|
-
|
|
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
|
|
@@ -1085,30 +1121,22 @@ var buildCompilerConfig = (entry, opts, includeHotPlugin) => {
|
|
|
1085
1121
|
// Route all React imports to slim-react for SSR.
|
|
1086
1122
|
react: slimReactIndex,
|
|
1087
1123
|
"react/jsx-runtime": slimReactJsx,
|
|
1088
|
-
"react/jsx-dev-runtime": slimReactJsx
|
|
1089
|
-
//
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
"@emotion/styled": path.resolve(process.cwd(), "node_modules", "@emotion", "styled")
|
|
1124
|
+
"react/jsx-dev-runtime": slimReactJsx
|
|
1125
|
+
// @emotion/* is bundled (not external) so that its `react` imports are
|
|
1126
|
+
// resolved through the alias above to slim-react. If left external,
|
|
1127
|
+
// emotion loads real React from node_modules and calls
|
|
1128
|
+
// ReactSharedInternals.H.useContext which requires React's dispatcher.
|
|
1094
1129
|
} : void 0;
|
|
1095
1130
|
const externals = isServerBuild ? [
|
|
1096
1131
|
// 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
1132
|
"node:fs",
|
|
1102
1133
|
"node:path",
|
|
1103
1134
|
"node:os",
|
|
1104
1135
|
"node:stream",
|
|
1105
1136
|
"node:util",
|
|
1106
|
-
//
|
|
1107
|
-
//
|
|
1108
|
-
"@emotion/
|
|
1109
|
-
"@emotion/server",
|
|
1110
|
-
"@emotion/cache",
|
|
1111
|
-
"@emotion/styled"
|
|
1137
|
+
// @emotion/server is only used outside component rendering (CSS extraction)
|
|
1138
|
+
// and does not call React hooks, so it is safe to leave as external.
|
|
1139
|
+
"@emotion/server"
|
|
1112
1140
|
] : void 0;
|
|
1113
1141
|
const extraPlugins = [];
|
|
1114
1142
|
if (opts.define && typeof opts.define === "object") {
|
|
@@ -1123,7 +1151,10 @@ var buildCompilerConfig = (entry, opts, includeHotPlugin) => {
|
|
|
1123
1151
|
extensions: [".tsx", ".ts", ".js", ".jsx"],
|
|
1124
1152
|
alias: resolveAliases,
|
|
1125
1153
|
// for server builds prefer the package "main"/"module" fields and avoid "browser" so we don't pick browser-specific entrypoints
|
|
1126
|
-
mainFields: isServerBuild ? ["main", "module"] : ["browser", "module", "main"]
|
|
1154
|
+
mainFields: isServerBuild ? ["main", "module"] : ["browser", "module", "main"],
|
|
1155
|
+
// for server builds exclude the "browser" condition so packages with package.json
|
|
1156
|
+
// "exports" conditions (e.g. @emotion/*) resolve their Node/CJS entry, not the browser build
|
|
1157
|
+
...isServerBuild ? { conditionNames: ["node", "require", "default"] } : {}
|
|
1127
1158
|
};
|
|
1128
1159
|
const optimization = !isServerBuild && !isDev ? {
|
|
1129
1160
|
moduleIds: "deterministic",
|
package/dist/index.js
CHANGED
|
@@ -100,39 +100,34 @@ function createElement(type, props, ...children) {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
// src/slim-react/renderContext.ts
|
|
103
|
-
var
|
|
103
|
+
var MAP_KEY = "__slimReactContextMap";
|
|
104
104
|
var _g = globalThis;
|
|
105
|
-
if (!_g
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
114
|
-
|
|
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
|
|
119
|
-
if (
|
|
120
|
-
return
|
|
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
|
|
123
|
+
const map = _g[MAP_KEY];
|
|
126
124
|
const c = context;
|
|
127
|
-
const prev =
|
|
128
|
-
|
|
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
|
-
|
|
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
|
-
|
|
682
|
-
|
|
683
|
-
|
|
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
|
-
|
|
718
|
-
|
|
719
|
-
|
|
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
|
-
|
|
731
|
-
|
|
732
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|