@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/http.cjs
CHANGED
|
@@ -131,28 +131,6 @@ function renderRSCToString(payload, options = {}) {
|
|
|
131
131
|
stream.pipe(writable);
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
|
-
function createReadableStreamFromString(value) {
|
|
135
|
-
const encoder = new TextEncoder();
|
|
136
|
-
return new ReadableStream({
|
|
137
|
-
start(controller) {
|
|
138
|
-
controller.enqueue(encoder.encode(value));
|
|
139
|
-
controller.close();
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
async function renderHtmlFromFlightData(flightData, options) {
|
|
144
|
-
const appRequire = (0, import_node_module.createRequire)(import_node_path.default.join(process.cwd(), "__webframez_react_server__.js"));
|
|
145
|
-
const reactDomPkg = appRequire.resolve("react-dom/package.json");
|
|
146
|
-
const { renderToString } = appRequire(import_node_path.default.join(import_node_path.default.dirname(reactDomPkg), "server.node.js"));
|
|
147
|
-
const model = await (0, import_client.createFromReadableStream)(createReadableStreamFromString(flightData), {
|
|
148
|
-
serverConsumerManifest: {
|
|
149
|
-
moduleMap: options.moduleMap ?? {},
|
|
150
|
-
serverModuleMap: null,
|
|
151
|
-
moduleLoading: null
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
return renderToString(model);
|
|
155
|
-
}
|
|
156
134
|
function sendRSC(res, model, options = {}) {
|
|
157
135
|
const {
|
|
158
136
|
moduleMap = {},
|
|
@@ -232,9 +210,6 @@ function injectRouteChildren(node, routeChildren) {
|
|
|
232
210
|
|
|
233
211
|
// src/file-router.tsx
|
|
234
212
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
235
|
-
var ROOT_RUNTIME_REQUIRE = import_node_module2.default.createRequire(
|
|
236
|
-
import_node_path2.default.join(process.cwd(), "__webframez_react_runtime__.js")
|
|
237
|
-
);
|
|
238
213
|
var FORCED_PACKAGE_REQUESTS = [
|
|
239
214
|
"@webtypen/webframez-core",
|
|
240
215
|
"@webtypen/webframez-react",
|
|
@@ -311,10 +286,16 @@ function installForcedPackageResolution() {
|
|
|
311
286
|
}
|
|
312
287
|
const moduleWithPrivateResolver = import_node_module2.default;
|
|
313
288
|
const originalResolveFilename = moduleWithPrivateResolver._resolveFilename;
|
|
289
|
+
const rootParent = {
|
|
290
|
+
id: "__webframez_react_runtime__",
|
|
291
|
+
filename: import_node_path2.default.join(process.cwd(), "__webframez_react_runtime__.js"),
|
|
292
|
+
path: process.cwd(),
|
|
293
|
+
paths: moduleWithPrivateResolver._nodeModulePaths(process.cwd())
|
|
294
|
+
};
|
|
314
295
|
moduleWithPrivateResolver._resolveFilename = function patchedResolveFilename(request, parent, isMain, options) {
|
|
315
296
|
if (typeof request === "string" && shouldForcePackageResolution(request)) {
|
|
316
297
|
try {
|
|
317
|
-
return
|
|
298
|
+
return originalResolveFilename.call(this, request, rootParent, false, options);
|
|
318
299
|
} catch {
|
|
319
300
|
}
|
|
320
301
|
}
|
|
@@ -653,49 +634,49 @@ var INITIAL_HTML_WORKER_SCRIPT = `
|
|
|
653
634
|
const path = require("node:path");
|
|
654
635
|
const Module = require("node:module");
|
|
655
636
|
const { Writable } = require("node:stream");
|
|
637
|
+
const { createFromReadableStream } = require("react-server-dom-webpack/client.node");
|
|
656
638
|
|
|
657
|
-
const pagesDir = process.env.WEBFRAMEZ_REACT_PAGES_DIR || "";
|
|
658
|
-
if (!pagesDir) {
|
|
659
|
-
throw new Error("Missing WEBFRAMEZ_REACT_PAGES_DIR");
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
const rootRequire = Module.createRequire(path.join(process.cwd(), "__webframez_react_worker__.js"));
|
|
663
639
|
const originalResolveFilename = Module._resolveFilename;
|
|
664
|
-
const
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
640
|
+
const rootParent = {
|
|
641
|
+
id: "__webframez_react_worker__",
|
|
642
|
+
filename: path.join(process.cwd(), "__webframez_react_worker__.js"),
|
|
643
|
+
path: process.cwd(),
|
|
644
|
+
paths: Module._nodeModulePaths(process.cwd()),
|
|
645
|
+
};
|
|
646
|
+
const forcedPackageRequests = [
|
|
647
|
+
"@webtypen/webframez-core",
|
|
648
|
+
"@webtypen/webframez-react",
|
|
649
|
+
"react",
|
|
650
|
+
"react/jsx-runtime",
|
|
651
|
+
"react/jsx-dev-runtime",
|
|
652
|
+
"react-dom",
|
|
653
|
+
"react-dom/client",
|
|
654
|
+
"react-dom/server",
|
|
655
|
+
"react-dom/server.node",
|
|
656
|
+
"react-server-dom-webpack",
|
|
657
|
+
"react-server-dom-webpack/server",
|
|
658
|
+
"react-server-dom-webpack/client",
|
|
659
|
+
"react-server-dom-webpack/client.node",
|
|
660
|
+
"scheduler"
|
|
661
|
+
];
|
|
662
|
+
|
|
663
|
+
function shouldForcePackageResolution(request) {
|
|
664
|
+
return forcedPackageRequests.some((candidate) =>
|
|
665
|
+
request === candidate || request.startsWith(candidate + "/")
|
|
666
|
+
);
|
|
667
|
+
}
|
|
680
668
|
|
|
681
669
|
Module._resolveFilename = function(request, parent, isMain, options) {
|
|
682
|
-
if (
|
|
683
|
-
return
|
|
684
|
-
}
|
|
685
|
-
for (const forcedRequest of forcedResolutions.keys()) {
|
|
686
|
-
if (request.startsWith(forcedRequest + "/")) {
|
|
687
|
-
return rootRequire.resolve(request);
|
|
688
|
-
}
|
|
670
|
+
if (typeof request === "string" && shouldForcePackageResolution(request)) {
|
|
671
|
+
return originalResolveFilename.call(this, request, rootParent, false, options);
|
|
689
672
|
}
|
|
690
673
|
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
691
674
|
};
|
|
692
675
|
|
|
693
|
-
const { createFileRouter } = require("@webtypen/webframez-react/router");
|
|
694
676
|
const reactDomPkg = require.resolve("react-dom/package.json", {
|
|
695
|
-
paths: [process.cwd()
|
|
677
|
+
paths: [process.cwd()]
|
|
696
678
|
});
|
|
697
679
|
const reactDomServer = require(path.join(path.dirname(reactDomPkg), "server.node.js"));
|
|
698
|
-
const router = createFileRouter({ pagesDir });
|
|
699
680
|
|
|
700
681
|
function renderHtml(model) {
|
|
701
682
|
return new Promise((resolve, reject) => {
|
|
@@ -732,21 +713,40 @@ function renderHtml(model) {
|
|
|
732
713
|
});
|
|
733
714
|
}
|
|
734
715
|
|
|
716
|
+
function createReadableStreamFromString(value) {
|
|
717
|
+
const encoder = new TextEncoder();
|
|
718
|
+
|
|
719
|
+
return new ReadableStream({
|
|
720
|
+
start(controller) {
|
|
721
|
+
controller.enqueue(encoder.encode(value));
|
|
722
|
+
controller.close();
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
728
|
+
const model = await createFromReadableStream(createReadableStreamFromString(flightData), {
|
|
729
|
+
serverConsumerManifest: {
|
|
730
|
+
moduleMap: moduleMap || {},
|
|
731
|
+
serverModuleMap: null,
|
|
732
|
+
moduleLoading: null
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
return renderHtml(model);
|
|
737
|
+
}
|
|
738
|
+
|
|
735
739
|
process.on("message", async (message) => {
|
|
736
|
-
if (!message || message.type !== "render") {
|
|
740
|
+
if (!message || message.type !== "render-flight") {
|
|
737
741
|
return;
|
|
738
742
|
}
|
|
739
743
|
|
|
740
|
-
const previousBasename = globalThis.__RSC_BASENAME;
|
|
741
|
-
globalThis.__RSC_BASENAME = message.payload.basename || "";
|
|
742
|
-
|
|
743
744
|
try {
|
|
744
|
-
const
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
const html = await renderHtml(resolved.model);
|
|
745
|
+
const html = await renderHtmlFromFlightData(
|
|
746
|
+
message.payload.flightData || "",
|
|
747
|
+
message.payload.moduleMap || {},
|
|
748
|
+
);
|
|
749
|
+
|
|
750
750
|
if (typeof process.send === "function") {
|
|
751
751
|
process.send({ id: message.id, ok: true, html });
|
|
752
752
|
}
|
|
@@ -757,8 +757,6 @@ process.on("message", async (message) => {
|
|
|
757
757
|
if (typeof process.send === "function") {
|
|
758
758
|
process.send({ id: message.id, ok: false, error: formatted });
|
|
759
759
|
}
|
|
760
|
-
} finally {
|
|
761
|
-
globalThis.__RSC_BASENAME = previousBasename;
|
|
762
760
|
}
|
|
763
761
|
});
|
|
764
762
|
`;
|
|
@@ -787,7 +785,7 @@ function sanitizeInitialHtmlWorkerNodeOptions(rawNodeOptions) {
|
|
|
787
785
|
}
|
|
788
786
|
return rawNodeOptions.replace(/(^|\s)--conditions\s+react-server(?=\s|$)/g, " ").replace(/(^|\s)-r\s+(\S*webframez-react\/register)(?=\s|$)/g, " ").replace(/\s+/g, " ").trim();
|
|
789
787
|
}
|
|
790
|
-
function createInitialHtmlWorker(
|
|
788
|
+
function createInitialHtmlWorker(_pagesDir) {
|
|
791
789
|
let child = null;
|
|
792
790
|
let nextRequestId = 1;
|
|
793
791
|
let stderrBuffer = "";
|
|
@@ -818,8 +816,7 @@ function createInitialHtmlWorker(pagesDir) {
|
|
|
818
816
|
cwd: process.cwd(),
|
|
819
817
|
env: {
|
|
820
818
|
...process.env,
|
|
821
|
-
NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
|
|
822
|
-
WEBFRAMEZ_REACT_PAGES_DIR: pagesDir
|
|
819
|
+
NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
|
|
823
820
|
},
|
|
824
821
|
stdio: ["ignore", "ignore", "pipe", "ipc"]
|
|
825
822
|
});
|
|
@@ -859,7 +856,7 @@ ${stderrBuffer.trim()}` : "";
|
|
|
859
856
|
return child;
|
|
860
857
|
};
|
|
861
858
|
return {
|
|
862
|
-
|
|
859
|
+
renderFromFlightData(payload) {
|
|
863
860
|
const activeChild = startWorker();
|
|
864
861
|
const requestId = nextRequestId++;
|
|
865
862
|
return new Promise((resolve, reject) => {
|
|
@@ -870,7 +867,7 @@ ${stderrBuffer.trim()}` : "";
|
|
|
870
867
|
pending.set(requestId, { resolve, reject, timeout });
|
|
871
868
|
const request = {
|
|
872
869
|
id: requestId,
|
|
873
|
-
type: "render",
|
|
870
|
+
type: "render-flight",
|
|
874
871
|
payload
|
|
875
872
|
};
|
|
876
873
|
activeChild.send(request, (error) => {
|
|
@@ -1102,26 +1099,26 @@ function createNodeRequestHandler(options) {
|
|
|
1102
1099
|
});
|
|
1103
1100
|
let rootHtml = "";
|
|
1104
1101
|
try {
|
|
1105
|
-
rootHtml = await initialHtmlWorker.
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
cookies: requestCookies,
|
|
1109
|
-
basename: basePath
|
|
1102
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1103
|
+
flightData: initialFlightData,
|
|
1104
|
+
moduleMap
|
|
1110
1105
|
});
|
|
1111
1106
|
} catch (error) {
|
|
1112
1107
|
console.error("[webframez-react] Failed to render initial HTML", error);
|
|
1113
1108
|
try {
|
|
1114
1109
|
initialHtmlWorker.dispose();
|
|
1115
|
-
rootHtml = await initialHtmlWorker.
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
cookies: requestCookies,
|
|
1119
|
-
basename: basePath
|
|
1110
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1111
|
+
flightData: initialFlightData,
|
|
1112
|
+
moduleMap
|
|
1120
1113
|
});
|
|
1121
1114
|
} catch (retryError) {
|
|
1122
1115
|
console.error("[webframez-react] Retry for initial HTML failed", retryError);
|
|
1123
1116
|
try {
|
|
1124
|
-
|
|
1117
|
+
initialHtmlWorker.dispose();
|
|
1118
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1119
|
+
flightData: initialFlightData,
|
|
1120
|
+
moduleMap
|
|
1121
|
+
});
|
|
1125
1122
|
} catch (flightRenderError) {
|
|
1126
1123
|
console.error("[webframez-react] Flight-to-HTML render failed", flightRenderError);
|
|
1127
1124
|
res.statusCode = 500;
|
package/dist/http.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;
|