@webtypen/webframez-react 0.0.17 → 0.0.19
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/http.cjs +20 -73
- package/dist/http.js +20 -73
- package/dist/index.cjs +20 -73
- package/dist/index.js +20 -73
- package/dist/webframez-core.cjs +20 -73
- package/dist/webframez-core.js +20 -73
- package/package.json +1 -1
package/dist/http.cjs
CHANGED
|
@@ -636,11 +636,6 @@ const Module = require("node:module");
|
|
|
636
636
|
const { Writable } = require("node:stream");
|
|
637
637
|
const { createFromReadableStream } = require("react-server-dom-webpack/client.node");
|
|
638
638
|
|
|
639
|
-
const pagesDir = process.env.WEBFRAMEZ_REACT_PAGES_DIR || "";
|
|
640
|
-
if (!pagesDir) {
|
|
641
|
-
throw new Error("Missing WEBFRAMEZ_REACT_PAGES_DIR");
|
|
642
|
-
}
|
|
643
|
-
|
|
644
639
|
const originalResolveFilename = Module._resolveFilename;
|
|
645
640
|
const rootParent = {
|
|
646
641
|
id: "__webframez_react_worker__",
|
|
@@ -678,12 +673,10 @@ Module._resolveFilename = function(request, parent, isMain, options) {
|
|
|
678
673
|
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
679
674
|
};
|
|
680
675
|
|
|
681
|
-
const { createFileRouter } = require("@webtypen/webframez-react/router");
|
|
682
676
|
const reactDomPkg = require.resolve("react-dom/package.json", {
|
|
683
|
-
paths: [process.cwd()
|
|
677
|
+
paths: [process.cwd()]
|
|
684
678
|
});
|
|
685
679
|
const reactDomServer = require(path.join(path.dirname(reactDomPkg), "server.node.js"));
|
|
686
|
-
const router = createFileRouter({ pagesDir });
|
|
687
680
|
|
|
688
681
|
function renderHtml(model) {
|
|
689
682
|
return new Promise((resolve, reject) => {
|
|
@@ -732,7 +725,7 @@ function createReadableStreamFromString(value) {
|
|
|
732
725
|
}
|
|
733
726
|
|
|
734
727
|
async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
735
|
-
const
|
|
728
|
+
const payload = await createFromReadableStream(createReadableStreamFromString(flightData), {
|
|
736
729
|
serverConsumerManifest: {
|
|
737
730
|
moduleMap: moduleMap || {},
|
|
738
731
|
serverModuleMap: null,
|
|
@@ -740,37 +733,24 @@ async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
|
740
733
|
}
|
|
741
734
|
});
|
|
742
735
|
|
|
736
|
+
const model =
|
|
737
|
+
payload && typeof payload === "object" && "model" in payload
|
|
738
|
+
? payload.model
|
|
739
|
+
: payload;
|
|
740
|
+
|
|
743
741
|
return renderHtml(model);
|
|
744
742
|
}
|
|
745
743
|
|
|
746
744
|
process.on("message", async (message) => {
|
|
747
|
-
if (!message ||
|
|
745
|
+
if (!message || message.type !== "render-flight") {
|
|
748
746
|
return;
|
|
749
747
|
}
|
|
750
748
|
|
|
751
749
|
try {
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
globalThis.__RSC_BASENAME = message.payload.basename || "";
|
|
757
|
-
|
|
758
|
-
try {
|
|
759
|
-
const resolved = await router.resolve({
|
|
760
|
-
pathname: message.payload.pathname,
|
|
761
|
-
searchParams: message.payload.searchParams || {},
|
|
762
|
-
cookies: message.payload.cookies || {},
|
|
763
|
-
});
|
|
764
|
-
html = await renderHtml(resolved.model);
|
|
765
|
-
} finally {
|
|
766
|
-
globalThis.__RSC_BASENAME = previousBasename;
|
|
767
|
-
}
|
|
768
|
-
} else {
|
|
769
|
-
html = await renderHtmlFromFlightData(
|
|
770
|
-
message.payload.flightData || "",
|
|
771
|
-
message.payload.moduleMap || {},
|
|
772
|
-
);
|
|
773
|
-
}
|
|
750
|
+
const html = await renderHtmlFromFlightData(
|
|
751
|
+
message.payload.flightData || "",
|
|
752
|
+
message.payload.moduleMap || {},
|
|
753
|
+
);
|
|
774
754
|
|
|
775
755
|
if (typeof process.send === "function") {
|
|
776
756
|
process.send({ id: message.id, ok: true, html });
|
|
@@ -810,7 +790,7 @@ function sanitizeInitialHtmlWorkerNodeOptions(rawNodeOptions) {
|
|
|
810
790
|
}
|
|
811
791
|
return rawNodeOptions.replace(/(^|\s)--conditions\s+react-server(?=\s|$)/g, " ").replace(/(^|\s)-r\s+(\S*webframez-react\/register)(?=\s|$)/g, " ").replace(/\s+/g, " ").trim();
|
|
812
792
|
}
|
|
813
|
-
function createInitialHtmlWorker(
|
|
793
|
+
function createInitialHtmlWorker(_pagesDir) {
|
|
814
794
|
let child = null;
|
|
815
795
|
let nextRequestId = 1;
|
|
816
796
|
let stderrBuffer = "";
|
|
@@ -841,8 +821,7 @@ function createInitialHtmlWorker(pagesDir) {
|
|
|
841
821
|
cwd: process.cwd(),
|
|
842
822
|
env: {
|
|
843
823
|
...process.env,
|
|
844
|
-
NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
|
|
845
|
-
WEBFRAMEZ_REACT_PAGES_DIR: pagesDir
|
|
824
|
+
NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
|
|
846
825
|
},
|
|
847
826
|
stdio: ["ignore", "ignore", "pipe", "ipc"]
|
|
848
827
|
});
|
|
@@ -882,34 +861,6 @@ ${stderrBuffer.trim()}` : "";
|
|
|
882
861
|
return child;
|
|
883
862
|
};
|
|
884
863
|
return {
|
|
885
|
-
render(payload) {
|
|
886
|
-
const activeChild = startWorker();
|
|
887
|
-
const requestId = nextRequestId++;
|
|
888
|
-
return new Promise((resolve, reject) => {
|
|
889
|
-
const timeout = setTimeout(() => {
|
|
890
|
-
rejectPending(new Error("[webframez-react] Initial HTML worker timed out"));
|
|
891
|
-
stopWorker();
|
|
892
|
-
}, 1e4);
|
|
893
|
-
pending.set(requestId, { resolve, reject, timeout });
|
|
894
|
-
const request = {
|
|
895
|
-
id: requestId,
|
|
896
|
-
type: "render-route",
|
|
897
|
-
payload
|
|
898
|
-
};
|
|
899
|
-
activeChild.send(request, (error) => {
|
|
900
|
-
if (!error) {
|
|
901
|
-
return;
|
|
902
|
-
}
|
|
903
|
-
const entry = pending.get(requestId);
|
|
904
|
-
if (!entry) {
|
|
905
|
-
return;
|
|
906
|
-
}
|
|
907
|
-
pending.delete(requestId);
|
|
908
|
-
clearTimeout(entry.timeout);
|
|
909
|
-
entry.reject(error instanceof Error ? error : new Error(String(error)));
|
|
910
|
-
});
|
|
911
|
-
});
|
|
912
|
-
},
|
|
913
864
|
renderFromFlightData(payload) {
|
|
914
865
|
const activeChild = startWorker();
|
|
915
866
|
const requestId = nextRequestId++;
|
|
@@ -1153,21 +1104,17 @@ function createNodeRequestHandler(options) {
|
|
|
1153
1104
|
});
|
|
1154
1105
|
let rootHtml = "";
|
|
1155
1106
|
try {
|
|
1156
|
-
rootHtml = await initialHtmlWorker.
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
cookies: requestCookies,
|
|
1160
|
-
basename: basePath
|
|
1107
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1108
|
+
flightData: initialFlightData,
|
|
1109
|
+
moduleMap
|
|
1161
1110
|
});
|
|
1162
1111
|
} catch (error) {
|
|
1163
1112
|
console.error("[webframez-react] Failed to render initial HTML", error);
|
|
1164
1113
|
try {
|
|
1165
1114
|
initialHtmlWorker.dispose();
|
|
1166
|
-
rootHtml = await initialHtmlWorker.
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
cookies: requestCookies,
|
|
1170
|
-
basename: basePath
|
|
1115
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1116
|
+
flightData: initialFlightData,
|
|
1117
|
+
moduleMap
|
|
1171
1118
|
});
|
|
1172
1119
|
} catch (retryError) {
|
|
1173
1120
|
console.error("[webframez-react] Retry for initial HTML failed", retryError);
|
package/dist/http.js
CHANGED
|
@@ -611,11 +611,6 @@ const Module = require("node:module");
|
|
|
611
611
|
const { Writable } = require("node:stream");
|
|
612
612
|
const { createFromReadableStream } = require("react-server-dom-webpack/client.node");
|
|
613
613
|
|
|
614
|
-
const pagesDir = process.env.WEBFRAMEZ_REACT_PAGES_DIR || "";
|
|
615
|
-
if (!pagesDir) {
|
|
616
|
-
throw new Error("Missing WEBFRAMEZ_REACT_PAGES_DIR");
|
|
617
|
-
}
|
|
618
|
-
|
|
619
614
|
const originalResolveFilename = Module._resolveFilename;
|
|
620
615
|
const rootParent = {
|
|
621
616
|
id: "__webframez_react_worker__",
|
|
@@ -653,12 +648,10 @@ Module._resolveFilename = function(request, parent, isMain, options) {
|
|
|
653
648
|
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
654
649
|
};
|
|
655
650
|
|
|
656
|
-
const { createFileRouter } = require("@webtypen/webframez-react/router");
|
|
657
651
|
const reactDomPkg = require.resolve("react-dom/package.json", {
|
|
658
|
-
paths: [process.cwd()
|
|
652
|
+
paths: [process.cwd()]
|
|
659
653
|
});
|
|
660
654
|
const reactDomServer = require(path.join(path.dirname(reactDomPkg), "server.node.js"));
|
|
661
|
-
const router = createFileRouter({ pagesDir });
|
|
662
655
|
|
|
663
656
|
function renderHtml(model) {
|
|
664
657
|
return new Promise((resolve, reject) => {
|
|
@@ -707,7 +700,7 @@ function createReadableStreamFromString(value) {
|
|
|
707
700
|
}
|
|
708
701
|
|
|
709
702
|
async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
710
|
-
const
|
|
703
|
+
const payload = await createFromReadableStream(createReadableStreamFromString(flightData), {
|
|
711
704
|
serverConsumerManifest: {
|
|
712
705
|
moduleMap: moduleMap || {},
|
|
713
706
|
serverModuleMap: null,
|
|
@@ -715,37 +708,24 @@ async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
|
715
708
|
}
|
|
716
709
|
});
|
|
717
710
|
|
|
711
|
+
const model =
|
|
712
|
+
payload && typeof payload === "object" && "model" in payload
|
|
713
|
+
? payload.model
|
|
714
|
+
: payload;
|
|
715
|
+
|
|
718
716
|
return renderHtml(model);
|
|
719
717
|
}
|
|
720
718
|
|
|
721
719
|
process.on("message", async (message) => {
|
|
722
|
-
if (!message ||
|
|
720
|
+
if (!message || message.type !== "render-flight") {
|
|
723
721
|
return;
|
|
724
722
|
}
|
|
725
723
|
|
|
726
724
|
try {
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
globalThis.__RSC_BASENAME = message.payload.basename || "";
|
|
732
|
-
|
|
733
|
-
try {
|
|
734
|
-
const resolved = await router.resolve({
|
|
735
|
-
pathname: message.payload.pathname,
|
|
736
|
-
searchParams: message.payload.searchParams || {},
|
|
737
|
-
cookies: message.payload.cookies || {},
|
|
738
|
-
});
|
|
739
|
-
html = await renderHtml(resolved.model);
|
|
740
|
-
} finally {
|
|
741
|
-
globalThis.__RSC_BASENAME = previousBasename;
|
|
742
|
-
}
|
|
743
|
-
} else {
|
|
744
|
-
html = await renderHtmlFromFlightData(
|
|
745
|
-
message.payload.flightData || "",
|
|
746
|
-
message.payload.moduleMap || {},
|
|
747
|
-
);
|
|
748
|
-
}
|
|
725
|
+
const html = await renderHtmlFromFlightData(
|
|
726
|
+
message.payload.flightData || "",
|
|
727
|
+
message.payload.moduleMap || {},
|
|
728
|
+
);
|
|
749
729
|
|
|
750
730
|
if (typeof process.send === "function") {
|
|
751
731
|
process.send({ id: message.id, ok: true, html });
|
|
@@ -785,7 +765,7 @@ function sanitizeInitialHtmlWorkerNodeOptions(rawNodeOptions) {
|
|
|
785
765
|
}
|
|
786
766
|
return rawNodeOptions.replace(/(^|\s)--conditions\s+react-server(?=\s|$)/g, " ").replace(/(^|\s)-r\s+(\S*webframez-react\/register)(?=\s|$)/g, " ").replace(/\s+/g, " ").trim();
|
|
787
767
|
}
|
|
788
|
-
function createInitialHtmlWorker(
|
|
768
|
+
function createInitialHtmlWorker(_pagesDir) {
|
|
789
769
|
let child = null;
|
|
790
770
|
let nextRequestId = 1;
|
|
791
771
|
let stderrBuffer = "";
|
|
@@ -816,8 +796,7 @@ function createInitialHtmlWorker(pagesDir) {
|
|
|
816
796
|
cwd: process.cwd(),
|
|
817
797
|
env: {
|
|
818
798
|
...process.env,
|
|
819
|
-
NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
|
|
820
|
-
WEBFRAMEZ_REACT_PAGES_DIR: pagesDir
|
|
799
|
+
NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
|
|
821
800
|
},
|
|
822
801
|
stdio: ["ignore", "ignore", "pipe", "ipc"]
|
|
823
802
|
});
|
|
@@ -857,34 +836,6 @@ ${stderrBuffer.trim()}` : "";
|
|
|
857
836
|
return child;
|
|
858
837
|
};
|
|
859
838
|
return {
|
|
860
|
-
render(payload) {
|
|
861
|
-
const activeChild = startWorker();
|
|
862
|
-
const requestId = nextRequestId++;
|
|
863
|
-
return new Promise((resolve, reject) => {
|
|
864
|
-
const timeout = setTimeout(() => {
|
|
865
|
-
rejectPending(new Error("[webframez-react] Initial HTML worker timed out"));
|
|
866
|
-
stopWorker();
|
|
867
|
-
}, 1e4);
|
|
868
|
-
pending.set(requestId, { resolve, reject, timeout });
|
|
869
|
-
const request = {
|
|
870
|
-
id: requestId,
|
|
871
|
-
type: "render-route",
|
|
872
|
-
payload
|
|
873
|
-
};
|
|
874
|
-
activeChild.send(request, (error) => {
|
|
875
|
-
if (!error) {
|
|
876
|
-
return;
|
|
877
|
-
}
|
|
878
|
-
const entry = pending.get(requestId);
|
|
879
|
-
if (!entry) {
|
|
880
|
-
return;
|
|
881
|
-
}
|
|
882
|
-
pending.delete(requestId);
|
|
883
|
-
clearTimeout(entry.timeout);
|
|
884
|
-
entry.reject(error instanceof Error ? error : new Error(String(error)));
|
|
885
|
-
});
|
|
886
|
-
});
|
|
887
|
-
},
|
|
888
839
|
renderFromFlightData(payload) {
|
|
889
840
|
const activeChild = startWorker();
|
|
890
841
|
const requestId = nextRequestId++;
|
|
@@ -1128,21 +1079,17 @@ function createNodeRequestHandler(options) {
|
|
|
1128
1079
|
});
|
|
1129
1080
|
let rootHtml = "";
|
|
1130
1081
|
try {
|
|
1131
|
-
rootHtml = await initialHtmlWorker.
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
cookies: requestCookies,
|
|
1135
|
-
basename: basePath
|
|
1082
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1083
|
+
flightData: initialFlightData,
|
|
1084
|
+
moduleMap
|
|
1136
1085
|
});
|
|
1137
1086
|
} catch (error) {
|
|
1138
1087
|
console.error("[webframez-react] Failed to render initial HTML", error);
|
|
1139
1088
|
try {
|
|
1140
1089
|
initialHtmlWorker.dispose();
|
|
1141
|
-
rootHtml = await initialHtmlWorker.
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
cookies: requestCookies,
|
|
1145
|
-
basename: basePath
|
|
1090
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1091
|
+
flightData: initialFlightData,
|
|
1092
|
+
moduleMap
|
|
1146
1093
|
});
|
|
1147
1094
|
} catch (retryError) {
|
|
1148
1095
|
console.error("[webframez-react] Retry for initial HTML failed", retryError);
|
package/dist/index.cjs
CHANGED
|
@@ -673,11 +673,6 @@ const Module = require("node:module");
|
|
|
673
673
|
const { Writable } = require("node:stream");
|
|
674
674
|
const { createFromReadableStream } = require("react-server-dom-webpack/client.node");
|
|
675
675
|
|
|
676
|
-
const pagesDir = process.env.WEBFRAMEZ_REACT_PAGES_DIR || "";
|
|
677
|
-
if (!pagesDir) {
|
|
678
|
-
throw new Error("Missing WEBFRAMEZ_REACT_PAGES_DIR");
|
|
679
|
-
}
|
|
680
|
-
|
|
681
676
|
const originalResolveFilename = Module._resolveFilename;
|
|
682
677
|
const rootParent = {
|
|
683
678
|
id: "__webframez_react_worker__",
|
|
@@ -715,12 +710,10 @@ Module._resolveFilename = function(request, parent, isMain, options) {
|
|
|
715
710
|
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
716
711
|
};
|
|
717
712
|
|
|
718
|
-
const { createFileRouter } = require("@webtypen/webframez-react/router");
|
|
719
713
|
const reactDomPkg = require.resolve("react-dom/package.json", {
|
|
720
|
-
paths: [process.cwd()
|
|
714
|
+
paths: [process.cwd()]
|
|
721
715
|
});
|
|
722
716
|
const reactDomServer = require(path.join(path.dirname(reactDomPkg), "server.node.js"));
|
|
723
|
-
const router = createFileRouter({ pagesDir });
|
|
724
717
|
|
|
725
718
|
function renderHtml(model) {
|
|
726
719
|
return new Promise((resolve, reject) => {
|
|
@@ -769,7 +762,7 @@ function createReadableStreamFromString(value) {
|
|
|
769
762
|
}
|
|
770
763
|
|
|
771
764
|
async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
772
|
-
const
|
|
765
|
+
const payload = await createFromReadableStream(createReadableStreamFromString(flightData), {
|
|
773
766
|
serverConsumerManifest: {
|
|
774
767
|
moduleMap: moduleMap || {},
|
|
775
768
|
serverModuleMap: null,
|
|
@@ -777,37 +770,24 @@ async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
|
777
770
|
}
|
|
778
771
|
});
|
|
779
772
|
|
|
773
|
+
const model =
|
|
774
|
+
payload && typeof payload === "object" && "model" in payload
|
|
775
|
+
? payload.model
|
|
776
|
+
: payload;
|
|
777
|
+
|
|
780
778
|
return renderHtml(model);
|
|
781
779
|
}
|
|
782
780
|
|
|
783
781
|
process.on("message", async (message) => {
|
|
784
|
-
if (!message ||
|
|
782
|
+
if (!message || message.type !== "render-flight") {
|
|
785
783
|
return;
|
|
786
784
|
}
|
|
787
785
|
|
|
788
786
|
try {
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
globalThis.__RSC_BASENAME = message.payload.basename || "";
|
|
794
|
-
|
|
795
|
-
try {
|
|
796
|
-
const resolved = await router.resolve({
|
|
797
|
-
pathname: message.payload.pathname,
|
|
798
|
-
searchParams: message.payload.searchParams || {},
|
|
799
|
-
cookies: message.payload.cookies || {},
|
|
800
|
-
});
|
|
801
|
-
html = await renderHtml(resolved.model);
|
|
802
|
-
} finally {
|
|
803
|
-
globalThis.__RSC_BASENAME = previousBasename;
|
|
804
|
-
}
|
|
805
|
-
} else {
|
|
806
|
-
html = await renderHtmlFromFlightData(
|
|
807
|
-
message.payload.flightData || "",
|
|
808
|
-
message.payload.moduleMap || {},
|
|
809
|
-
);
|
|
810
|
-
}
|
|
787
|
+
const html = await renderHtmlFromFlightData(
|
|
788
|
+
message.payload.flightData || "",
|
|
789
|
+
message.payload.moduleMap || {},
|
|
790
|
+
);
|
|
811
791
|
|
|
812
792
|
if (typeof process.send === "function") {
|
|
813
793
|
process.send({ id: message.id, ok: true, html });
|
|
@@ -847,7 +827,7 @@ function sanitizeInitialHtmlWorkerNodeOptions(rawNodeOptions) {
|
|
|
847
827
|
}
|
|
848
828
|
return rawNodeOptions.replace(/(^|\s)--conditions\s+react-server(?=\s|$)/g, " ").replace(/(^|\s)-r\s+(\S*webframez-react\/register)(?=\s|$)/g, " ").replace(/\s+/g, " ").trim();
|
|
849
829
|
}
|
|
850
|
-
function createInitialHtmlWorker(
|
|
830
|
+
function createInitialHtmlWorker(_pagesDir) {
|
|
851
831
|
let child = null;
|
|
852
832
|
let nextRequestId = 1;
|
|
853
833
|
let stderrBuffer = "";
|
|
@@ -878,8 +858,7 @@ function createInitialHtmlWorker(pagesDir) {
|
|
|
878
858
|
cwd: process.cwd(),
|
|
879
859
|
env: {
|
|
880
860
|
...process.env,
|
|
881
|
-
NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
|
|
882
|
-
WEBFRAMEZ_REACT_PAGES_DIR: pagesDir
|
|
861
|
+
NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
|
|
883
862
|
},
|
|
884
863
|
stdio: ["ignore", "ignore", "pipe", "ipc"]
|
|
885
864
|
});
|
|
@@ -919,34 +898,6 @@ ${stderrBuffer.trim()}` : "";
|
|
|
919
898
|
return child;
|
|
920
899
|
};
|
|
921
900
|
return {
|
|
922
|
-
render(payload) {
|
|
923
|
-
const activeChild = startWorker();
|
|
924
|
-
const requestId = nextRequestId++;
|
|
925
|
-
return new Promise((resolve, reject) => {
|
|
926
|
-
const timeout = setTimeout(() => {
|
|
927
|
-
rejectPending(new Error("[webframez-react] Initial HTML worker timed out"));
|
|
928
|
-
stopWorker();
|
|
929
|
-
}, 1e4);
|
|
930
|
-
pending.set(requestId, { resolve, reject, timeout });
|
|
931
|
-
const request = {
|
|
932
|
-
id: requestId,
|
|
933
|
-
type: "render-route",
|
|
934
|
-
payload
|
|
935
|
-
};
|
|
936
|
-
activeChild.send(request, (error) => {
|
|
937
|
-
if (!error) {
|
|
938
|
-
return;
|
|
939
|
-
}
|
|
940
|
-
const entry = pending.get(requestId);
|
|
941
|
-
if (!entry) {
|
|
942
|
-
return;
|
|
943
|
-
}
|
|
944
|
-
pending.delete(requestId);
|
|
945
|
-
clearTimeout(entry.timeout);
|
|
946
|
-
entry.reject(error instanceof Error ? error : new Error(String(error)));
|
|
947
|
-
});
|
|
948
|
-
});
|
|
949
|
-
},
|
|
950
901
|
renderFromFlightData(payload) {
|
|
951
902
|
const activeChild = startWorker();
|
|
952
903
|
const requestId = nextRequestId++;
|
|
@@ -1190,21 +1141,17 @@ function createNodeRequestHandler(options) {
|
|
|
1190
1141
|
});
|
|
1191
1142
|
let rootHtml = "";
|
|
1192
1143
|
try {
|
|
1193
|
-
rootHtml = await initialHtmlWorker.
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
cookies: requestCookies,
|
|
1197
|
-
basename: basePath
|
|
1144
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1145
|
+
flightData: initialFlightData,
|
|
1146
|
+
moduleMap
|
|
1198
1147
|
});
|
|
1199
1148
|
} catch (error) {
|
|
1200
1149
|
console.error("[webframez-react] Failed to render initial HTML", error);
|
|
1201
1150
|
try {
|
|
1202
1151
|
initialHtmlWorker.dispose();
|
|
1203
|
-
rootHtml = await initialHtmlWorker.
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
cookies: requestCookies,
|
|
1207
|
-
basename: basePath
|
|
1152
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1153
|
+
flightData: initialFlightData,
|
|
1154
|
+
moduleMap
|
|
1208
1155
|
});
|
|
1209
1156
|
} catch (retryError) {
|
|
1210
1157
|
console.error("[webframez-react] Retry for initial HTML failed", retryError);
|
package/dist/index.js
CHANGED
|
@@ -637,11 +637,6 @@ const Module = require("node:module");
|
|
|
637
637
|
const { Writable } = require("node:stream");
|
|
638
638
|
const { createFromReadableStream } = require("react-server-dom-webpack/client.node");
|
|
639
639
|
|
|
640
|
-
const pagesDir = process.env.WEBFRAMEZ_REACT_PAGES_DIR || "";
|
|
641
|
-
if (!pagesDir) {
|
|
642
|
-
throw new Error("Missing WEBFRAMEZ_REACT_PAGES_DIR");
|
|
643
|
-
}
|
|
644
|
-
|
|
645
640
|
const originalResolveFilename = Module._resolveFilename;
|
|
646
641
|
const rootParent = {
|
|
647
642
|
id: "__webframez_react_worker__",
|
|
@@ -679,12 +674,10 @@ Module._resolveFilename = function(request, parent, isMain, options) {
|
|
|
679
674
|
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
680
675
|
};
|
|
681
676
|
|
|
682
|
-
const { createFileRouter } = require("@webtypen/webframez-react/router");
|
|
683
677
|
const reactDomPkg = require.resolve("react-dom/package.json", {
|
|
684
|
-
paths: [process.cwd()
|
|
678
|
+
paths: [process.cwd()]
|
|
685
679
|
});
|
|
686
680
|
const reactDomServer = require(path.join(path.dirname(reactDomPkg), "server.node.js"));
|
|
687
|
-
const router = createFileRouter({ pagesDir });
|
|
688
681
|
|
|
689
682
|
function renderHtml(model) {
|
|
690
683
|
return new Promise((resolve, reject) => {
|
|
@@ -733,7 +726,7 @@ function createReadableStreamFromString(value) {
|
|
|
733
726
|
}
|
|
734
727
|
|
|
735
728
|
async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
736
|
-
const
|
|
729
|
+
const payload = await createFromReadableStream(createReadableStreamFromString(flightData), {
|
|
737
730
|
serverConsumerManifest: {
|
|
738
731
|
moduleMap: moduleMap || {},
|
|
739
732
|
serverModuleMap: null,
|
|
@@ -741,37 +734,24 @@ async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
|
741
734
|
}
|
|
742
735
|
});
|
|
743
736
|
|
|
737
|
+
const model =
|
|
738
|
+
payload && typeof payload === "object" && "model" in payload
|
|
739
|
+
? payload.model
|
|
740
|
+
: payload;
|
|
741
|
+
|
|
744
742
|
return renderHtml(model);
|
|
745
743
|
}
|
|
746
744
|
|
|
747
745
|
process.on("message", async (message) => {
|
|
748
|
-
if (!message ||
|
|
746
|
+
if (!message || message.type !== "render-flight") {
|
|
749
747
|
return;
|
|
750
748
|
}
|
|
751
749
|
|
|
752
750
|
try {
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
globalThis.__RSC_BASENAME = message.payload.basename || "";
|
|
758
|
-
|
|
759
|
-
try {
|
|
760
|
-
const resolved = await router.resolve({
|
|
761
|
-
pathname: message.payload.pathname,
|
|
762
|
-
searchParams: message.payload.searchParams || {},
|
|
763
|
-
cookies: message.payload.cookies || {},
|
|
764
|
-
});
|
|
765
|
-
html = await renderHtml(resolved.model);
|
|
766
|
-
} finally {
|
|
767
|
-
globalThis.__RSC_BASENAME = previousBasename;
|
|
768
|
-
}
|
|
769
|
-
} else {
|
|
770
|
-
html = await renderHtmlFromFlightData(
|
|
771
|
-
message.payload.flightData || "",
|
|
772
|
-
message.payload.moduleMap || {},
|
|
773
|
-
);
|
|
774
|
-
}
|
|
751
|
+
const html = await renderHtmlFromFlightData(
|
|
752
|
+
message.payload.flightData || "",
|
|
753
|
+
message.payload.moduleMap || {},
|
|
754
|
+
);
|
|
775
755
|
|
|
776
756
|
if (typeof process.send === "function") {
|
|
777
757
|
process.send({ id: message.id, ok: true, html });
|
|
@@ -811,7 +791,7 @@ function sanitizeInitialHtmlWorkerNodeOptions(rawNodeOptions) {
|
|
|
811
791
|
}
|
|
812
792
|
return rawNodeOptions.replace(/(^|\s)--conditions\s+react-server(?=\s|$)/g, " ").replace(/(^|\s)-r\s+(\S*webframez-react\/register)(?=\s|$)/g, " ").replace(/\s+/g, " ").trim();
|
|
813
793
|
}
|
|
814
|
-
function createInitialHtmlWorker(
|
|
794
|
+
function createInitialHtmlWorker(_pagesDir) {
|
|
815
795
|
let child = null;
|
|
816
796
|
let nextRequestId = 1;
|
|
817
797
|
let stderrBuffer = "";
|
|
@@ -842,8 +822,7 @@ function createInitialHtmlWorker(pagesDir) {
|
|
|
842
822
|
cwd: process.cwd(),
|
|
843
823
|
env: {
|
|
844
824
|
...process.env,
|
|
845
|
-
NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
|
|
846
|
-
WEBFRAMEZ_REACT_PAGES_DIR: pagesDir
|
|
825
|
+
NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
|
|
847
826
|
},
|
|
848
827
|
stdio: ["ignore", "ignore", "pipe", "ipc"]
|
|
849
828
|
});
|
|
@@ -883,34 +862,6 @@ ${stderrBuffer.trim()}` : "";
|
|
|
883
862
|
return child;
|
|
884
863
|
};
|
|
885
864
|
return {
|
|
886
|
-
render(payload) {
|
|
887
|
-
const activeChild = startWorker();
|
|
888
|
-
const requestId = nextRequestId++;
|
|
889
|
-
return new Promise((resolve, reject) => {
|
|
890
|
-
const timeout = setTimeout(() => {
|
|
891
|
-
rejectPending(new Error("[webframez-react] Initial HTML worker timed out"));
|
|
892
|
-
stopWorker();
|
|
893
|
-
}, 1e4);
|
|
894
|
-
pending.set(requestId, { resolve, reject, timeout });
|
|
895
|
-
const request = {
|
|
896
|
-
id: requestId,
|
|
897
|
-
type: "render-route",
|
|
898
|
-
payload
|
|
899
|
-
};
|
|
900
|
-
activeChild.send(request, (error) => {
|
|
901
|
-
if (!error) {
|
|
902
|
-
return;
|
|
903
|
-
}
|
|
904
|
-
const entry = pending.get(requestId);
|
|
905
|
-
if (!entry) {
|
|
906
|
-
return;
|
|
907
|
-
}
|
|
908
|
-
pending.delete(requestId);
|
|
909
|
-
clearTimeout(entry.timeout);
|
|
910
|
-
entry.reject(error instanceof Error ? error : new Error(String(error)));
|
|
911
|
-
});
|
|
912
|
-
});
|
|
913
|
-
},
|
|
914
865
|
renderFromFlightData(payload) {
|
|
915
866
|
const activeChild = startWorker();
|
|
916
867
|
const requestId = nextRequestId++;
|
|
@@ -1154,21 +1105,17 @@ function createNodeRequestHandler(options) {
|
|
|
1154
1105
|
});
|
|
1155
1106
|
let rootHtml = "";
|
|
1156
1107
|
try {
|
|
1157
|
-
rootHtml = await initialHtmlWorker.
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
cookies: requestCookies,
|
|
1161
|
-
basename: basePath
|
|
1108
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1109
|
+
flightData: initialFlightData,
|
|
1110
|
+
moduleMap
|
|
1162
1111
|
});
|
|
1163
1112
|
} catch (error) {
|
|
1164
1113
|
console.error("[webframez-react] Failed to render initial HTML", error);
|
|
1165
1114
|
try {
|
|
1166
1115
|
initialHtmlWorker.dispose();
|
|
1167
|
-
rootHtml = await initialHtmlWorker.
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
cookies: requestCookies,
|
|
1171
|
-
basename: basePath
|
|
1116
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1117
|
+
flightData: initialFlightData,
|
|
1118
|
+
moduleMap
|
|
1172
1119
|
});
|
|
1173
1120
|
} catch (retryError) {
|
|
1174
1121
|
console.error("[webframez-react] Retry for initial HTML failed", retryError);
|
package/dist/webframez-core.cjs
CHANGED
|
@@ -639,11 +639,6 @@ const Module = require("node:module");
|
|
|
639
639
|
const { Writable } = require("node:stream");
|
|
640
640
|
const { createFromReadableStream } = require("react-server-dom-webpack/client.node");
|
|
641
641
|
|
|
642
|
-
const pagesDir = process.env.WEBFRAMEZ_REACT_PAGES_DIR || "";
|
|
643
|
-
if (!pagesDir) {
|
|
644
|
-
throw new Error("Missing WEBFRAMEZ_REACT_PAGES_DIR");
|
|
645
|
-
}
|
|
646
|
-
|
|
647
642
|
const originalResolveFilename = Module._resolveFilename;
|
|
648
643
|
const rootParent = {
|
|
649
644
|
id: "__webframez_react_worker__",
|
|
@@ -681,12 +676,10 @@ Module._resolveFilename = function(request, parent, isMain, options) {
|
|
|
681
676
|
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
682
677
|
};
|
|
683
678
|
|
|
684
|
-
const { createFileRouter } = require("@webtypen/webframez-react/router");
|
|
685
679
|
const reactDomPkg = require.resolve("react-dom/package.json", {
|
|
686
|
-
paths: [process.cwd()
|
|
680
|
+
paths: [process.cwd()]
|
|
687
681
|
});
|
|
688
682
|
const reactDomServer = require(path.join(path.dirname(reactDomPkg), "server.node.js"));
|
|
689
|
-
const router = createFileRouter({ pagesDir });
|
|
690
683
|
|
|
691
684
|
function renderHtml(model) {
|
|
692
685
|
return new Promise((resolve, reject) => {
|
|
@@ -735,7 +728,7 @@ function createReadableStreamFromString(value) {
|
|
|
735
728
|
}
|
|
736
729
|
|
|
737
730
|
async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
738
|
-
const
|
|
731
|
+
const payload = await createFromReadableStream(createReadableStreamFromString(flightData), {
|
|
739
732
|
serverConsumerManifest: {
|
|
740
733
|
moduleMap: moduleMap || {},
|
|
741
734
|
serverModuleMap: null,
|
|
@@ -743,37 +736,24 @@ async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
|
743
736
|
}
|
|
744
737
|
});
|
|
745
738
|
|
|
739
|
+
const model =
|
|
740
|
+
payload && typeof payload === "object" && "model" in payload
|
|
741
|
+
? payload.model
|
|
742
|
+
: payload;
|
|
743
|
+
|
|
746
744
|
return renderHtml(model);
|
|
747
745
|
}
|
|
748
746
|
|
|
749
747
|
process.on("message", async (message) => {
|
|
750
|
-
if (!message ||
|
|
748
|
+
if (!message || message.type !== "render-flight") {
|
|
751
749
|
return;
|
|
752
750
|
}
|
|
753
751
|
|
|
754
752
|
try {
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
globalThis.__RSC_BASENAME = message.payload.basename || "";
|
|
760
|
-
|
|
761
|
-
try {
|
|
762
|
-
const resolved = await router.resolve({
|
|
763
|
-
pathname: message.payload.pathname,
|
|
764
|
-
searchParams: message.payload.searchParams || {},
|
|
765
|
-
cookies: message.payload.cookies || {},
|
|
766
|
-
});
|
|
767
|
-
html = await renderHtml(resolved.model);
|
|
768
|
-
} finally {
|
|
769
|
-
globalThis.__RSC_BASENAME = previousBasename;
|
|
770
|
-
}
|
|
771
|
-
} else {
|
|
772
|
-
html = await renderHtmlFromFlightData(
|
|
773
|
-
message.payload.flightData || "",
|
|
774
|
-
message.payload.moduleMap || {},
|
|
775
|
-
);
|
|
776
|
-
}
|
|
753
|
+
const html = await renderHtmlFromFlightData(
|
|
754
|
+
message.payload.flightData || "",
|
|
755
|
+
message.payload.moduleMap || {},
|
|
756
|
+
);
|
|
777
757
|
|
|
778
758
|
if (typeof process.send === "function") {
|
|
779
759
|
process.send({ id: message.id, ok: true, html });
|
|
@@ -813,7 +793,7 @@ function sanitizeInitialHtmlWorkerNodeOptions(rawNodeOptions) {
|
|
|
813
793
|
}
|
|
814
794
|
return rawNodeOptions.replace(/(^|\s)--conditions\s+react-server(?=\s|$)/g, " ").replace(/(^|\s)-r\s+(\S*webframez-react\/register)(?=\s|$)/g, " ").replace(/\s+/g, " ").trim();
|
|
815
795
|
}
|
|
816
|
-
function createInitialHtmlWorker(
|
|
796
|
+
function createInitialHtmlWorker(_pagesDir) {
|
|
817
797
|
let child = null;
|
|
818
798
|
let nextRequestId = 1;
|
|
819
799
|
let stderrBuffer = "";
|
|
@@ -844,8 +824,7 @@ function createInitialHtmlWorker(pagesDir) {
|
|
|
844
824
|
cwd: process.cwd(),
|
|
845
825
|
env: {
|
|
846
826
|
...process.env,
|
|
847
|
-
NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
|
|
848
|
-
WEBFRAMEZ_REACT_PAGES_DIR: pagesDir
|
|
827
|
+
NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
|
|
849
828
|
},
|
|
850
829
|
stdio: ["ignore", "ignore", "pipe", "ipc"]
|
|
851
830
|
});
|
|
@@ -885,34 +864,6 @@ ${stderrBuffer.trim()}` : "";
|
|
|
885
864
|
return child;
|
|
886
865
|
};
|
|
887
866
|
return {
|
|
888
|
-
render(payload) {
|
|
889
|
-
const activeChild = startWorker();
|
|
890
|
-
const requestId = nextRequestId++;
|
|
891
|
-
return new Promise((resolve, reject) => {
|
|
892
|
-
const timeout = setTimeout(() => {
|
|
893
|
-
rejectPending(new Error("[webframez-react] Initial HTML worker timed out"));
|
|
894
|
-
stopWorker();
|
|
895
|
-
}, 1e4);
|
|
896
|
-
pending.set(requestId, { resolve, reject, timeout });
|
|
897
|
-
const request = {
|
|
898
|
-
id: requestId,
|
|
899
|
-
type: "render-route",
|
|
900
|
-
payload
|
|
901
|
-
};
|
|
902
|
-
activeChild.send(request, (error) => {
|
|
903
|
-
if (!error) {
|
|
904
|
-
return;
|
|
905
|
-
}
|
|
906
|
-
const entry = pending.get(requestId);
|
|
907
|
-
if (!entry) {
|
|
908
|
-
return;
|
|
909
|
-
}
|
|
910
|
-
pending.delete(requestId);
|
|
911
|
-
clearTimeout(entry.timeout);
|
|
912
|
-
entry.reject(error instanceof Error ? error : new Error(String(error)));
|
|
913
|
-
});
|
|
914
|
-
});
|
|
915
|
-
},
|
|
916
867
|
renderFromFlightData(payload) {
|
|
917
868
|
const activeChild = startWorker();
|
|
918
869
|
const requestId = nextRequestId++;
|
|
@@ -1156,21 +1107,17 @@ function createNodeRequestHandler(options) {
|
|
|
1156
1107
|
});
|
|
1157
1108
|
let rootHtml = "";
|
|
1158
1109
|
try {
|
|
1159
|
-
rootHtml = await initialHtmlWorker.
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
cookies: requestCookies,
|
|
1163
|
-
basename: basePath
|
|
1110
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1111
|
+
flightData: initialFlightData,
|
|
1112
|
+
moduleMap
|
|
1164
1113
|
});
|
|
1165
1114
|
} catch (error) {
|
|
1166
1115
|
console.error("[webframez-react] Failed to render initial HTML", error);
|
|
1167
1116
|
try {
|
|
1168
1117
|
initialHtmlWorker.dispose();
|
|
1169
|
-
rootHtml = await initialHtmlWorker.
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
cookies: requestCookies,
|
|
1173
|
-
basename: basePath
|
|
1118
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1119
|
+
flightData: initialFlightData,
|
|
1120
|
+
moduleMap
|
|
1174
1121
|
});
|
|
1175
1122
|
} catch (retryError) {
|
|
1176
1123
|
console.error("[webframez-react] Retry for initial HTML failed", retryError);
|
package/dist/webframez-core.js
CHANGED
|
@@ -611,11 +611,6 @@ const Module = require("node:module");
|
|
|
611
611
|
const { Writable } = require("node:stream");
|
|
612
612
|
const { createFromReadableStream } = require("react-server-dom-webpack/client.node");
|
|
613
613
|
|
|
614
|
-
const pagesDir = process.env.WEBFRAMEZ_REACT_PAGES_DIR || "";
|
|
615
|
-
if (!pagesDir) {
|
|
616
|
-
throw new Error("Missing WEBFRAMEZ_REACT_PAGES_DIR");
|
|
617
|
-
}
|
|
618
|
-
|
|
619
614
|
const originalResolveFilename = Module._resolveFilename;
|
|
620
615
|
const rootParent = {
|
|
621
616
|
id: "__webframez_react_worker__",
|
|
@@ -653,12 +648,10 @@ Module._resolveFilename = function(request, parent, isMain, options) {
|
|
|
653
648
|
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
654
649
|
};
|
|
655
650
|
|
|
656
|
-
const { createFileRouter } = require("@webtypen/webframez-react/router");
|
|
657
651
|
const reactDomPkg = require.resolve("react-dom/package.json", {
|
|
658
|
-
paths: [process.cwd()
|
|
652
|
+
paths: [process.cwd()]
|
|
659
653
|
});
|
|
660
654
|
const reactDomServer = require(path.join(path.dirname(reactDomPkg), "server.node.js"));
|
|
661
|
-
const router = createFileRouter({ pagesDir });
|
|
662
655
|
|
|
663
656
|
function renderHtml(model) {
|
|
664
657
|
return new Promise((resolve, reject) => {
|
|
@@ -707,7 +700,7 @@ function createReadableStreamFromString(value) {
|
|
|
707
700
|
}
|
|
708
701
|
|
|
709
702
|
async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
710
|
-
const
|
|
703
|
+
const payload = await createFromReadableStream(createReadableStreamFromString(flightData), {
|
|
711
704
|
serverConsumerManifest: {
|
|
712
705
|
moduleMap: moduleMap || {},
|
|
713
706
|
serverModuleMap: null,
|
|
@@ -715,37 +708,24 @@ async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
|
715
708
|
}
|
|
716
709
|
});
|
|
717
710
|
|
|
711
|
+
const model =
|
|
712
|
+
payload && typeof payload === "object" && "model" in payload
|
|
713
|
+
? payload.model
|
|
714
|
+
: payload;
|
|
715
|
+
|
|
718
716
|
return renderHtml(model);
|
|
719
717
|
}
|
|
720
718
|
|
|
721
719
|
process.on("message", async (message) => {
|
|
722
|
-
if (!message ||
|
|
720
|
+
if (!message || message.type !== "render-flight") {
|
|
723
721
|
return;
|
|
724
722
|
}
|
|
725
723
|
|
|
726
724
|
try {
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
globalThis.__RSC_BASENAME = message.payload.basename || "";
|
|
732
|
-
|
|
733
|
-
try {
|
|
734
|
-
const resolved = await router.resolve({
|
|
735
|
-
pathname: message.payload.pathname,
|
|
736
|
-
searchParams: message.payload.searchParams || {},
|
|
737
|
-
cookies: message.payload.cookies || {},
|
|
738
|
-
});
|
|
739
|
-
html = await renderHtml(resolved.model);
|
|
740
|
-
} finally {
|
|
741
|
-
globalThis.__RSC_BASENAME = previousBasename;
|
|
742
|
-
}
|
|
743
|
-
} else {
|
|
744
|
-
html = await renderHtmlFromFlightData(
|
|
745
|
-
message.payload.flightData || "",
|
|
746
|
-
message.payload.moduleMap || {},
|
|
747
|
-
);
|
|
748
|
-
}
|
|
725
|
+
const html = await renderHtmlFromFlightData(
|
|
726
|
+
message.payload.flightData || "",
|
|
727
|
+
message.payload.moduleMap || {},
|
|
728
|
+
);
|
|
749
729
|
|
|
750
730
|
if (typeof process.send === "function") {
|
|
751
731
|
process.send({ id: message.id, ok: true, html });
|
|
@@ -785,7 +765,7 @@ function sanitizeInitialHtmlWorkerNodeOptions(rawNodeOptions) {
|
|
|
785
765
|
}
|
|
786
766
|
return rawNodeOptions.replace(/(^|\s)--conditions\s+react-server(?=\s|$)/g, " ").replace(/(^|\s)-r\s+(\S*webframez-react\/register)(?=\s|$)/g, " ").replace(/\s+/g, " ").trim();
|
|
787
767
|
}
|
|
788
|
-
function createInitialHtmlWorker(
|
|
768
|
+
function createInitialHtmlWorker(_pagesDir) {
|
|
789
769
|
let child = null;
|
|
790
770
|
let nextRequestId = 1;
|
|
791
771
|
let stderrBuffer = "";
|
|
@@ -816,8 +796,7 @@ function createInitialHtmlWorker(pagesDir) {
|
|
|
816
796
|
cwd: process.cwd(),
|
|
817
797
|
env: {
|
|
818
798
|
...process.env,
|
|
819
|
-
NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
|
|
820
|
-
WEBFRAMEZ_REACT_PAGES_DIR: pagesDir
|
|
799
|
+
NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
|
|
821
800
|
},
|
|
822
801
|
stdio: ["ignore", "ignore", "pipe", "ipc"]
|
|
823
802
|
});
|
|
@@ -857,34 +836,6 @@ ${stderrBuffer.trim()}` : "";
|
|
|
857
836
|
return child;
|
|
858
837
|
};
|
|
859
838
|
return {
|
|
860
|
-
render(payload) {
|
|
861
|
-
const activeChild = startWorker();
|
|
862
|
-
const requestId = nextRequestId++;
|
|
863
|
-
return new Promise((resolve, reject) => {
|
|
864
|
-
const timeout = setTimeout(() => {
|
|
865
|
-
rejectPending(new Error("[webframez-react] Initial HTML worker timed out"));
|
|
866
|
-
stopWorker();
|
|
867
|
-
}, 1e4);
|
|
868
|
-
pending.set(requestId, { resolve, reject, timeout });
|
|
869
|
-
const request = {
|
|
870
|
-
id: requestId,
|
|
871
|
-
type: "render-route",
|
|
872
|
-
payload
|
|
873
|
-
};
|
|
874
|
-
activeChild.send(request, (error) => {
|
|
875
|
-
if (!error) {
|
|
876
|
-
return;
|
|
877
|
-
}
|
|
878
|
-
const entry = pending.get(requestId);
|
|
879
|
-
if (!entry) {
|
|
880
|
-
return;
|
|
881
|
-
}
|
|
882
|
-
pending.delete(requestId);
|
|
883
|
-
clearTimeout(entry.timeout);
|
|
884
|
-
entry.reject(error instanceof Error ? error : new Error(String(error)));
|
|
885
|
-
});
|
|
886
|
-
});
|
|
887
|
-
},
|
|
888
839
|
renderFromFlightData(payload) {
|
|
889
840
|
const activeChild = startWorker();
|
|
890
841
|
const requestId = nextRequestId++;
|
|
@@ -1128,21 +1079,17 @@ function createNodeRequestHandler(options) {
|
|
|
1128
1079
|
});
|
|
1129
1080
|
let rootHtml = "";
|
|
1130
1081
|
try {
|
|
1131
|
-
rootHtml = await initialHtmlWorker.
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
cookies: requestCookies,
|
|
1135
|
-
basename: basePath
|
|
1082
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1083
|
+
flightData: initialFlightData,
|
|
1084
|
+
moduleMap
|
|
1136
1085
|
});
|
|
1137
1086
|
} catch (error) {
|
|
1138
1087
|
console.error("[webframez-react] Failed to render initial HTML", error);
|
|
1139
1088
|
try {
|
|
1140
1089
|
initialHtmlWorker.dispose();
|
|
1141
|
-
rootHtml = await initialHtmlWorker.
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
cookies: requestCookies,
|
|
1145
|
-
basename: basePath
|
|
1090
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1091
|
+
flightData: initialFlightData,
|
|
1092
|
+
moduleMap
|
|
1146
1093
|
});
|
|
1147
1094
|
} catch (retryError) {
|
|
1148
1095
|
console.error("[webframez-react] Retry for initial HTML failed", retryError);
|