hadars 0.3.1 → 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/README.md +2 -0
- package/dist/{chunk-2KJRDPCN.js → chunk-2J2L2H3H.js} +9 -9
- package/dist/{chunk-LY5MTHFV.js → chunk-TV37IMRB.js} +50 -51
- package/dist/cli.js +70 -67
- package/dist/cloudflare.cjs +56 -57
- package/dist/cloudflare.js +2 -2
- package/dist/lambda.cjs +58 -65
- package/dist/lambda.js +4 -10
- package/dist/slim-react/index.cjs +50 -51
- package/dist/slim-react/index.js +1 -1
- package/dist/ssr-render-worker.js +46 -47
- package/dist/ssr-watch.js +9 -6
- package/package.json +2 -2
- package/src/build.ts +9 -5
- package/src/lambda.ts +7 -14
- package/src/slim-react/render.ts +39 -25
- package/src/slim-react/renderContext.ts +34 -11
- package/src/utils/rspack.ts +9 -6
- package/src/utils/ssrHandler.ts +13 -8
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
A minimal server-side rendering framework for React built on [rspack](https://rspack.dev). Runs on Bun, Node.js, and Deno.
|
|
4
4
|
|
|
5
|
+
**[hadars.xyz](https://hadars.xyz)** — docs & website
|
|
6
|
+
|
|
5
7
|
## Why hadars?
|
|
6
8
|
|
|
7
9
|
hadars is an alternative to Next.js for apps that just need SSR.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
renderPreflight,
|
|
3
3
|
renderToString
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-TV37IMRB.js";
|
|
5
5
|
import {
|
|
6
6
|
createElement
|
|
7
7
|
} from "./chunk-OS3V4CPN.js";
|
|
@@ -230,18 +230,18 @@ var makePrecontentHtmlGetter = (htmlFilePromise) => {
|
|
|
230
230
|
let preHead = null;
|
|
231
231
|
let postHead = null;
|
|
232
232
|
let postContent = null;
|
|
233
|
+
const primed = htmlFilePromise.then((html) => {
|
|
234
|
+
const headEnd = html.indexOf(HEAD_MARKER);
|
|
235
|
+
const contentStart = html.indexOf(BODY_MARKER);
|
|
236
|
+
preHead = html.slice(0, headEnd);
|
|
237
|
+
postHead = html.slice(headEnd + HEAD_MARKER.length, contentStart);
|
|
238
|
+
postContent = html.slice(contentStart + BODY_MARKER.length);
|
|
239
|
+
});
|
|
233
240
|
return (headHtml) => {
|
|
234
241
|
if (preHead !== null) {
|
|
235
242
|
return [preHead + headHtml + postHead, postContent];
|
|
236
243
|
}
|
|
237
|
-
return
|
|
238
|
-
const headEnd = html.indexOf(HEAD_MARKER);
|
|
239
|
-
const contentStart = html.indexOf(BODY_MARKER);
|
|
240
|
-
preHead = html.slice(0, headEnd);
|
|
241
|
-
postHead = html.slice(headEnd + HEAD_MARKER.length, contentStart);
|
|
242
|
-
postContent = html.slice(contentStart + BODY_MARKER.length);
|
|
243
|
-
return [preHead + headHtml + postHead, postContent];
|
|
244
|
-
});
|
|
244
|
+
return primed.then(() => [preHead + headHtml + postHead, postContent]);
|
|
245
245
|
};
|
|
246
246
|
};
|
|
247
247
|
async function transformStream(data, stream) {
|
|
@@ -115,7 +115,16 @@ function componentCalledUseId() {
|
|
|
115
115
|
function snapshotContext() {
|
|
116
116
|
const st = s();
|
|
117
117
|
const ctx = st.currentTreeContext;
|
|
118
|
-
|
|
118
|
+
const depth = _treeDepth;
|
|
119
|
+
return {
|
|
120
|
+
tree: { id: ctx.id, overflow: ctx.overflow },
|
|
121
|
+
localId: st.localIdCounter,
|
|
122
|
+
treeDepth: depth,
|
|
123
|
+
// Snapshot the live stack so that popTreeContext reads correct saved values
|
|
124
|
+
// even if another concurrent render's resetRenderState stomped the arrays.
|
|
125
|
+
idStack: _treeIdStack.slice(0, depth),
|
|
126
|
+
ovStack: _treeOvStack.slice(0, depth)
|
|
127
|
+
};
|
|
119
128
|
}
|
|
120
129
|
function restoreContext(snap) {
|
|
121
130
|
const st = s();
|
|
@@ -124,6 +133,10 @@ function restoreContext(snap) {
|
|
|
124
133
|
ctx.overflow = snap.tree.overflow;
|
|
125
134
|
st.localIdCounter = snap.localId;
|
|
126
135
|
_treeDepth = snap.treeDepth;
|
|
136
|
+
for (let i = 0; i < snap.treeDepth; i++) {
|
|
137
|
+
_treeIdStack[i] = snap.idStack[i];
|
|
138
|
+
_treeOvStack[i] = snap.ovStack[i];
|
|
139
|
+
}
|
|
127
140
|
}
|
|
128
141
|
function getTreeId() {
|
|
129
142
|
const { id, overflow } = s().currentTreeContext;
|
|
@@ -269,6 +282,14 @@ function restoreDispatcher(prev) {
|
|
|
269
282
|
}
|
|
270
283
|
|
|
271
284
|
// src/slim-react/render.ts
|
|
285
|
+
function captureRenderCtx() {
|
|
286
|
+
return { m: captureMap(), u: captureUnsuspend(), t: snapshotContext() };
|
|
287
|
+
}
|
|
288
|
+
function restoreRenderCtx(ctx) {
|
|
289
|
+
swapContextMap(ctx.m);
|
|
290
|
+
restoreUnsuspend(ctx.u);
|
|
291
|
+
restoreContext(ctx.t);
|
|
292
|
+
}
|
|
272
293
|
var VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
273
294
|
"area",
|
|
274
295
|
"base",
|
|
@@ -712,11 +733,9 @@ function renderComponent(type, props, writer, isSvg, _suspenseRetries = 0) {
|
|
|
712
733
|
if (e && typeof e.then === "function") {
|
|
713
734
|
if (_suspenseRetries + 1 >= MAX_COMPONENT_SUSPENSE_RETRIES) throw SUSPENSE_RETRY_LIMIT;
|
|
714
735
|
patchPromiseStatus(e);
|
|
715
|
-
const
|
|
716
|
-
const u = captureUnsuspend();
|
|
736
|
+
const rctx = captureRenderCtx();
|
|
717
737
|
return e.then(() => {
|
|
718
|
-
|
|
719
|
-
restoreUnsuspend(u);
|
|
738
|
+
restoreRenderCtx(rctx);
|
|
720
739
|
return renderComponent(type, props, writer, isSvg, _suspenseRetries + 1);
|
|
721
740
|
});
|
|
722
741
|
}
|
|
@@ -753,17 +772,14 @@ function renderComponent(type, props, writer, isSvg, _suspenseRetries = 0) {
|
|
|
753
772
|
};
|
|
754
773
|
const r2 = renderChildren(props.children, writer, isSvg);
|
|
755
774
|
if (r2 && typeof r2.then === "function") {
|
|
756
|
-
const
|
|
757
|
-
const u = captureUnsuspend();
|
|
775
|
+
const rctx = captureRenderCtx();
|
|
758
776
|
return r2.then(
|
|
759
777
|
() => {
|
|
760
|
-
|
|
761
|
-
restoreUnsuspend(u);
|
|
778
|
+
restoreRenderCtx(rctx);
|
|
762
779
|
finish();
|
|
763
780
|
},
|
|
764
781
|
(e) => {
|
|
765
|
-
|
|
766
|
-
restoreUnsuspend(u);
|
|
782
|
+
restoreRenderCtx(rctx);
|
|
767
783
|
finish();
|
|
768
784
|
throw e;
|
|
769
785
|
}
|
|
@@ -792,11 +808,9 @@ function renderComponent(type, props, writer, isSvg, _suspenseRetries = 0) {
|
|
|
792
808
|
if (e && typeof e.then === "function") {
|
|
793
809
|
if (_suspenseRetries + 1 >= MAX_COMPONENT_SUSPENSE_RETRIES) throw SUSPENSE_RETRY_LIMIT;
|
|
794
810
|
patchPromiseStatus(e);
|
|
795
|
-
const
|
|
796
|
-
const u = captureUnsuspend();
|
|
811
|
+
const rctx = captureRenderCtx();
|
|
797
812
|
return e.then(() => {
|
|
798
|
-
|
|
799
|
-
restoreUnsuspend(u);
|
|
813
|
+
restoreRenderCtx(rctx);
|
|
800
814
|
return renderComponent(type, props, writer, isSvg, _suspenseRetries + 1);
|
|
801
815
|
});
|
|
802
816
|
}
|
|
@@ -808,30 +822,25 @@ function renderComponent(type, props, writer, isSvg, _suspenseRetries = 0) {
|
|
|
808
822
|
savedIdTree = pushTreeContext(1, 0);
|
|
809
823
|
}
|
|
810
824
|
if (result instanceof Promise) {
|
|
811
|
-
const
|
|
812
|
-
const u = captureUnsuspend();
|
|
825
|
+
const rctx = captureRenderCtx();
|
|
813
826
|
return result.then((resolved) => {
|
|
814
|
-
|
|
815
|
-
restoreUnsuspend(u);
|
|
827
|
+
restoreRenderCtx(rctx);
|
|
816
828
|
let asyncSavedIdTree;
|
|
817
829
|
if (componentCalledUseId()) {
|
|
818
830
|
asyncSavedIdTree = pushTreeContext(1, 0);
|
|
819
831
|
}
|
|
820
832
|
const r2 = renderNode(resolved, writer, isSvg);
|
|
821
833
|
if (r2 && typeof r2.then === "function") {
|
|
822
|
-
const
|
|
823
|
-
const u2 = captureUnsuspend();
|
|
834
|
+
const rctx2 = captureRenderCtx();
|
|
824
835
|
return r2.then(
|
|
825
836
|
() => {
|
|
826
|
-
|
|
827
|
-
restoreUnsuspend(u2);
|
|
837
|
+
restoreRenderCtx(rctx2);
|
|
828
838
|
if (asyncSavedIdTree !== void 0) popTreeContext(asyncSavedIdTree);
|
|
829
839
|
popComponentScope(savedScope);
|
|
830
840
|
if (isProvider) popContextValue(ctx, prevCtxValue);
|
|
831
841
|
},
|
|
832
842
|
(e) => {
|
|
833
|
-
|
|
834
|
-
restoreUnsuspend(u2);
|
|
843
|
+
restoreRenderCtx(rctx2);
|
|
835
844
|
if (asyncSavedIdTree !== void 0) popTreeContext(asyncSavedIdTree);
|
|
836
845
|
popComponentScope(savedScope);
|
|
837
846
|
if (isProvider) popContextValue(ctx, prevCtxValue);
|
|
@@ -843,8 +852,7 @@ function renderComponent(type, props, writer, isSvg, _suspenseRetries = 0) {
|
|
|
843
852
|
popComponentScope(savedScope);
|
|
844
853
|
if (isProvider) popContextValue(ctx, prevCtxValue);
|
|
845
854
|
}, (e) => {
|
|
846
|
-
|
|
847
|
-
restoreUnsuspend(u);
|
|
855
|
+
restoreRenderCtx(rctx);
|
|
848
856
|
popComponentScope(savedScope);
|
|
849
857
|
if (isProvider) popContextValue(ctx, prevCtxValue);
|
|
850
858
|
throw e;
|
|
@@ -852,19 +860,16 @@ function renderComponent(type, props, writer, isSvg, _suspenseRetries = 0) {
|
|
|
852
860
|
}
|
|
853
861
|
const r = renderNode(result, writer, isSvg);
|
|
854
862
|
if (r && typeof r.then === "function") {
|
|
855
|
-
const
|
|
856
|
-
const u = captureUnsuspend();
|
|
863
|
+
const rctx = captureRenderCtx();
|
|
857
864
|
return r.then(
|
|
858
865
|
() => {
|
|
859
|
-
|
|
860
|
-
restoreUnsuspend(u);
|
|
866
|
+
restoreRenderCtx(rctx);
|
|
861
867
|
if (savedIdTree !== void 0) popTreeContext(savedIdTree);
|
|
862
868
|
popComponentScope(savedScope);
|
|
863
869
|
if (isProvider) popContextValue(ctx, prevCtxValue);
|
|
864
870
|
},
|
|
865
871
|
(e) => {
|
|
866
|
-
|
|
867
|
-
restoreUnsuspend(u);
|
|
872
|
+
restoreRenderCtx(rctx);
|
|
868
873
|
if (savedIdTree !== void 0) popTreeContext(savedIdTree);
|
|
869
874
|
popComponentScope(savedScope);
|
|
870
875
|
if (isProvider) popContextValue(ctx, prevCtxValue);
|
|
@@ -889,11 +894,9 @@ function renderChildArrayFrom(children, startIndex, writer, isSvg) {
|
|
|
889
894
|
const savedTree = pushTreeContext(totalChildren, i);
|
|
890
895
|
const r = renderNode(child, writer, isSvg);
|
|
891
896
|
if (r && typeof r.then === "function") {
|
|
892
|
-
const
|
|
893
|
-
const u = captureUnsuspend();
|
|
897
|
+
const rctx = captureRenderCtx();
|
|
894
898
|
return r.then(() => {
|
|
895
|
-
|
|
896
|
-
restoreUnsuspend(u);
|
|
899
|
+
restoreRenderCtx(rctx);
|
|
897
900
|
popTreeContext(savedTree);
|
|
898
901
|
return renderChildArrayFrom(children, i + 1, writer, isSvg);
|
|
899
902
|
});
|
|
@@ -917,11 +920,9 @@ async function renderSuspense(props, writer, isSvg = false) {
|
|
|
917
920
|
try {
|
|
918
921
|
const r = renderNode(children, buffer, isSvg);
|
|
919
922
|
if (r && typeof r.then === "function") {
|
|
920
|
-
const
|
|
921
|
-
const u = captureUnsuspend();
|
|
923
|
+
const rctx = captureRenderCtx();
|
|
922
924
|
await r;
|
|
923
|
-
|
|
924
|
-
restoreUnsuspend(u);
|
|
925
|
+
restoreRenderCtx(rctx);
|
|
925
926
|
}
|
|
926
927
|
writer.write("<!--$-->");
|
|
927
928
|
buffer.flushTo(writer);
|
|
@@ -935,11 +936,9 @@ async function renderSuspense(props, writer, isSvg = false) {
|
|
|
935
936
|
if (fallback) {
|
|
936
937
|
const r = renderNode(fallback, writer, isSvg);
|
|
937
938
|
if (r && typeof r.then === "function") {
|
|
938
|
-
const
|
|
939
|
-
const u = captureUnsuspend();
|
|
939
|
+
const rctx = captureRenderCtx();
|
|
940
940
|
await r;
|
|
941
|
-
|
|
942
|
-
restoreUnsuspend(u);
|
|
941
|
+
restoreRenderCtx(rctx);
|
|
943
942
|
}
|
|
944
943
|
}
|
|
945
944
|
writer.write("<!--/$-->");
|
|
@@ -976,9 +975,9 @@ function renderToStream(element, options) {
|
|
|
976
975
|
try {
|
|
977
976
|
const r = renderNode(element, writer);
|
|
978
977
|
if (r && typeof r.then === "function") {
|
|
979
|
-
const
|
|
978
|
+
const rctx = captureRenderCtx();
|
|
980
979
|
await r;
|
|
981
|
-
|
|
980
|
+
restoreRenderCtx(rctx);
|
|
982
981
|
}
|
|
983
982
|
writer.flush();
|
|
984
983
|
controller.close();
|
|
@@ -1005,9 +1004,9 @@ async function renderPreflight(element, options) {
|
|
|
1005
1004
|
NULL_WRITER.lastWasText = false;
|
|
1006
1005
|
const r = renderNode(element, NULL_WRITER);
|
|
1007
1006
|
if (r && typeof r.then === "function") {
|
|
1008
|
-
const
|
|
1007
|
+
const rctx = captureRenderCtx();
|
|
1009
1008
|
await r;
|
|
1010
|
-
|
|
1009
|
+
restoreRenderCtx(rctx);
|
|
1011
1010
|
}
|
|
1012
1011
|
} finally {
|
|
1013
1012
|
swapContextMap(prev);
|
|
@@ -1032,9 +1031,9 @@ async function renderToString(element, options) {
|
|
|
1032
1031
|
resetRenderState(idPrefix);
|
|
1033
1032
|
const r = renderNode(element, writer);
|
|
1034
1033
|
if (r && typeof r.then === "function") {
|
|
1035
|
-
const
|
|
1034
|
+
const rctx = captureRenderCtx();
|
|
1036
1035
|
await r;
|
|
1037
|
-
|
|
1036
|
+
restoreRenderCtx(rctx);
|
|
1038
1037
|
}
|
|
1039
1038
|
return output;
|
|
1040
1039
|
} finally {
|
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
|
-
|
|
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
|
|
840
|
-
const u = captureUnsuspend();
|
|
860
|
+
const rctx = captureRenderCtx();
|
|
841
861
|
return e.then(() => {
|
|
842
|
-
|
|
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
|
|
881
|
-
const u = captureUnsuspend();
|
|
899
|
+
const rctx = captureRenderCtx();
|
|
882
900
|
return r2.then(
|
|
883
901
|
() => {
|
|
884
|
-
|
|
885
|
-
restoreUnsuspend(u);
|
|
902
|
+
restoreRenderCtx(rctx);
|
|
886
903
|
finish();
|
|
887
904
|
},
|
|
888
905
|
(e) => {
|
|
889
|
-
|
|
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
|
|
920
|
-
const u = captureUnsuspend();
|
|
935
|
+
const rctx = captureRenderCtx();
|
|
921
936
|
return e.then(() => {
|
|
922
|
-
|
|
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
|
|
936
|
-
const u = captureUnsuspend();
|
|
949
|
+
const rctx = captureRenderCtx();
|
|
937
950
|
return result.then((resolved) => {
|
|
938
|
-
|
|
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
|
|
947
|
-
const u2 = captureUnsuspend();
|
|
958
|
+
const rctx2 = captureRenderCtx();
|
|
948
959
|
return r2.then(
|
|
949
960
|
() => {
|
|
950
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
980
|
-
const u = captureUnsuspend();
|
|
987
|
+
const rctx = captureRenderCtx();
|
|
981
988
|
return r.then(
|
|
982
989
|
() => {
|
|
983
|
-
|
|
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
|
-
|
|
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
|
|
1017
|
-
const u = captureUnsuspend();
|
|
1021
|
+
const rctx = captureRenderCtx();
|
|
1018
1022
|
return r.then(() => {
|
|
1019
|
-
|
|
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
|
|
1045
|
-
const u = captureUnsuspend();
|
|
1047
|
+
const rctx = captureRenderCtx();
|
|
1046
1048
|
await r;
|
|
1047
|
-
|
|
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
|
|
1063
|
-
const u = captureUnsuspend();
|
|
1063
|
+
const rctx = captureRenderCtx();
|
|
1064
1064
|
await r;
|
|
1065
|
-
|
|
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
|
|
1090
|
+
const rctx = captureRenderCtx();
|
|
1092
1091
|
await r;
|
|
1093
|
-
|
|
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
|
|
1117
|
+
const rctx = captureRenderCtx();
|
|
1119
1118
|
await r;
|
|
1120
|
-
|
|
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
|
-
|
|
1585
|
-
children: true,
|
|
1586
|
-
chunks: true,
|
|
1587
|
-
chunkModules: true
|
|
1589
|
+
preset: "minimal"
|
|
1588
1590
|
}));
|
|
1589
1591
|
resolve2(stats);
|
|
1590
1592
|
});
|
|
@@ -1786,18 +1788,18 @@ var makePrecontentHtmlGetter = (htmlFilePromise) => {
|
|
|
1786
1788
|
let preHead = null;
|
|
1787
1789
|
let postHead = null;
|
|
1788
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
|
+
});
|
|
1789
1798
|
return (headHtml) => {
|
|
1790
1799
|
if (preHead !== null) {
|
|
1791
1800
|
return [preHead + headHtml + postHead, postContent];
|
|
1792
1801
|
}
|
|
1793
|
-
return
|
|
1794
|
-
const headEnd = html.indexOf(HEAD_MARKER);
|
|
1795
|
-
const contentStart = html.indexOf(BODY_MARKER);
|
|
1796
|
-
preHead = html.slice(0, headEnd);
|
|
1797
|
-
postHead = html.slice(headEnd + HEAD_MARKER.length, contentStart);
|
|
1798
|
-
postContent = html.slice(contentStart + BODY_MARKER.length);
|
|
1799
|
-
return [preHead + headHtml + postHead, postContent];
|
|
1800
|
-
});
|
|
1802
|
+
return primed.then(() => [preHead + headHtml + postHead, postContent]);
|
|
1801
1803
|
};
|
|
1802
1804
|
};
|
|
1803
1805
|
async function transformStream(data, stream) {
|
|
@@ -2833,6 +2835,10 @@ var run = async (options) => {
|
|
|
2833
2835
|
const getPrecontentHtml = makePrecontentHtmlGetter(
|
|
2834
2836
|
fs.readFile(pathMod2.join(__dirname2, StaticPath, "out.html"), "utf-8")
|
|
2835
2837
|
);
|
|
2838
|
+
const componentPath = pathToFileURL(
|
|
2839
|
+
pathMod2.resolve(__dirname2, HadarsFolder, SSR_FILENAME)
|
|
2840
|
+
).href;
|
|
2841
|
+
const ssrModulePromise = import(componentPath);
|
|
2836
2842
|
const runHandler = async (req, ctx) => {
|
|
2837
2843
|
const request = parseRequest(req);
|
|
2838
2844
|
if (handler) {
|
|
@@ -2856,15 +2862,12 @@ var run = async (options) => {
|
|
|
2856
2862
|
);
|
|
2857
2863
|
if (routeRes) return routeRes;
|
|
2858
2864
|
}
|
|
2859
|
-
const componentPath = pathToFileURL(
|
|
2860
|
-
pathMod2.resolve(__dirname2, HadarsFolder, SSR_FILENAME)
|
|
2861
|
-
).href;
|
|
2862
2865
|
try {
|
|
2863
2866
|
const {
|
|
2864
2867
|
default: Component,
|
|
2865
2868
|
getInitProps,
|
|
2866
2869
|
getFinalProps
|
|
2867
|
-
} = await
|
|
2870
|
+
} = await ssrModulePromise;
|
|
2868
2871
|
if (renderPool && request.headers.get("Accept") !== "application/json") {
|
|
2869
2872
|
const serialReq = await serializeRequest(request);
|
|
2870
2873
|
const { html, headHtml: wHead, status: wStatus } = await renderPool.renderFull(serialReq);
|