@webtypen/webframez-react 0.0.16 → 0.0.18
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 +83 -86
- package/dist/http.js +83 -86
- package/dist/index.cjs +83 -86
- package/dist/index.js +83 -86
- package/dist/router.cjs +7 -4
- package/dist/router.js +7 -4
- package/dist/webframez-core.cjs +83 -86
- package/dist/webframez-core.js +83 -86
- package/package.json +1 -1
package/dist/webframez-core.cjs
CHANGED
|
@@ -134,28 +134,6 @@ function renderRSCToString(payload, options = {}) {
|
|
|
134
134
|
stream.pipe(writable);
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
|
-
function createReadableStreamFromString(value) {
|
|
138
|
-
const encoder = new TextEncoder();
|
|
139
|
-
return new ReadableStream({
|
|
140
|
-
start(controller) {
|
|
141
|
-
controller.enqueue(encoder.encode(value));
|
|
142
|
-
controller.close();
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
async function renderHtmlFromFlightData(flightData, options) {
|
|
147
|
-
const appRequire = (0, import_node_module.createRequire)(import_node_path.default.join(process.cwd(), "__webframez_react_server__.js"));
|
|
148
|
-
const reactDomPkg = appRequire.resolve("react-dom/package.json");
|
|
149
|
-
const { renderToString } = appRequire(import_node_path.default.join(import_node_path.default.dirname(reactDomPkg), "server.node.js"));
|
|
150
|
-
const model = await (0, import_client.createFromReadableStream)(createReadableStreamFromString(flightData), {
|
|
151
|
-
serverConsumerManifest: {
|
|
152
|
-
moduleMap: options.moduleMap ?? {},
|
|
153
|
-
serverModuleMap: null,
|
|
154
|
-
moduleLoading: null
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
return renderToString(model);
|
|
158
|
-
}
|
|
159
137
|
function sendRSC(res, model, options = {}) {
|
|
160
138
|
const {
|
|
161
139
|
moduleMap = {},
|
|
@@ -235,9 +213,6 @@ function injectRouteChildren(node, routeChildren) {
|
|
|
235
213
|
|
|
236
214
|
// src/file-router.tsx
|
|
237
215
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
238
|
-
var ROOT_RUNTIME_REQUIRE = import_node_module2.default.createRequire(
|
|
239
|
-
import_node_path2.default.join(process.cwd(), "__webframez_react_runtime__.js")
|
|
240
|
-
);
|
|
241
216
|
var FORCED_PACKAGE_REQUESTS = [
|
|
242
217
|
"@webtypen/webframez-core",
|
|
243
218
|
"@webtypen/webframez-react",
|
|
@@ -314,10 +289,16 @@ function installForcedPackageResolution() {
|
|
|
314
289
|
}
|
|
315
290
|
const moduleWithPrivateResolver = import_node_module2.default;
|
|
316
291
|
const originalResolveFilename = moduleWithPrivateResolver._resolveFilename;
|
|
292
|
+
const rootParent = {
|
|
293
|
+
id: "__webframez_react_runtime__",
|
|
294
|
+
filename: import_node_path2.default.join(process.cwd(), "__webframez_react_runtime__.js"),
|
|
295
|
+
path: process.cwd(),
|
|
296
|
+
paths: moduleWithPrivateResolver._nodeModulePaths(process.cwd())
|
|
297
|
+
};
|
|
317
298
|
moduleWithPrivateResolver._resolveFilename = function patchedResolveFilename(request, parent, isMain, options) {
|
|
318
299
|
if (typeof request === "string" && shouldForcePackageResolution(request)) {
|
|
319
300
|
try {
|
|
320
|
-
return
|
|
301
|
+
return originalResolveFilename.call(this, request, rootParent, false, options);
|
|
321
302
|
} catch {
|
|
322
303
|
}
|
|
323
304
|
}
|
|
@@ -656,49 +637,49 @@ var INITIAL_HTML_WORKER_SCRIPT = `
|
|
|
656
637
|
const path = require("node:path");
|
|
657
638
|
const Module = require("node:module");
|
|
658
639
|
const { Writable } = require("node:stream");
|
|
640
|
+
const { createFromReadableStream } = require("react-server-dom-webpack/client.node");
|
|
659
641
|
|
|
660
|
-
const pagesDir = process.env.WEBFRAMEZ_REACT_PAGES_DIR || "";
|
|
661
|
-
if (!pagesDir) {
|
|
662
|
-
throw new Error("Missing WEBFRAMEZ_REACT_PAGES_DIR");
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
const rootRequire = Module.createRequire(path.join(process.cwd(), "__webframez_react_worker__.js"));
|
|
666
642
|
const originalResolveFilename = Module._resolveFilename;
|
|
667
|
-
const
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
643
|
+
const rootParent = {
|
|
644
|
+
id: "__webframez_react_worker__",
|
|
645
|
+
filename: path.join(process.cwd(), "__webframez_react_worker__.js"),
|
|
646
|
+
path: process.cwd(),
|
|
647
|
+
paths: Module._nodeModulePaths(process.cwd()),
|
|
648
|
+
};
|
|
649
|
+
const forcedPackageRequests = [
|
|
650
|
+
"@webtypen/webframez-core",
|
|
651
|
+
"@webtypen/webframez-react",
|
|
652
|
+
"react",
|
|
653
|
+
"react/jsx-runtime",
|
|
654
|
+
"react/jsx-dev-runtime",
|
|
655
|
+
"react-dom",
|
|
656
|
+
"react-dom/client",
|
|
657
|
+
"react-dom/server",
|
|
658
|
+
"react-dom/server.node",
|
|
659
|
+
"react-server-dom-webpack",
|
|
660
|
+
"react-server-dom-webpack/server",
|
|
661
|
+
"react-server-dom-webpack/client",
|
|
662
|
+
"react-server-dom-webpack/client.node",
|
|
663
|
+
"scheduler"
|
|
664
|
+
];
|
|
665
|
+
|
|
666
|
+
function shouldForcePackageResolution(request) {
|
|
667
|
+
return forcedPackageRequests.some((candidate) =>
|
|
668
|
+
request === candidate || request.startsWith(candidate + "/")
|
|
669
|
+
);
|
|
670
|
+
}
|
|
683
671
|
|
|
684
672
|
Module._resolveFilename = function(request, parent, isMain, options) {
|
|
685
|
-
if (
|
|
686
|
-
return
|
|
687
|
-
}
|
|
688
|
-
for (const forcedRequest of forcedResolutions.keys()) {
|
|
689
|
-
if (request.startsWith(forcedRequest + "/")) {
|
|
690
|
-
return rootRequire.resolve(request);
|
|
691
|
-
}
|
|
673
|
+
if (typeof request === "string" && shouldForcePackageResolution(request)) {
|
|
674
|
+
return originalResolveFilename.call(this, request, rootParent, false, options);
|
|
692
675
|
}
|
|
693
676
|
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
694
677
|
};
|
|
695
678
|
|
|
696
|
-
const { createFileRouter } = require("@webtypen/webframez-react/router");
|
|
697
679
|
const reactDomPkg = require.resolve("react-dom/package.json", {
|
|
698
|
-
paths: [process.cwd()
|
|
680
|
+
paths: [process.cwd()]
|
|
699
681
|
});
|
|
700
682
|
const reactDomServer = require(path.join(path.dirname(reactDomPkg), "server.node.js"));
|
|
701
|
-
const router = createFileRouter({ pagesDir });
|
|
702
683
|
|
|
703
684
|
function renderHtml(model) {
|
|
704
685
|
return new Promise((resolve, reject) => {
|
|
@@ -735,21 +716,40 @@ function renderHtml(model) {
|
|
|
735
716
|
});
|
|
736
717
|
}
|
|
737
718
|
|
|
719
|
+
function createReadableStreamFromString(value) {
|
|
720
|
+
const encoder = new TextEncoder();
|
|
721
|
+
|
|
722
|
+
return new ReadableStream({
|
|
723
|
+
start(controller) {
|
|
724
|
+
controller.enqueue(encoder.encode(value));
|
|
725
|
+
controller.close();
|
|
726
|
+
}
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
731
|
+
const model = await createFromReadableStream(createReadableStreamFromString(flightData), {
|
|
732
|
+
serverConsumerManifest: {
|
|
733
|
+
moduleMap: moduleMap || {},
|
|
734
|
+
serverModuleMap: null,
|
|
735
|
+
moduleLoading: null
|
|
736
|
+
}
|
|
737
|
+
});
|
|
738
|
+
|
|
739
|
+
return renderHtml(model);
|
|
740
|
+
}
|
|
741
|
+
|
|
738
742
|
process.on("message", async (message) => {
|
|
739
|
-
if (!message || message.type !== "render") {
|
|
743
|
+
if (!message || message.type !== "render-flight") {
|
|
740
744
|
return;
|
|
741
745
|
}
|
|
742
746
|
|
|
743
|
-
const previousBasename = globalThis.__RSC_BASENAME;
|
|
744
|
-
globalThis.__RSC_BASENAME = message.payload.basename || "";
|
|
745
|
-
|
|
746
747
|
try {
|
|
747
|
-
const
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
const html = await renderHtml(resolved.model);
|
|
748
|
+
const html = await renderHtmlFromFlightData(
|
|
749
|
+
message.payload.flightData || "",
|
|
750
|
+
message.payload.moduleMap || {},
|
|
751
|
+
);
|
|
752
|
+
|
|
753
753
|
if (typeof process.send === "function") {
|
|
754
754
|
process.send({ id: message.id, ok: true, html });
|
|
755
755
|
}
|
|
@@ -760,8 +760,6 @@ process.on("message", async (message) => {
|
|
|
760
760
|
if (typeof process.send === "function") {
|
|
761
761
|
process.send({ id: message.id, ok: false, error: formatted });
|
|
762
762
|
}
|
|
763
|
-
} finally {
|
|
764
|
-
globalThis.__RSC_BASENAME = previousBasename;
|
|
765
763
|
}
|
|
766
764
|
});
|
|
767
765
|
`;
|
|
@@ -790,7 +788,7 @@ function sanitizeInitialHtmlWorkerNodeOptions(rawNodeOptions) {
|
|
|
790
788
|
}
|
|
791
789
|
return rawNodeOptions.replace(/(^|\s)--conditions\s+react-server(?=\s|$)/g, " ").replace(/(^|\s)-r\s+(\S*webframez-react\/register)(?=\s|$)/g, " ").replace(/\s+/g, " ").trim();
|
|
792
790
|
}
|
|
793
|
-
function createInitialHtmlWorker(
|
|
791
|
+
function createInitialHtmlWorker(_pagesDir) {
|
|
794
792
|
let child = null;
|
|
795
793
|
let nextRequestId = 1;
|
|
796
794
|
let stderrBuffer = "";
|
|
@@ -821,8 +819,7 @@ function createInitialHtmlWorker(pagesDir) {
|
|
|
821
819
|
cwd: process.cwd(),
|
|
822
820
|
env: {
|
|
823
821
|
...process.env,
|
|
824
|
-
NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
|
|
825
|
-
WEBFRAMEZ_REACT_PAGES_DIR: pagesDir
|
|
822
|
+
NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
|
|
826
823
|
},
|
|
827
824
|
stdio: ["ignore", "ignore", "pipe", "ipc"]
|
|
828
825
|
});
|
|
@@ -862,7 +859,7 @@ ${stderrBuffer.trim()}` : "";
|
|
|
862
859
|
return child;
|
|
863
860
|
};
|
|
864
861
|
return {
|
|
865
|
-
|
|
862
|
+
renderFromFlightData(payload) {
|
|
866
863
|
const activeChild = startWorker();
|
|
867
864
|
const requestId = nextRequestId++;
|
|
868
865
|
return new Promise((resolve, reject) => {
|
|
@@ -873,7 +870,7 @@ ${stderrBuffer.trim()}` : "";
|
|
|
873
870
|
pending.set(requestId, { resolve, reject, timeout });
|
|
874
871
|
const request = {
|
|
875
872
|
id: requestId,
|
|
876
|
-
type: "render",
|
|
873
|
+
type: "render-flight",
|
|
877
874
|
payload
|
|
878
875
|
};
|
|
879
876
|
activeChild.send(request, (error) => {
|
|
@@ -1105,26 +1102,26 @@ function createNodeRequestHandler(options) {
|
|
|
1105
1102
|
});
|
|
1106
1103
|
let rootHtml = "";
|
|
1107
1104
|
try {
|
|
1108
|
-
rootHtml = await initialHtmlWorker.
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
cookies: requestCookies,
|
|
1112
|
-
basename: basePath
|
|
1105
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1106
|
+
flightData: initialFlightData,
|
|
1107
|
+
moduleMap
|
|
1113
1108
|
});
|
|
1114
1109
|
} catch (error) {
|
|
1115
1110
|
console.error("[webframez-react] Failed to render initial HTML", error);
|
|
1116
1111
|
try {
|
|
1117
1112
|
initialHtmlWorker.dispose();
|
|
1118
|
-
rootHtml = await initialHtmlWorker.
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
cookies: requestCookies,
|
|
1122
|
-
basename: basePath
|
|
1113
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1114
|
+
flightData: initialFlightData,
|
|
1115
|
+
moduleMap
|
|
1123
1116
|
});
|
|
1124
1117
|
} catch (retryError) {
|
|
1125
1118
|
console.error("[webframez-react] Retry for initial HTML failed", retryError);
|
|
1126
1119
|
try {
|
|
1127
|
-
|
|
1120
|
+
initialHtmlWorker.dispose();
|
|
1121
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1122
|
+
flightData: initialFlightData,
|
|
1123
|
+
moduleMap
|
|
1124
|
+
});
|
|
1128
1125
|
} catch (flightRenderError) {
|
|
1129
1126
|
console.error("[webframez-react] Flight-to-HTML render failed", flightRenderError);
|
|
1130
1127
|
res.statusCode = 500;
|
package/dist/webframez-core.js
CHANGED
|
@@ -106,28 +106,6 @@ function renderRSCToString(payload, options = {}) {
|
|
|
106
106
|
stream.pipe(writable);
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
|
-
function createReadableStreamFromString(value) {
|
|
110
|
-
const encoder = new TextEncoder();
|
|
111
|
-
return new ReadableStream({
|
|
112
|
-
start(controller) {
|
|
113
|
-
controller.enqueue(encoder.encode(value));
|
|
114
|
-
controller.close();
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
async function renderHtmlFromFlightData(flightData, options) {
|
|
119
|
-
const appRequire = createRequire(path.join(process.cwd(), "__webframez_react_server__.js"));
|
|
120
|
-
const reactDomPkg = appRequire.resolve("react-dom/package.json");
|
|
121
|
-
const { renderToString } = appRequire(path.join(path.dirname(reactDomPkg), "server.node.js"));
|
|
122
|
-
const model = await createFromReadableStream(createReadableStreamFromString(flightData), {
|
|
123
|
-
serverConsumerManifest: {
|
|
124
|
-
moduleMap: options.moduleMap ?? {},
|
|
125
|
-
serverModuleMap: null,
|
|
126
|
-
moduleLoading: null
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
return renderToString(model);
|
|
130
|
-
}
|
|
131
109
|
function sendRSC(res, model, options = {}) {
|
|
132
110
|
const {
|
|
133
111
|
moduleMap = {},
|
|
@@ -207,9 +185,6 @@ function injectRouteChildren(node, routeChildren) {
|
|
|
207
185
|
|
|
208
186
|
// src/file-router.tsx
|
|
209
187
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
210
|
-
var ROOT_RUNTIME_REQUIRE = Module.createRequire(
|
|
211
|
-
path2.join(process.cwd(), "__webframez_react_runtime__.js")
|
|
212
|
-
);
|
|
213
188
|
var FORCED_PACKAGE_REQUESTS = [
|
|
214
189
|
"@webtypen/webframez-core",
|
|
215
190
|
"@webtypen/webframez-react",
|
|
@@ -286,10 +261,16 @@ function installForcedPackageResolution() {
|
|
|
286
261
|
}
|
|
287
262
|
const moduleWithPrivateResolver = Module;
|
|
288
263
|
const originalResolveFilename = moduleWithPrivateResolver._resolveFilename;
|
|
264
|
+
const rootParent = {
|
|
265
|
+
id: "__webframez_react_runtime__",
|
|
266
|
+
filename: path2.join(process.cwd(), "__webframez_react_runtime__.js"),
|
|
267
|
+
path: process.cwd(),
|
|
268
|
+
paths: moduleWithPrivateResolver._nodeModulePaths(process.cwd())
|
|
269
|
+
};
|
|
289
270
|
moduleWithPrivateResolver._resolveFilename = function patchedResolveFilename(request, parent, isMain, options) {
|
|
290
271
|
if (typeof request === "string" && shouldForcePackageResolution(request)) {
|
|
291
272
|
try {
|
|
292
|
-
return
|
|
273
|
+
return originalResolveFilename.call(this, request, rootParent, false, options);
|
|
293
274
|
} catch {
|
|
294
275
|
}
|
|
295
276
|
}
|
|
@@ -628,49 +609,49 @@ var INITIAL_HTML_WORKER_SCRIPT = `
|
|
|
628
609
|
const path = require("node:path");
|
|
629
610
|
const Module = require("node:module");
|
|
630
611
|
const { Writable } = require("node:stream");
|
|
612
|
+
const { createFromReadableStream } = require("react-server-dom-webpack/client.node");
|
|
631
613
|
|
|
632
|
-
const pagesDir = process.env.WEBFRAMEZ_REACT_PAGES_DIR || "";
|
|
633
|
-
if (!pagesDir) {
|
|
634
|
-
throw new Error("Missing WEBFRAMEZ_REACT_PAGES_DIR");
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
const rootRequire = Module.createRequire(path.join(process.cwd(), "__webframez_react_worker__.js"));
|
|
638
614
|
const originalResolveFilename = Module._resolveFilename;
|
|
639
|
-
const
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
615
|
+
const rootParent = {
|
|
616
|
+
id: "__webframez_react_worker__",
|
|
617
|
+
filename: path.join(process.cwd(), "__webframez_react_worker__.js"),
|
|
618
|
+
path: process.cwd(),
|
|
619
|
+
paths: Module._nodeModulePaths(process.cwd()),
|
|
620
|
+
};
|
|
621
|
+
const forcedPackageRequests = [
|
|
622
|
+
"@webtypen/webframez-core",
|
|
623
|
+
"@webtypen/webframez-react",
|
|
624
|
+
"react",
|
|
625
|
+
"react/jsx-runtime",
|
|
626
|
+
"react/jsx-dev-runtime",
|
|
627
|
+
"react-dom",
|
|
628
|
+
"react-dom/client",
|
|
629
|
+
"react-dom/server",
|
|
630
|
+
"react-dom/server.node",
|
|
631
|
+
"react-server-dom-webpack",
|
|
632
|
+
"react-server-dom-webpack/server",
|
|
633
|
+
"react-server-dom-webpack/client",
|
|
634
|
+
"react-server-dom-webpack/client.node",
|
|
635
|
+
"scheduler"
|
|
636
|
+
];
|
|
637
|
+
|
|
638
|
+
function shouldForcePackageResolution(request) {
|
|
639
|
+
return forcedPackageRequests.some((candidate) =>
|
|
640
|
+
request === candidate || request.startsWith(candidate + "/")
|
|
641
|
+
);
|
|
642
|
+
}
|
|
655
643
|
|
|
656
644
|
Module._resolveFilename = function(request, parent, isMain, options) {
|
|
657
|
-
if (
|
|
658
|
-
return
|
|
659
|
-
}
|
|
660
|
-
for (const forcedRequest of forcedResolutions.keys()) {
|
|
661
|
-
if (request.startsWith(forcedRequest + "/")) {
|
|
662
|
-
return rootRequire.resolve(request);
|
|
663
|
-
}
|
|
645
|
+
if (typeof request === "string" && shouldForcePackageResolution(request)) {
|
|
646
|
+
return originalResolveFilename.call(this, request, rootParent, false, options);
|
|
664
647
|
}
|
|
665
648
|
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
666
649
|
};
|
|
667
650
|
|
|
668
|
-
const { createFileRouter } = require("@webtypen/webframez-react/router");
|
|
669
651
|
const reactDomPkg = require.resolve("react-dom/package.json", {
|
|
670
|
-
paths: [process.cwd()
|
|
652
|
+
paths: [process.cwd()]
|
|
671
653
|
});
|
|
672
654
|
const reactDomServer = require(path.join(path.dirname(reactDomPkg), "server.node.js"));
|
|
673
|
-
const router = createFileRouter({ pagesDir });
|
|
674
655
|
|
|
675
656
|
function renderHtml(model) {
|
|
676
657
|
return new Promise((resolve, reject) => {
|
|
@@ -707,21 +688,40 @@ function renderHtml(model) {
|
|
|
707
688
|
});
|
|
708
689
|
}
|
|
709
690
|
|
|
691
|
+
function createReadableStreamFromString(value) {
|
|
692
|
+
const encoder = new TextEncoder();
|
|
693
|
+
|
|
694
|
+
return new ReadableStream({
|
|
695
|
+
start(controller) {
|
|
696
|
+
controller.enqueue(encoder.encode(value));
|
|
697
|
+
controller.close();
|
|
698
|
+
}
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
703
|
+
const model = await createFromReadableStream(createReadableStreamFromString(flightData), {
|
|
704
|
+
serverConsumerManifest: {
|
|
705
|
+
moduleMap: moduleMap || {},
|
|
706
|
+
serverModuleMap: null,
|
|
707
|
+
moduleLoading: null
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
return renderHtml(model);
|
|
712
|
+
}
|
|
713
|
+
|
|
710
714
|
process.on("message", async (message) => {
|
|
711
|
-
if (!message || message.type !== "render") {
|
|
715
|
+
if (!message || message.type !== "render-flight") {
|
|
712
716
|
return;
|
|
713
717
|
}
|
|
714
718
|
|
|
715
|
-
const previousBasename = globalThis.__RSC_BASENAME;
|
|
716
|
-
globalThis.__RSC_BASENAME = message.payload.basename || "";
|
|
717
|
-
|
|
718
719
|
try {
|
|
719
|
-
const
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
const html = await renderHtml(resolved.model);
|
|
720
|
+
const html = await renderHtmlFromFlightData(
|
|
721
|
+
message.payload.flightData || "",
|
|
722
|
+
message.payload.moduleMap || {},
|
|
723
|
+
);
|
|
724
|
+
|
|
725
725
|
if (typeof process.send === "function") {
|
|
726
726
|
process.send({ id: message.id, ok: true, html });
|
|
727
727
|
}
|
|
@@ -732,8 +732,6 @@ process.on("message", async (message) => {
|
|
|
732
732
|
if (typeof process.send === "function") {
|
|
733
733
|
process.send({ id: message.id, ok: false, error: formatted });
|
|
734
734
|
}
|
|
735
|
-
} finally {
|
|
736
|
-
globalThis.__RSC_BASENAME = previousBasename;
|
|
737
735
|
}
|
|
738
736
|
});
|
|
739
737
|
`;
|
|
@@ -762,7 +760,7 @@ function sanitizeInitialHtmlWorkerNodeOptions(rawNodeOptions) {
|
|
|
762
760
|
}
|
|
763
761
|
return rawNodeOptions.replace(/(^|\s)--conditions\s+react-server(?=\s|$)/g, " ").replace(/(^|\s)-r\s+(\S*webframez-react\/register)(?=\s|$)/g, " ").replace(/\s+/g, " ").trim();
|
|
764
762
|
}
|
|
765
|
-
function createInitialHtmlWorker(
|
|
763
|
+
function createInitialHtmlWorker(_pagesDir) {
|
|
766
764
|
let child = null;
|
|
767
765
|
let nextRequestId = 1;
|
|
768
766
|
let stderrBuffer = "";
|
|
@@ -793,8 +791,7 @@ function createInitialHtmlWorker(pagesDir) {
|
|
|
793
791
|
cwd: process.cwd(),
|
|
794
792
|
env: {
|
|
795
793
|
...process.env,
|
|
796
|
-
NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
|
|
797
|
-
WEBFRAMEZ_REACT_PAGES_DIR: pagesDir
|
|
794
|
+
NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
|
|
798
795
|
},
|
|
799
796
|
stdio: ["ignore", "ignore", "pipe", "ipc"]
|
|
800
797
|
});
|
|
@@ -834,7 +831,7 @@ ${stderrBuffer.trim()}` : "";
|
|
|
834
831
|
return child;
|
|
835
832
|
};
|
|
836
833
|
return {
|
|
837
|
-
|
|
834
|
+
renderFromFlightData(payload) {
|
|
838
835
|
const activeChild = startWorker();
|
|
839
836
|
const requestId = nextRequestId++;
|
|
840
837
|
return new Promise((resolve, reject) => {
|
|
@@ -845,7 +842,7 @@ ${stderrBuffer.trim()}` : "";
|
|
|
845
842
|
pending.set(requestId, { resolve, reject, timeout });
|
|
846
843
|
const request = {
|
|
847
844
|
id: requestId,
|
|
848
|
-
type: "render",
|
|
845
|
+
type: "render-flight",
|
|
849
846
|
payload
|
|
850
847
|
};
|
|
851
848
|
activeChild.send(request, (error) => {
|
|
@@ -1077,26 +1074,26 @@ function createNodeRequestHandler(options) {
|
|
|
1077
1074
|
});
|
|
1078
1075
|
let rootHtml = "";
|
|
1079
1076
|
try {
|
|
1080
|
-
rootHtml = await initialHtmlWorker.
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
cookies: requestCookies,
|
|
1084
|
-
basename: basePath
|
|
1077
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1078
|
+
flightData: initialFlightData,
|
|
1079
|
+
moduleMap
|
|
1085
1080
|
});
|
|
1086
1081
|
} catch (error) {
|
|
1087
1082
|
console.error("[webframez-react] Failed to render initial HTML", error);
|
|
1088
1083
|
try {
|
|
1089
1084
|
initialHtmlWorker.dispose();
|
|
1090
|
-
rootHtml = await initialHtmlWorker.
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
cookies: requestCookies,
|
|
1094
|
-
basename: basePath
|
|
1085
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1086
|
+
flightData: initialFlightData,
|
|
1087
|
+
moduleMap
|
|
1095
1088
|
});
|
|
1096
1089
|
} catch (retryError) {
|
|
1097
1090
|
console.error("[webframez-react] Retry for initial HTML failed", retryError);
|
|
1098
1091
|
try {
|
|
1099
|
-
|
|
1092
|
+
initialHtmlWorker.dispose();
|
|
1093
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1094
|
+
flightData: initialFlightData,
|
|
1095
|
+
moduleMap
|
|
1096
|
+
});
|
|
1100
1097
|
} catch (flightRenderError) {
|
|
1101
1098
|
console.error("[webframez-react] Flight-to-HTML render failed", flightRenderError);
|
|
1102
1099
|
res.statusCode = 500;
|