@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/index.cjs
CHANGED
|
@@ -136,28 +136,6 @@ function renderRSCToString(payload, options = {}) {
|
|
|
136
136
|
stream.pipe(writable);
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
|
-
function createReadableStreamFromString(value) {
|
|
140
|
-
const encoder = new TextEncoder();
|
|
141
|
-
return new ReadableStream({
|
|
142
|
-
start(controller) {
|
|
143
|
-
controller.enqueue(encoder.encode(value));
|
|
144
|
-
controller.close();
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
async function renderHtmlFromFlightData(flightData, options) {
|
|
149
|
-
const appRequire = (0, import_node_module.createRequire)(import_node_path.default.join(process.cwd(), "__webframez_react_server__.js"));
|
|
150
|
-
const reactDomPkg = appRequire.resolve("react-dom/package.json");
|
|
151
|
-
const { renderToString } = appRequire(import_node_path.default.join(import_node_path.default.dirname(reactDomPkg), "server.node.js"));
|
|
152
|
-
const model = await (0, import_client.createFromReadableStream)(createReadableStreamFromString(flightData), {
|
|
153
|
-
serverConsumerManifest: {
|
|
154
|
-
moduleMap: options.moduleMap ?? {},
|
|
155
|
-
serverModuleMap: null,
|
|
156
|
-
moduleLoading: null
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
return renderToString(model);
|
|
160
|
-
}
|
|
161
139
|
function sendRSC(res, model, options = {}) {
|
|
162
140
|
const {
|
|
163
141
|
moduleMap = {},
|
|
@@ -265,9 +243,6 @@ function injectRouteChildren(node, routeChildren) {
|
|
|
265
243
|
|
|
266
244
|
// src/file-router.tsx
|
|
267
245
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
268
|
-
var ROOT_RUNTIME_REQUIRE = import_node_module2.default.createRequire(
|
|
269
|
-
import_node_path2.default.join(process.cwd(), "__webframez_react_runtime__.js")
|
|
270
|
-
);
|
|
271
246
|
var FORCED_PACKAGE_REQUESTS = [
|
|
272
247
|
"@webtypen/webframez-core",
|
|
273
248
|
"@webtypen/webframez-react",
|
|
@@ -344,10 +319,16 @@ function installForcedPackageResolution() {
|
|
|
344
319
|
}
|
|
345
320
|
const moduleWithPrivateResolver = import_node_module2.default;
|
|
346
321
|
const originalResolveFilename = moduleWithPrivateResolver._resolveFilename;
|
|
322
|
+
const rootParent = {
|
|
323
|
+
id: "__webframez_react_runtime__",
|
|
324
|
+
filename: import_node_path2.default.join(process.cwd(), "__webframez_react_runtime__.js"),
|
|
325
|
+
path: process.cwd(),
|
|
326
|
+
paths: moduleWithPrivateResolver._nodeModulePaths(process.cwd())
|
|
327
|
+
};
|
|
347
328
|
moduleWithPrivateResolver._resolveFilename = function patchedResolveFilename(request, parent, isMain, options) {
|
|
348
329
|
if (typeof request === "string" && shouldForcePackageResolution(request)) {
|
|
349
330
|
try {
|
|
350
|
-
return
|
|
331
|
+
return originalResolveFilename.call(this, request, rootParent, false, options);
|
|
351
332
|
} catch {
|
|
352
333
|
}
|
|
353
334
|
}
|
|
@@ -690,49 +671,49 @@ var INITIAL_HTML_WORKER_SCRIPT = `
|
|
|
690
671
|
const path = require("node:path");
|
|
691
672
|
const Module = require("node:module");
|
|
692
673
|
const { Writable } = require("node:stream");
|
|
674
|
+
const { createFromReadableStream } = require("react-server-dom-webpack/client.node");
|
|
693
675
|
|
|
694
|
-
const pagesDir = process.env.WEBFRAMEZ_REACT_PAGES_DIR || "";
|
|
695
|
-
if (!pagesDir) {
|
|
696
|
-
throw new Error("Missing WEBFRAMEZ_REACT_PAGES_DIR");
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
const rootRequire = Module.createRequire(path.join(process.cwd(), "__webframez_react_worker__.js"));
|
|
700
676
|
const originalResolveFilename = Module._resolveFilename;
|
|
701
|
-
const
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
677
|
+
const rootParent = {
|
|
678
|
+
id: "__webframez_react_worker__",
|
|
679
|
+
filename: path.join(process.cwd(), "__webframez_react_worker__.js"),
|
|
680
|
+
path: process.cwd(),
|
|
681
|
+
paths: Module._nodeModulePaths(process.cwd()),
|
|
682
|
+
};
|
|
683
|
+
const forcedPackageRequests = [
|
|
684
|
+
"@webtypen/webframez-core",
|
|
685
|
+
"@webtypen/webframez-react",
|
|
686
|
+
"react",
|
|
687
|
+
"react/jsx-runtime",
|
|
688
|
+
"react/jsx-dev-runtime",
|
|
689
|
+
"react-dom",
|
|
690
|
+
"react-dom/client",
|
|
691
|
+
"react-dom/server",
|
|
692
|
+
"react-dom/server.node",
|
|
693
|
+
"react-server-dom-webpack",
|
|
694
|
+
"react-server-dom-webpack/server",
|
|
695
|
+
"react-server-dom-webpack/client",
|
|
696
|
+
"react-server-dom-webpack/client.node",
|
|
697
|
+
"scheduler"
|
|
698
|
+
];
|
|
699
|
+
|
|
700
|
+
function shouldForcePackageResolution(request) {
|
|
701
|
+
return forcedPackageRequests.some((candidate) =>
|
|
702
|
+
request === candidate || request.startsWith(candidate + "/")
|
|
703
|
+
);
|
|
704
|
+
}
|
|
717
705
|
|
|
718
706
|
Module._resolveFilename = function(request, parent, isMain, options) {
|
|
719
|
-
if (
|
|
720
|
-
return
|
|
721
|
-
}
|
|
722
|
-
for (const forcedRequest of forcedResolutions.keys()) {
|
|
723
|
-
if (request.startsWith(forcedRequest + "/")) {
|
|
724
|
-
return rootRequire.resolve(request);
|
|
725
|
-
}
|
|
707
|
+
if (typeof request === "string" && shouldForcePackageResolution(request)) {
|
|
708
|
+
return originalResolveFilename.call(this, request, rootParent, false, options);
|
|
726
709
|
}
|
|
727
710
|
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
728
711
|
};
|
|
729
712
|
|
|
730
|
-
const { createFileRouter } = require("@webtypen/webframez-react/router");
|
|
731
713
|
const reactDomPkg = require.resolve("react-dom/package.json", {
|
|
732
|
-
paths: [process.cwd()
|
|
714
|
+
paths: [process.cwd()]
|
|
733
715
|
});
|
|
734
716
|
const reactDomServer = require(path.join(path.dirname(reactDomPkg), "server.node.js"));
|
|
735
|
-
const router = createFileRouter({ pagesDir });
|
|
736
717
|
|
|
737
718
|
function renderHtml(model) {
|
|
738
719
|
return new Promise((resolve, reject) => {
|
|
@@ -769,21 +750,40 @@ function renderHtml(model) {
|
|
|
769
750
|
});
|
|
770
751
|
}
|
|
771
752
|
|
|
753
|
+
function createReadableStreamFromString(value) {
|
|
754
|
+
const encoder = new TextEncoder();
|
|
755
|
+
|
|
756
|
+
return new ReadableStream({
|
|
757
|
+
start(controller) {
|
|
758
|
+
controller.enqueue(encoder.encode(value));
|
|
759
|
+
controller.close();
|
|
760
|
+
}
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
765
|
+
const model = await createFromReadableStream(createReadableStreamFromString(flightData), {
|
|
766
|
+
serverConsumerManifest: {
|
|
767
|
+
moduleMap: moduleMap || {},
|
|
768
|
+
serverModuleMap: null,
|
|
769
|
+
moduleLoading: null
|
|
770
|
+
}
|
|
771
|
+
});
|
|
772
|
+
|
|
773
|
+
return renderHtml(model);
|
|
774
|
+
}
|
|
775
|
+
|
|
772
776
|
process.on("message", async (message) => {
|
|
773
|
-
if (!message || message.type !== "render") {
|
|
777
|
+
if (!message || message.type !== "render-flight") {
|
|
774
778
|
return;
|
|
775
779
|
}
|
|
776
780
|
|
|
777
|
-
const previousBasename = globalThis.__RSC_BASENAME;
|
|
778
|
-
globalThis.__RSC_BASENAME = message.payload.basename || "";
|
|
779
|
-
|
|
780
781
|
try {
|
|
781
|
-
const
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
const html = await renderHtml(resolved.model);
|
|
782
|
+
const html = await renderHtmlFromFlightData(
|
|
783
|
+
message.payload.flightData || "",
|
|
784
|
+
message.payload.moduleMap || {},
|
|
785
|
+
);
|
|
786
|
+
|
|
787
787
|
if (typeof process.send === "function") {
|
|
788
788
|
process.send({ id: message.id, ok: true, html });
|
|
789
789
|
}
|
|
@@ -794,8 +794,6 @@ process.on("message", async (message) => {
|
|
|
794
794
|
if (typeof process.send === "function") {
|
|
795
795
|
process.send({ id: message.id, ok: false, error: formatted });
|
|
796
796
|
}
|
|
797
|
-
} finally {
|
|
798
|
-
globalThis.__RSC_BASENAME = previousBasename;
|
|
799
797
|
}
|
|
800
798
|
});
|
|
801
799
|
`;
|
|
@@ -824,7 +822,7 @@ function sanitizeInitialHtmlWorkerNodeOptions(rawNodeOptions) {
|
|
|
824
822
|
}
|
|
825
823
|
return rawNodeOptions.replace(/(^|\s)--conditions\s+react-server(?=\s|$)/g, " ").replace(/(^|\s)-r\s+(\S*webframez-react\/register)(?=\s|$)/g, " ").replace(/\s+/g, " ").trim();
|
|
826
824
|
}
|
|
827
|
-
function createInitialHtmlWorker(
|
|
825
|
+
function createInitialHtmlWorker(_pagesDir) {
|
|
828
826
|
let child = null;
|
|
829
827
|
let nextRequestId = 1;
|
|
830
828
|
let stderrBuffer = "";
|
|
@@ -855,8 +853,7 @@ function createInitialHtmlWorker(pagesDir) {
|
|
|
855
853
|
cwd: process.cwd(),
|
|
856
854
|
env: {
|
|
857
855
|
...process.env,
|
|
858
|
-
NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
|
|
859
|
-
WEBFRAMEZ_REACT_PAGES_DIR: pagesDir
|
|
856
|
+
NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
|
|
860
857
|
},
|
|
861
858
|
stdio: ["ignore", "ignore", "pipe", "ipc"]
|
|
862
859
|
});
|
|
@@ -896,7 +893,7 @@ ${stderrBuffer.trim()}` : "";
|
|
|
896
893
|
return child;
|
|
897
894
|
};
|
|
898
895
|
return {
|
|
899
|
-
|
|
896
|
+
renderFromFlightData(payload) {
|
|
900
897
|
const activeChild = startWorker();
|
|
901
898
|
const requestId = nextRequestId++;
|
|
902
899
|
return new Promise((resolve, reject) => {
|
|
@@ -907,7 +904,7 @@ ${stderrBuffer.trim()}` : "";
|
|
|
907
904
|
pending.set(requestId, { resolve, reject, timeout });
|
|
908
905
|
const request = {
|
|
909
906
|
id: requestId,
|
|
910
|
-
type: "render",
|
|
907
|
+
type: "render-flight",
|
|
911
908
|
payload
|
|
912
909
|
};
|
|
913
910
|
activeChild.send(request, (error) => {
|
|
@@ -1139,26 +1136,26 @@ function createNodeRequestHandler(options) {
|
|
|
1139
1136
|
});
|
|
1140
1137
|
let rootHtml = "";
|
|
1141
1138
|
try {
|
|
1142
|
-
rootHtml = await initialHtmlWorker.
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
cookies: requestCookies,
|
|
1146
|
-
basename: basePath
|
|
1139
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1140
|
+
flightData: initialFlightData,
|
|
1141
|
+
moduleMap
|
|
1147
1142
|
});
|
|
1148
1143
|
} catch (error) {
|
|
1149
1144
|
console.error("[webframez-react] Failed to render initial HTML", error);
|
|
1150
1145
|
try {
|
|
1151
1146
|
initialHtmlWorker.dispose();
|
|
1152
|
-
rootHtml = await initialHtmlWorker.
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
cookies: requestCookies,
|
|
1156
|
-
basename: basePath
|
|
1147
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1148
|
+
flightData: initialFlightData,
|
|
1149
|
+
moduleMap
|
|
1157
1150
|
});
|
|
1158
1151
|
} catch (retryError) {
|
|
1159
1152
|
console.error("[webframez-react] Retry for initial HTML failed", retryError);
|
|
1160
1153
|
try {
|
|
1161
|
-
|
|
1154
|
+
initialHtmlWorker.dispose();
|
|
1155
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1156
|
+
flightData: initialFlightData,
|
|
1157
|
+
moduleMap
|
|
1158
|
+
});
|
|
1162
1159
|
} catch (flightRenderError) {
|
|
1163
1160
|
console.error("[webframez-react] Flight-to-HTML render failed", flightRenderError);
|
|
1164
1161
|
res.statusCode = 500;
|
package/dist/index.js
CHANGED
|
@@ -100,28 +100,6 @@ function renderRSCToString(payload, options = {}) {
|
|
|
100
100
|
stream.pipe(writable);
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
|
-
function createReadableStreamFromString(value) {
|
|
104
|
-
const encoder = new TextEncoder();
|
|
105
|
-
return new ReadableStream({
|
|
106
|
-
start(controller) {
|
|
107
|
-
controller.enqueue(encoder.encode(value));
|
|
108
|
-
controller.close();
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
async function renderHtmlFromFlightData(flightData, options) {
|
|
113
|
-
const appRequire = createRequire(path.join(process.cwd(), "__webframez_react_server__.js"));
|
|
114
|
-
const reactDomPkg = appRequire.resolve("react-dom/package.json");
|
|
115
|
-
const { renderToString } = appRequire(path.join(path.dirname(reactDomPkg), "server.node.js"));
|
|
116
|
-
const model = await createFromReadableStream(createReadableStreamFromString(flightData), {
|
|
117
|
-
serverConsumerManifest: {
|
|
118
|
-
moduleMap: options.moduleMap ?? {},
|
|
119
|
-
serverModuleMap: null,
|
|
120
|
-
moduleLoading: null
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
return renderToString(model);
|
|
124
|
-
}
|
|
125
103
|
function sendRSC(res, model, options = {}) {
|
|
126
104
|
const {
|
|
127
105
|
moduleMap = {},
|
|
@@ -229,9 +207,6 @@ function injectRouteChildren(node, routeChildren) {
|
|
|
229
207
|
|
|
230
208
|
// src/file-router.tsx
|
|
231
209
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
232
|
-
var ROOT_RUNTIME_REQUIRE = Module.createRequire(
|
|
233
|
-
path2.join(process.cwd(), "__webframez_react_runtime__.js")
|
|
234
|
-
);
|
|
235
210
|
var FORCED_PACKAGE_REQUESTS = [
|
|
236
211
|
"@webtypen/webframez-core",
|
|
237
212
|
"@webtypen/webframez-react",
|
|
@@ -308,10 +283,16 @@ function installForcedPackageResolution() {
|
|
|
308
283
|
}
|
|
309
284
|
const moduleWithPrivateResolver = Module;
|
|
310
285
|
const originalResolveFilename = moduleWithPrivateResolver._resolveFilename;
|
|
286
|
+
const rootParent = {
|
|
287
|
+
id: "__webframez_react_runtime__",
|
|
288
|
+
filename: path2.join(process.cwd(), "__webframez_react_runtime__.js"),
|
|
289
|
+
path: process.cwd(),
|
|
290
|
+
paths: moduleWithPrivateResolver._nodeModulePaths(process.cwd())
|
|
291
|
+
};
|
|
311
292
|
moduleWithPrivateResolver._resolveFilename = function patchedResolveFilename(request, parent, isMain, options) {
|
|
312
293
|
if (typeof request === "string" && shouldForcePackageResolution(request)) {
|
|
313
294
|
try {
|
|
314
|
-
return
|
|
295
|
+
return originalResolveFilename.call(this, request, rootParent, false, options);
|
|
315
296
|
} catch {
|
|
316
297
|
}
|
|
317
298
|
}
|
|
@@ -654,49 +635,49 @@ var INITIAL_HTML_WORKER_SCRIPT = `
|
|
|
654
635
|
const path = require("node:path");
|
|
655
636
|
const Module = require("node:module");
|
|
656
637
|
const { Writable } = require("node:stream");
|
|
638
|
+
const { createFromReadableStream } = require("react-server-dom-webpack/client.node");
|
|
657
639
|
|
|
658
|
-
const pagesDir = process.env.WEBFRAMEZ_REACT_PAGES_DIR || "";
|
|
659
|
-
if (!pagesDir) {
|
|
660
|
-
throw new Error("Missing WEBFRAMEZ_REACT_PAGES_DIR");
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
const rootRequire = Module.createRequire(path.join(process.cwd(), "__webframez_react_worker__.js"));
|
|
664
640
|
const originalResolveFilename = Module._resolveFilename;
|
|
665
|
-
const
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
641
|
+
const rootParent = {
|
|
642
|
+
id: "__webframez_react_worker__",
|
|
643
|
+
filename: path.join(process.cwd(), "__webframez_react_worker__.js"),
|
|
644
|
+
path: process.cwd(),
|
|
645
|
+
paths: Module._nodeModulePaths(process.cwd()),
|
|
646
|
+
};
|
|
647
|
+
const forcedPackageRequests = [
|
|
648
|
+
"@webtypen/webframez-core",
|
|
649
|
+
"@webtypen/webframez-react",
|
|
650
|
+
"react",
|
|
651
|
+
"react/jsx-runtime",
|
|
652
|
+
"react/jsx-dev-runtime",
|
|
653
|
+
"react-dom",
|
|
654
|
+
"react-dom/client",
|
|
655
|
+
"react-dom/server",
|
|
656
|
+
"react-dom/server.node",
|
|
657
|
+
"react-server-dom-webpack",
|
|
658
|
+
"react-server-dom-webpack/server",
|
|
659
|
+
"react-server-dom-webpack/client",
|
|
660
|
+
"react-server-dom-webpack/client.node",
|
|
661
|
+
"scheduler"
|
|
662
|
+
];
|
|
663
|
+
|
|
664
|
+
function shouldForcePackageResolution(request) {
|
|
665
|
+
return forcedPackageRequests.some((candidate) =>
|
|
666
|
+
request === candidate || request.startsWith(candidate + "/")
|
|
667
|
+
);
|
|
668
|
+
}
|
|
681
669
|
|
|
682
670
|
Module._resolveFilename = function(request, parent, isMain, options) {
|
|
683
|
-
if (
|
|
684
|
-
return
|
|
685
|
-
}
|
|
686
|
-
for (const forcedRequest of forcedResolutions.keys()) {
|
|
687
|
-
if (request.startsWith(forcedRequest + "/")) {
|
|
688
|
-
return rootRequire.resolve(request);
|
|
689
|
-
}
|
|
671
|
+
if (typeof request === "string" && shouldForcePackageResolution(request)) {
|
|
672
|
+
return originalResolveFilename.call(this, request, rootParent, false, options);
|
|
690
673
|
}
|
|
691
674
|
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
692
675
|
};
|
|
693
676
|
|
|
694
|
-
const { createFileRouter } = require("@webtypen/webframez-react/router");
|
|
695
677
|
const reactDomPkg = require.resolve("react-dom/package.json", {
|
|
696
|
-
paths: [process.cwd()
|
|
678
|
+
paths: [process.cwd()]
|
|
697
679
|
});
|
|
698
680
|
const reactDomServer = require(path.join(path.dirname(reactDomPkg), "server.node.js"));
|
|
699
|
-
const router = createFileRouter({ pagesDir });
|
|
700
681
|
|
|
701
682
|
function renderHtml(model) {
|
|
702
683
|
return new Promise((resolve, reject) => {
|
|
@@ -733,21 +714,40 @@ function renderHtml(model) {
|
|
|
733
714
|
});
|
|
734
715
|
}
|
|
735
716
|
|
|
717
|
+
function createReadableStreamFromString(value) {
|
|
718
|
+
const encoder = new TextEncoder();
|
|
719
|
+
|
|
720
|
+
return new ReadableStream({
|
|
721
|
+
start(controller) {
|
|
722
|
+
controller.enqueue(encoder.encode(value));
|
|
723
|
+
controller.close();
|
|
724
|
+
}
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
729
|
+
const model = await createFromReadableStream(createReadableStreamFromString(flightData), {
|
|
730
|
+
serverConsumerManifest: {
|
|
731
|
+
moduleMap: moduleMap || {},
|
|
732
|
+
serverModuleMap: null,
|
|
733
|
+
moduleLoading: null
|
|
734
|
+
}
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
return renderHtml(model);
|
|
738
|
+
}
|
|
739
|
+
|
|
736
740
|
process.on("message", async (message) => {
|
|
737
|
-
if (!message || message.type !== "render") {
|
|
741
|
+
if (!message || message.type !== "render-flight") {
|
|
738
742
|
return;
|
|
739
743
|
}
|
|
740
744
|
|
|
741
|
-
const previousBasename = globalThis.__RSC_BASENAME;
|
|
742
|
-
globalThis.__RSC_BASENAME = message.payload.basename || "";
|
|
743
|
-
|
|
744
745
|
try {
|
|
745
|
-
const
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
const html = await renderHtml(resolved.model);
|
|
746
|
+
const html = await renderHtmlFromFlightData(
|
|
747
|
+
message.payload.flightData || "",
|
|
748
|
+
message.payload.moduleMap || {},
|
|
749
|
+
);
|
|
750
|
+
|
|
751
751
|
if (typeof process.send === "function") {
|
|
752
752
|
process.send({ id: message.id, ok: true, html });
|
|
753
753
|
}
|
|
@@ -758,8 +758,6 @@ process.on("message", async (message) => {
|
|
|
758
758
|
if (typeof process.send === "function") {
|
|
759
759
|
process.send({ id: message.id, ok: false, error: formatted });
|
|
760
760
|
}
|
|
761
|
-
} finally {
|
|
762
|
-
globalThis.__RSC_BASENAME = previousBasename;
|
|
763
761
|
}
|
|
764
762
|
});
|
|
765
763
|
`;
|
|
@@ -788,7 +786,7 @@ function sanitizeInitialHtmlWorkerNodeOptions(rawNodeOptions) {
|
|
|
788
786
|
}
|
|
789
787
|
return rawNodeOptions.replace(/(^|\s)--conditions\s+react-server(?=\s|$)/g, " ").replace(/(^|\s)-r\s+(\S*webframez-react\/register)(?=\s|$)/g, " ").replace(/\s+/g, " ").trim();
|
|
790
788
|
}
|
|
791
|
-
function createInitialHtmlWorker(
|
|
789
|
+
function createInitialHtmlWorker(_pagesDir) {
|
|
792
790
|
let child = null;
|
|
793
791
|
let nextRequestId = 1;
|
|
794
792
|
let stderrBuffer = "";
|
|
@@ -819,8 +817,7 @@ function createInitialHtmlWorker(pagesDir) {
|
|
|
819
817
|
cwd: process.cwd(),
|
|
820
818
|
env: {
|
|
821
819
|
...process.env,
|
|
822
|
-
NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
|
|
823
|
-
WEBFRAMEZ_REACT_PAGES_DIR: pagesDir
|
|
820
|
+
NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
|
|
824
821
|
},
|
|
825
822
|
stdio: ["ignore", "ignore", "pipe", "ipc"]
|
|
826
823
|
});
|
|
@@ -860,7 +857,7 @@ ${stderrBuffer.trim()}` : "";
|
|
|
860
857
|
return child;
|
|
861
858
|
};
|
|
862
859
|
return {
|
|
863
|
-
|
|
860
|
+
renderFromFlightData(payload) {
|
|
864
861
|
const activeChild = startWorker();
|
|
865
862
|
const requestId = nextRequestId++;
|
|
866
863
|
return new Promise((resolve, reject) => {
|
|
@@ -871,7 +868,7 @@ ${stderrBuffer.trim()}` : "";
|
|
|
871
868
|
pending.set(requestId, { resolve, reject, timeout });
|
|
872
869
|
const request = {
|
|
873
870
|
id: requestId,
|
|
874
|
-
type: "render",
|
|
871
|
+
type: "render-flight",
|
|
875
872
|
payload
|
|
876
873
|
};
|
|
877
874
|
activeChild.send(request, (error) => {
|
|
@@ -1103,26 +1100,26 @@ function createNodeRequestHandler(options) {
|
|
|
1103
1100
|
});
|
|
1104
1101
|
let rootHtml = "";
|
|
1105
1102
|
try {
|
|
1106
|
-
rootHtml = await initialHtmlWorker.
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
cookies: requestCookies,
|
|
1110
|
-
basename: basePath
|
|
1103
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1104
|
+
flightData: initialFlightData,
|
|
1105
|
+
moduleMap
|
|
1111
1106
|
});
|
|
1112
1107
|
} catch (error) {
|
|
1113
1108
|
console.error("[webframez-react] Failed to render initial HTML", error);
|
|
1114
1109
|
try {
|
|
1115
1110
|
initialHtmlWorker.dispose();
|
|
1116
|
-
rootHtml = await initialHtmlWorker.
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
cookies: requestCookies,
|
|
1120
|
-
basename: basePath
|
|
1111
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1112
|
+
flightData: initialFlightData,
|
|
1113
|
+
moduleMap
|
|
1121
1114
|
});
|
|
1122
1115
|
} catch (retryError) {
|
|
1123
1116
|
console.error("[webframez-react] Retry for initial HTML failed", retryError);
|
|
1124
1117
|
try {
|
|
1125
|
-
|
|
1118
|
+
initialHtmlWorker.dispose();
|
|
1119
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1120
|
+
flightData: initialFlightData,
|
|
1121
|
+
moduleMap
|
|
1122
|
+
});
|
|
1126
1123
|
} catch (flightRenderError) {
|
|
1127
1124
|
console.error("[webframez-react] Flight-to-HTML render failed", flightRenderError);
|
|
1128
1125
|
res.statusCode = 500;
|
package/dist/router.cjs
CHANGED
|
@@ -101,9 +101,6 @@ function injectRouteChildren(node, routeChildren) {
|
|
|
101
101
|
|
|
102
102
|
// src/file-router.tsx
|
|
103
103
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
104
|
-
var ROOT_RUNTIME_REQUIRE = import_node_module.default.createRequire(
|
|
105
|
-
import_node_path.default.join(process.cwd(), "__webframez_react_runtime__.js")
|
|
106
|
-
);
|
|
107
104
|
var FORCED_PACKAGE_REQUESTS = [
|
|
108
105
|
"@webtypen/webframez-core",
|
|
109
106
|
"@webtypen/webframez-react",
|
|
@@ -180,10 +177,16 @@ function installForcedPackageResolution() {
|
|
|
180
177
|
}
|
|
181
178
|
const moduleWithPrivateResolver = import_node_module.default;
|
|
182
179
|
const originalResolveFilename = moduleWithPrivateResolver._resolveFilename;
|
|
180
|
+
const rootParent = {
|
|
181
|
+
id: "__webframez_react_runtime__",
|
|
182
|
+
filename: import_node_path.default.join(process.cwd(), "__webframez_react_runtime__.js"),
|
|
183
|
+
path: process.cwd(),
|
|
184
|
+
paths: moduleWithPrivateResolver._nodeModulePaths(process.cwd())
|
|
185
|
+
};
|
|
183
186
|
moduleWithPrivateResolver._resolveFilename = function patchedResolveFilename(request, parent, isMain, options) {
|
|
184
187
|
if (typeof request === "string" && shouldForcePackageResolution(request)) {
|
|
185
188
|
try {
|
|
186
|
-
return
|
|
189
|
+
return originalResolveFilename.call(this, request, rootParent, false, options);
|
|
187
190
|
} catch {
|
|
188
191
|
}
|
|
189
192
|
}
|
package/dist/router.js
CHANGED
|
@@ -71,9 +71,6 @@ function injectRouteChildren(node, routeChildren) {
|
|
|
71
71
|
|
|
72
72
|
// src/file-router.tsx
|
|
73
73
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
74
|
-
var ROOT_RUNTIME_REQUIRE = Module.createRequire(
|
|
75
|
-
path.join(process.cwd(), "__webframez_react_runtime__.js")
|
|
76
|
-
);
|
|
77
74
|
var FORCED_PACKAGE_REQUESTS = [
|
|
78
75
|
"@webtypen/webframez-core",
|
|
79
76
|
"@webtypen/webframez-react",
|
|
@@ -150,10 +147,16 @@ function installForcedPackageResolution() {
|
|
|
150
147
|
}
|
|
151
148
|
const moduleWithPrivateResolver = Module;
|
|
152
149
|
const originalResolveFilename = moduleWithPrivateResolver._resolveFilename;
|
|
150
|
+
const rootParent = {
|
|
151
|
+
id: "__webframez_react_runtime__",
|
|
152
|
+
filename: path.join(process.cwd(), "__webframez_react_runtime__.js"),
|
|
153
|
+
path: process.cwd(),
|
|
154
|
+
paths: moduleWithPrivateResolver._nodeModulePaths(process.cwd())
|
|
155
|
+
};
|
|
153
156
|
moduleWithPrivateResolver._resolveFilename = function patchedResolveFilename(request, parent, isMain, options) {
|
|
154
157
|
if (typeof request === "string" && shouldForcePackageResolution(request)) {
|
|
155
158
|
try {
|
|
156
|
-
return
|
|
159
|
+
return originalResolveFilename.call(this, request, rootParent, false, options);
|
|
157
160
|
} catch {
|
|
158
161
|
}
|
|
159
162
|
}
|