@webtypen/webframez-react 0.0.16 → 0.0.17
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 +119 -64
- package/dist/http.js +119 -64
- package/dist/index.cjs +119 -64
- package/dist/index.js +119 -64
- package/dist/router.cjs +7 -4
- package/dist/router.js +7 -4
- package/dist/webframez-core.cjs +119 -64
- package/dist/webframez-core.js +119 -64
- 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,39 +637,46 @@ 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
642
|
const pagesDir = process.env.WEBFRAMEZ_REACT_PAGES_DIR || "";
|
|
661
643
|
if (!pagesDir) {
|
|
662
644
|
throw new Error("Missing WEBFRAMEZ_REACT_PAGES_DIR");
|
|
663
645
|
}
|
|
664
646
|
|
|
665
|
-
const rootRequire = Module.createRequire(path.join(process.cwd(), "__webframez_react_worker__.js"));
|
|
666
647
|
const originalResolveFilename = Module._resolveFilename;
|
|
667
|
-
const
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
648
|
+
const rootParent = {
|
|
649
|
+
id: "__webframez_react_worker__",
|
|
650
|
+
filename: path.join(process.cwd(), "__webframez_react_worker__.js"),
|
|
651
|
+
path: process.cwd(),
|
|
652
|
+
paths: Module._nodeModulePaths(process.cwd()),
|
|
653
|
+
};
|
|
654
|
+
const forcedPackageRequests = [
|
|
655
|
+
"@webtypen/webframez-core",
|
|
656
|
+
"@webtypen/webframez-react",
|
|
657
|
+
"react",
|
|
658
|
+
"react/jsx-runtime",
|
|
659
|
+
"react/jsx-dev-runtime",
|
|
660
|
+
"react-dom",
|
|
661
|
+
"react-dom/client",
|
|
662
|
+
"react-dom/server",
|
|
663
|
+
"react-dom/server.node",
|
|
664
|
+
"react-server-dom-webpack",
|
|
665
|
+
"react-server-dom-webpack/server",
|
|
666
|
+
"react-server-dom-webpack/client",
|
|
667
|
+
"react-server-dom-webpack/client.node",
|
|
668
|
+
"scheduler"
|
|
669
|
+
];
|
|
670
|
+
|
|
671
|
+
function shouldForcePackageResolution(request) {
|
|
672
|
+
return forcedPackageRequests.some((candidate) =>
|
|
673
|
+
request === candidate || request.startsWith(candidate + "/")
|
|
674
|
+
);
|
|
675
|
+
}
|
|
683
676
|
|
|
684
677
|
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
|
-
}
|
|
678
|
+
if (typeof request === "string" && shouldForcePackageResolution(request)) {
|
|
679
|
+
return originalResolveFilename.call(this, request, rootParent, false, options);
|
|
692
680
|
}
|
|
693
681
|
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
694
682
|
};
|
|
@@ -735,21 +723,58 @@ function renderHtml(model) {
|
|
|
735
723
|
});
|
|
736
724
|
}
|
|
737
725
|
|
|
726
|
+
function createReadableStreamFromString(value) {
|
|
727
|
+
const encoder = new TextEncoder();
|
|
728
|
+
|
|
729
|
+
return new ReadableStream({
|
|
730
|
+
start(controller) {
|
|
731
|
+
controller.enqueue(encoder.encode(value));
|
|
732
|
+
controller.close();
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
738
|
+
const model = await createFromReadableStream(createReadableStreamFromString(flightData), {
|
|
739
|
+
serverConsumerManifest: {
|
|
740
|
+
moduleMap: moduleMap || {},
|
|
741
|
+
serverModuleMap: null,
|
|
742
|
+
moduleLoading: null
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
|
|
746
|
+
return renderHtml(model);
|
|
747
|
+
}
|
|
748
|
+
|
|
738
749
|
process.on("message", async (message) => {
|
|
739
|
-
if (!message || message.type !== "render") {
|
|
750
|
+
if (!message || (message.type !== "render-route" && message.type !== "render-flight")) {
|
|
740
751
|
return;
|
|
741
752
|
}
|
|
742
753
|
|
|
743
|
-
const previousBasename = globalThis.__RSC_BASENAME;
|
|
744
|
-
globalThis.__RSC_BASENAME = message.payload.basename || "";
|
|
745
|
-
|
|
746
754
|
try {
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
755
|
+
let html = "";
|
|
756
|
+
|
|
757
|
+
if (message.type === "render-route") {
|
|
758
|
+
const previousBasename = globalThis.__RSC_BASENAME;
|
|
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
|
+
}
|
|
777
|
+
|
|
753
778
|
if (typeof process.send === "function") {
|
|
754
779
|
process.send({ id: message.id, ok: true, html });
|
|
755
780
|
}
|
|
@@ -760,8 +785,6 @@ process.on("message", async (message) => {
|
|
|
760
785
|
if (typeof process.send === "function") {
|
|
761
786
|
process.send({ id: message.id, ok: false, error: formatted });
|
|
762
787
|
}
|
|
763
|
-
} finally {
|
|
764
|
-
globalThis.__RSC_BASENAME = previousBasename;
|
|
765
788
|
}
|
|
766
789
|
});
|
|
767
790
|
`;
|
|
@@ -873,7 +896,35 @@ ${stderrBuffer.trim()}` : "";
|
|
|
873
896
|
pending.set(requestId, { resolve, reject, timeout });
|
|
874
897
|
const request = {
|
|
875
898
|
id: requestId,
|
|
876
|
-
type: "render",
|
|
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
|
+
renderFromFlightData(payload) {
|
|
917
|
+
const activeChild = startWorker();
|
|
918
|
+
const requestId = nextRequestId++;
|
|
919
|
+
return new Promise((resolve, reject) => {
|
|
920
|
+
const timeout = setTimeout(() => {
|
|
921
|
+
rejectPending(new Error("[webframez-react] Initial HTML worker timed out"));
|
|
922
|
+
stopWorker();
|
|
923
|
+
}, 1e4);
|
|
924
|
+
pending.set(requestId, { resolve, reject, timeout });
|
|
925
|
+
const request = {
|
|
926
|
+
id: requestId,
|
|
927
|
+
type: "render-flight",
|
|
877
928
|
payload
|
|
878
929
|
};
|
|
879
930
|
activeChild.send(request, (error) => {
|
|
@@ -1124,7 +1175,11 @@ function createNodeRequestHandler(options) {
|
|
|
1124
1175
|
} catch (retryError) {
|
|
1125
1176
|
console.error("[webframez-react] Retry for initial HTML failed", retryError);
|
|
1126
1177
|
try {
|
|
1127
|
-
|
|
1178
|
+
initialHtmlWorker.dispose();
|
|
1179
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1180
|
+
flightData: initialFlightData,
|
|
1181
|
+
moduleMap
|
|
1182
|
+
});
|
|
1128
1183
|
} catch (flightRenderError) {
|
|
1129
1184
|
console.error("[webframez-react] Flight-to-HTML render failed", flightRenderError);
|
|
1130
1185
|
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,39 +609,46 @@ 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
614
|
const pagesDir = process.env.WEBFRAMEZ_REACT_PAGES_DIR || "";
|
|
633
615
|
if (!pagesDir) {
|
|
634
616
|
throw new Error("Missing WEBFRAMEZ_REACT_PAGES_DIR");
|
|
635
617
|
}
|
|
636
618
|
|
|
637
|
-
const rootRequire = Module.createRequire(path.join(process.cwd(), "__webframez_react_worker__.js"));
|
|
638
619
|
const originalResolveFilename = Module._resolveFilename;
|
|
639
|
-
const
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
620
|
+
const rootParent = {
|
|
621
|
+
id: "__webframez_react_worker__",
|
|
622
|
+
filename: path.join(process.cwd(), "__webframez_react_worker__.js"),
|
|
623
|
+
path: process.cwd(),
|
|
624
|
+
paths: Module._nodeModulePaths(process.cwd()),
|
|
625
|
+
};
|
|
626
|
+
const forcedPackageRequests = [
|
|
627
|
+
"@webtypen/webframez-core",
|
|
628
|
+
"@webtypen/webframez-react",
|
|
629
|
+
"react",
|
|
630
|
+
"react/jsx-runtime",
|
|
631
|
+
"react/jsx-dev-runtime",
|
|
632
|
+
"react-dom",
|
|
633
|
+
"react-dom/client",
|
|
634
|
+
"react-dom/server",
|
|
635
|
+
"react-dom/server.node",
|
|
636
|
+
"react-server-dom-webpack",
|
|
637
|
+
"react-server-dom-webpack/server",
|
|
638
|
+
"react-server-dom-webpack/client",
|
|
639
|
+
"react-server-dom-webpack/client.node",
|
|
640
|
+
"scheduler"
|
|
641
|
+
];
|
|
642
|
+
|
|
643
|
+
function shouldForcePackageResolution(request) {
|
|
644
|
+
return forcedPackageRequests.some((candidate) =>
|
|
645
|
+
request === candidate || request.startsWith(candidate + "/")
|
|
646
|
+
);
|
|
647
|
+
}
|
|
655
648
|
|
|
656
649
|
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
|
-
}
|
|
650
|
+
if (typeof request === "string" && shouldForcePackageResolution(request)) {
|
|
651
|
+
return originalResolveFilename.call(this, request, rootParent, false, options);
|
|
664
652
|
}
|
|
665
653
|
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
666
654
|
};
|
|
@@ -707,21 +695,58 @@ function renderHtml(model) {
|
|
|
707
695
|
});
|
|
708
696
|
}
|
|
709
697
|
|
|
698
|
+
function createReadableStreamFromString(value) {
|
|
699
|
+
const encoder = new TextEncoder();
|
|
700
|
+
|
|
701
|
+
return new ReadableStream({
|
|
702
|
+
start(controller) {
|
|
703
|
+
controller.enqueue(encoder.encode(value));
|
|
704
|
+
controller.close();
|
|
705
|
+
}
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
710
|
+
const model = await createFromReadableStream(createReadableStreamFromString(flightData), {
|
|
711
|
+
serverConsumerManifest: {
|
|
712
|
+
moduleMap: moduleMap || {},
|
|
713
|
+
serverModuleMap: null,
|
|
714
|
+
moduleLoading: null
|
|
715
|
+
}
|
|
716
|
+
});
|
|
717
|
+
|
|
718
|
+
return renderHtml(model);
|
|
719
|
+
}
|
|
720
|
+
|
|
710
721
|
process.on("message", async (message) => {
|
|
711
|
-
if (!message || message.type !== "render") {
|
|
722
|
+
if (!message || (message.type !== "render-route" && message.type !== "render-flight")) {
|
|
712
723
|
return;
|
|
713
724
|
}
|
|
714
725
|
|
|
715
|
-
const previousBasename = globalThis.__RSC_BASENAME;
|
|
716
|
-
globalThis.__RSC_BASENAME = message.payload.basename || "";
|
|
717
|
-
|
|
718
726
|
try {
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
727
|
+
let html = "";
|
|
728
|
+
|
|
729
|
+
if (message.type === "render-route") {
|
|
730
|
+
const previousBasename = globalThis.__RSC_BASENAME;
|
|
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
|
+
}
|
|
749
|
+
|
|
725
750
|
if (typeof process.send === "function") {
|
|
726
751
|
process.send({ id: message.id, ok: true, html });
|
|
727
752
|
}
|
|
@@ -732,8 +757,6 @@ process.on("message", async (message) => {
|
|
|
732
757
|
if (typeof process.send === "function") {
|
|
733
758
|
process.send({ id: message.id, ok: false, error: formatted });
|
|
734
759
|
}
|
|
735
|
-
} finally {
|
|
736
|
-
globalThis.__RSC_BASENAME = previousBasename;
|
|
737
760
|
}
|
|
738
761
|
});
|
|
739
762
|
`;
|
|
@@ -845,7 +868,35 @@ ${stderrBuffer.trim()}` : "";
|
|
|
845
868
|
pending.set(requestId, { resolve, reject, timeout });
|
|
846
869
|
const request = {
|
|
847
870
|
id: requestId,
|
|
848
|
-
type: "render",
|
|
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
|
+
renderFromFlightData(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-flight",
|
|
849
900
|
payload
|
|
850
901
|
};
|
|
851
902
|
activeChild.send(request, (error) => {
|
|
@@ -1096,7 +1147,11 @@ function createNodeRequestHandler(options) {
|
|
|
1096
1147
|
} catch (retryError) {
|
|
1097
1148
|
console.error("[webframez-react] Retry for initial HTML failed", retryError);
|
|
1098
1149
|
try {
|
|
1099
|
-
|
|
1150
|
+
initialHtmlWorker.dispose();
|
|
1151
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1152
|
+
flightData: initialFlightData,
|
|
1153
|
+
moduleMap
|
|
1154
|
+
});
|
|
1100
1155
|
} catch (flightRenderError) {
|
|
1101
1156
|
console.error("[webframez-react] Flight-to-HTML render failed", flightRenderError);
|
|
1102
1157
|
res.statusCode = 500;
|