@webtypen/webframez-react 0.0.15 → 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 +159 -45
- package/dist/http.js +159 -45
- package/dist/index.cjs +159 -45
- package/dist/index.js +159 -45
- package/dist/router.cjs +47 -0
- package/dist/router.js +47 -0
- package/dist/webframez-core.cjs +159 -45
- package/dist/webframez-core.js +159 -45
- 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 = {},
|
|
@@ -169,6 +147,7 @@ function sendRSC(res, model, options = {}) {
|
|
|
169
147
|
|
|
170
148
|
// src/file-router.tsx
|
|
171
149
|
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
150
|
+
var import_node_module2 = __toESM(require("node:module"), 1);
|
|
172
151
|
var import_node_path2 = __toESM(require("node:path"), 1);
|
|
173
152
|
|
|
174
153
|
// src/router-runtime.tsx
|
|
@@ -231,6 +210,23 @@ function injectRouteChildren(node, routeChildren) {
|
|
|
231
210
|
|
|
232
211
|
// src/file-router.tsx
|
|
233
212
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
213
|
+
var FORCED_PACKAGE_REQUESTS = [
|
|
214
|
+
"@webtypen/webframez-core",
|
|
215
|
+
"@webtypen/webframez-react",
|
|
216
|
+
"react",
|
|
217
|
+
"react/jsx-runtime",
|
|
218
|
+
"react/jsx-dev-runtime",
|
|
219
|
+
"react-dom",
|
|
220
|
+
"react-dom/client",
|
|
221
|
+
"react-dom/server",
|
|
222
|
+
"react-dom/server.node",
|
|
223
|
+
"react-server-dom-webpack",
|
|
224
|
+
"react-server-dom-webpack/server",
|
|
225
|
+
"react-server-dom-webpack/client",
|
|
226
|
+
"react-server-dom-webpack/client.node",
|
|
227
|
+
"scheduler"
|
|
228
|
+
];
|
|
229
|
+
var forcedPackageResolutionInstalled = false;
|
|
234
230
|
function normalizePathname(pathname) {
|
|
235
231
|
const trimmed = pathname.replace(/\/+$/, "") || "/";
|
|
236
232
|
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
@@ -279,6 +275,34 @@ var MANAGED_HEAD_ATTR = "data-webframez-head";
|
|
|
279
275
|
function createManagedAttributes() {
|
|
280
276
|
return `${MANAGED_HEAD_ATTR}="true"`;
|
|
281
277
|
}
|
|
278
|
+
function shouldForcePackageResolution(request) {
|
|
279
|
+
return FORCED_PACKAGE_REQUESTS.some(
|
|
280
|
+
(candidate) => request === candidate || request.startsWith(`${candidate}/`)
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
function installForcedPackageResolution() {
|
|
284
|
+
if (forcedPackageResolutionInstalled) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
const moduleWithPrivateResolver = import_node_module2.default;
|
|
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
|
+
};
|
|
295
|
+
moduleWithPrivateResolver._resolveFilename = function patchedResolveFilename(request, parent, isMain, options) {
|
|
296
|
+
if (typeof request === "string" && shouldForcePackageResolution(request)) {
|
|
297
|
+
try {
|
|
298
|
+
return originalResolveFilename.call(this, request, rootParent, false, options);
|
|
299
|
+
} catch {
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
303
|
+
};
|
|
304
|
+
forcedPackageResolutionInstalled = true;
|
|
305
|
+
}
|
|
282
306
|
function toRouteEntry(pagesDir, filePath) {
|
|
283
307
|
const normalized = filePath.replace(/\\/g, "/");
|
|
284
308
|
if (!normalized.endsWith("/index.js")) {
|
|
@@ -426,6 +450,7 @@ function isRouteAbort(value) {
|
|
|
426
450
|
}
|
|
427
451
|
}
|
|
428
452
|
function createFileRouter(options) {
|
|
453
|
+
installForcedPackageResolution();
|
|
429
454
|
const pagesDir = options.pagesDir;
|
|
430
455
|
const layoutPath = import_node_path2.default.join(pagesDir, "layout.js");
|
|
431
456
|
const errorPath = import_node_path2.default.join(pagesDir, "errors.js");
|
|
@@ -609,24 +634,46 @@ var INITIAL_HTML_WORKER_SCRIPT = `
|
|
|
609
634
|
const path = require("node:path");
|
|
610
635
|
const Module = require("node:module");
|
|
611
636
|
const { Writable } = require("node:stream");
|
|
637
|
+
const { createFromReadableStream } = require("react-server-dom-webpack/client.node");
|
|
612
638
|
|
|
613
639
|
const pagesDir = process.env.WEBFRAMEZ_REACT_PAGES_DIR || "";
|
|
614
640
|
if (!pagesDir) {
|
|
615
641
|
throw new Error("Missing WEBFRAMEZ_REACT_PAGES_DIR");
|
|
616
642
|
}
|
|
617
643
|
|
|
618
|
-
const appRequire = Module.createRequire(path.join(pagesDir, "__webframez_react_worker__.js"));
|
|
619
644
|
const originalResolveFilename = Module._resolveFilename;
|
|
620
|
-
const
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
645
|
+
const rootParent = {
|
|
646
|
+
id: "__webframez_react_worker__",
|
|
647
|
+
filename: path.join(process.cwd(), "__webframez_react_worker__.js"),
|
|
648
|
+
path: process.cwd(),
|
|
649
|
+
paths: Module._nodeModulePaths(process.cwd()),
|
|
650
|
+
};
|
|
651
|
+
const forcedPackageRequests = [
|
|
652
|
+
"@webtypen/webframez-core",
|
|
653
|
+
"@webtypen/webframez-react",
|
|
654
|
+
"react",
|
|
655
|
+
"react/jsx-runtime",
|
|
656
|
+
"react/jsx-dev-runtime",
|
|
657
|
+
"react-dom",
|
|
658
|
+
"react-dom/client",
|
|
659
|
+
"react-dom/server",
|
|
660
|
+
"react-dom/server.node",
|
|
661
|
+
"react-server-dom-webpack",
|
|
662
|
+
"react-server-dom-webpack/server",
|
|
663
|
+
"react-server-dom-webpack/client",
|
|
664
|
+
"react-server-dom-webpack/client.node",
|
|
665
|
+
"scheduler"
|
|
666
|
+
];
|
|
667
|
+
|
|
668
|
+
function shouldForcePackageResolution(request) {
|
|
669
|
+
return forcedPackageRequests.some((candidate) =>
|
|
670
|
+
request === candidate || request.startsWith(candidate + "/")
|
|
671
|
+
);
|
|
672
|
+
}
|
|
626
673
|
|
|
627
674
|
Module._resolveFilename = function(request, parent, isMain, options) {
|
|
628
|
-
if (
|
|
629
|
-
return
|
|
675
|
+
if (typeof request === "string" && shouldForcePackageResolution(request)) {
|
|
676
|
+
return originalResolveFilename.call(this, request, rootParent, false, options);
|
|
630
677
|
}
|
|
631
678
|
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
632
679
|
};
|
|
@@ -673,21 +720,58 @@ function renderHtml(model) {
|
|
|
673
720
|
});
|
|
674
721
|
}
|
|
675
722
|
|
|
723
|
+
function createReadableStreamFromString(value) {
|
|
724
|
+
const encoder = new TextEncoder();
|
|
725
|
+
|
|
726
|
+
return new ReadableStream({
|
|
727
|
+
start(controller) {
|
|
728
|
+
controller.enqueue(encoder.encode(value));
|
|
729
|
+
controller.close();
|
|
730
|
+
}
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
735
|
+
const model = await createFromReadableStream(createReadableStreamFromString(flightData), {
|
|
736
|
+
serverConsumerManifest: {
|
|
737
|
+
moduleMap: moduleMap || {},
|
|
738
|
+
serverModuleMap: null,
|
|
739
|
+
moduleLoading: null
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
|
|
743
|
+
return renderHtml(model);
|
|
744
|
+
}
|
|
745
|
+
|
|
676
746
|
process.on("message", async (message) => {
|
|
677
|
-
if (!message || message.type !== "render") {
|
|
747
|
+
if (!message || (message.type !== "render-route" && message.type !== "render-flight")) {
|
|
678
748
|
return;
|
|
679
749
|
}
|
|
680
750
|
|
|
681
|
-
const previousBasename = globalThis.__RSC_BASENAME;
|
|
682
|
-
globalThis.__RSC_BASENAME = message.payload.basename || "";
|
|
683
|
-
|
|
684
751
|
try {
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
752
|
+
let html = "";
|
|
753
|
+
|
|
754
|
+
if (message.type === "render-route") {
|
|
755
|
+
const previousBasename = globalThis.__RSC_BASENAME;
|
|
756
|
+
globalThis.__RSC_BASENAME = message.payload.basename || "";
|
|
757
|
+
|
|
758
|
+
try {
|
|
759
|
+
const resolved = await router.resolve({
|
|
760
|
+
pathname: message.payload.pathname,
|
|
761
|
+
searchParams: message.payload.searchParams || {},
|
|
762
|
+
cookies: message.payload.cookies || {},
|
|
763
|
+
});
|
|
764
|
+
html = await renderHtml(resolved.model);
|
|
765
|
+
} finally {
|
|
766
|
+
globalThis.__RSC_BASENAME = previousBasename;
|
|
767
|
+
}
|
|
768
|
+
} else {
|
|
769
|
+
html = await renderHtmlFromFlightData(
|
|
770
|
+
message.payload.flightData || "",
|
|
771
|
+
message.payload.moduleMap || {},
|
|
772
|
+
);
|
|
773
|
+
}
|
|
774
|
+
|
|
691
775
|
if (typeof process.send === "function") {
|
|
692
776
|
process.send({ id: message.id, ok: true, html });
|
|
693
777
|
}
|
|
@@ -698,8 +782,6 @@ process.on("message", async (message) => {
|
|
|
698
782
|
if (typeof process.send === "function") {
|
|
699
783
|
process.send({ id: message.id, ok: false, error: formatted });
|
|
700
784
|
}
|
|
701
|
-
} finally {
|
|
702
|
-
globalThis.__RSC_BASENAME = previousBasename;
|
|
703
785
|
}
|
|
704
786
|
});
|
|
705
787
|
`;
|
|
@@ -811,7 +893,35 @@ ${stderrBuffer.trim()}` : "";
|
|
|
811
893
|
pending.set(requestId, { resolve, reject, timeout });
|
|
812
894
|
const request = {
|
|
813
895
|
id: requestId,
|
|
814
|
-
type: "render",
|
|
896
|
+
type: "render-route",
|
|
897
|
+
payload
|
|
898
|
+
};
|
|
899
|
+
activeChild.send(request, (error) => {
|
|
900
|
+
if (!error) {
|
|
901
|
+
return;
|
|
902
|
+
}
|
|
903
|
+
const entry = pending.get(requestId);
|
|
904
|
+
if (!entry) {
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
pending.delete(requestId);
|
|
908
|
+
clearTimeout(entry.timeout);
|
|
909
|
+
entry.reject(error instanceof Error ? error : new Error(String(error)));
|
|
910
|
+
});
|
|
911
|
+
});
|
|
912
|
+
},
|
|
913
|
+
renderFromFlightData(payload) {
|
|
914
|
+
const activeChild = startWorker();
|
|
915
|
+
const requestId = nextRequestId++;
|
|
916
|
+
return new Promise((resolve, reject) => {
|
|
917
|
+
const timeout = setTimeout(() => {
|
|
918
|
+
rejectPending(new Error("[webframez-react] Initial HTML worker timed out"));
|
|
919
|
+
stopWorker();
|
|
920
|
+
}, 1e4);
|
|
921
|
+
pending.set(requestId, { resolve, reject, timeout });
|
|
922
|
+
const request = {
|
|
923
|
+
id: requestId,
|
|
924
|
+
type: "render-flight",
|
|
815
925
|
payload
|
|
816
926
|
};
|
|
817
927
|
activeChild.send(request, (error) => {
|
|
@@ -1062,7 +1172,11 @@ function createNodeRequestHandler(options) {
|
|
|
1062
1172
|
} catch (retryError) {
|
|
1063
1173
|
console.error("[webframez-react] Retry for initial HTML failed", retryError);
|
|
1064
1174
|
try {
|
|
1065
|
-
|
|
1175
|
+
initialHtmlWorker.dispose();
|
|
1176
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1177
|
+
flightData: initialFlightData,
|
|
1178
|
+
moduleMap
|
|
1179
|
+
});
|
|
1066
1180
|
} catch (flightRenderError) {
|
|
1067
1181
|
console.error("[webframez-react] Flight-to-HTML render failed", flightRenderError);
|
|
1068
1182
|
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 = {},
|
|
@@ -144,6 +122,7 @@ function sendRSC(res, model, options = {}) {
|
|
|
144
122
|
|
|
145
123
|
// src/file-router.tsx
|
|
146
124
|
import fs from "node:fs";
|
|
125
|
+
import Module from "node:module";
|
|
147
126
|
import path2 from "node:path";
|
|
148
127
|
|
|
149
128
|
// src/router-runtime.tsx
|
|
@@ -206,6 +185,23 @@ function injectRouteChildren(node, routeChildren) {
|
|
|
206
185
|
|
|
207
186
|
// src/file-router.tsx
|
|
208
187
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
188
|
+
var FORCED_PACKAGE_REQUESTS = [
|
|
189
|
+
"@webtypen/webframez-core",
|
|
190
|
+
"@webtypen/webframez-react",
|
|
191
|
+
"react",
|
|
192
|
+
"react/jsx-runtime",
|
|
193
|
+
"react/jsx-dev-runtime",
|
|
194
|
+
"react-dom",
|
|
195
|
+
"react-dom/client",
|
|
196
|
+
"react-dom/server",
|
|
197
|
+
"react-dom/server.node",
|
|
198
|
+
"react-server-dom-webpack",
|
|
199
|
+
"react-server-dom-webpack/server",
|
|
200
|
+
"react-server-dom-webpack/client",
|
|
201
|
+
"react-server-dom-webpack/client.node",
|
|
202
|
+
"scheduler"
|
|
203
|
+
];
|
|
204
|
+
var forcedPackageResolutionInstalled = false;
|
|
209
205
|
function normalizePathname(pathname) {
|
|
210
206
|
const trimmed = pathname.replace(/\/+$/, "") || "/";
|
|
211
207
|
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
@@ -254,6 +250,34 @@ var MANAGED_HEAD_ATTR = "data-webframez-head";
|
|
|
254
250
|
function createManagedAttributes() {
|
|
255
251
|
return `${MANAGED_HEAD_ATTR}="true"`;
|
|
256
252
|
}
|
|
253
|
+
function shouldForcePackageResolution(request) {
|
|
254
|
+
return FORCED_PACKAGE_REQUESTS.some(
|
|
255
|
+
(candidate) => request === candidate || request.startsWith(`${candidate}/`)
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
function installForcedPackageResolution() {
|
|
259
|
+
if (forcedPackageResolutionInstalled) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const moduleWithPrivateResolver = Module;
|
|
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
|
+
};
|
|
270
|
+
moduleWithPrivateResolver._resolveFilename = function patchedResolveFilename(request, parent, isMain, options) {
|
|
271
|
+
if (typeof request === "string" && shouldForcePackageResolution(request)) {
|
|
272
|
+
try {
|
|
273
|
+
return originalResolveFilename.call(this, request, rootParent, false, options);
|
|
274
|
+
} catch {
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
278
|
+
};
|
|
279
|
+
forcedPackageResolutionInstalled = true;
|
|
280
|
+
}
|
|
257
281
|
function toRouteEntry(pagesDir, filePath) {
|
|
258
282
|
const normalized = filePath.replace(/\\/g, "/");
|
|
259
283
|
if (!normalized.endsWith("/index.js")) {
|
|
@@ -401,6 +425,7 @@ function isRouteAbort(value) {
|
|
|
401
425
|
}
|
|
402
426
|
}
|
|
403
427
|
function createFileRouter(options) {
|
|
428
|
+
installForcedPackageResolution();
|
|
404
429
|
const pagesDir = options.pagesDir;
|
|
405
430
|
const layoutPath = path2.join(pagesDir, "layout.js");
|
|
406
431
|
const errorPath = path2.join(pagesDir, "errors.js");
|
|
@@ -584,24 +609,46 @@ var INITIAL_HTML_WORKER_SCRIPT = `
|
|
|
584
609
|
const path = require("node:path");
|
|
585
610
|
const Module = require("node:module");
|
|
586
611
|
const { Writable } = require("node:stream");
|
|
612
|
+
const { createFromReadableStream } = require("react-server-dom-webpack/client.node");
|
|
587
613
|
|
|
588
614
|
const pagesDir = process.env.WEBFRAMEZ_REACT_PAGES_DIR || "";
|
|
589
615
|
if (!pagesDir) {
|
|
590
616
|
throw new Error("Missing WEBFRAMEZ_REACT_PAGES_DIR");
|
|
591
617
|
}
|
|
592
618
|
|
|
593
|
-
const appRequire = Module.createRequire(path.join(pagesDir, "__webframez_react_worker__.js"));
|
|
594
619
|
const originalResolveFilename = Module._resolveFilename;
|
|
595
|
-
const
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
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
|
+
}
|
|
601
648
|
|
|
602
649
|
Module._resolveFilename = function(request, parent, isMain, options) {
|
|
603
|
-
if (
|
|
604
|
-
return
|
|
650
|
+
if (typeof request === "string" && shouldForcePackageResolution(request)) {
|
|
651
|
+
return originalResolveFilename.call(this, request, rootParent, false, options);
|
|
605
652
|
}
|
|
606
653
|
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
607
654
|
};
|
|
@@ -648,21 +695,58 @@ function renderHtml(model) {
|
|
|
648
695
|
});
|
|
649
696
|
}
|
|
650
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
|
+
|
|
651
721
|
process.on("message", async (message) => {
|
|
652
|
-
if (!message || message.type !== "render") {
|
|
722
|
+
if (!message || (message.type !== "render-route" && message.type !== "render-flight")) {
|
|
653
723
|
return;
|
|
654
724
|
}
|
|
655
725
|
|
|
656
|
-
const previousBasename = globalThis.__RSC_BASENAME;
|
|
657
|
-
globalThis.__RSC_BASENAME = message.payload.basename || "";
|
|
658
|
-
|
|
659
726
|
try {
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
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
|
+
|
|
666
750
|
if (typeof process.send === "function") {
|
|
667
751
|
process.send({ id: message.id, ok: true, html });
|
|
668
752
|
}
|
|
@@ -673,8 +757,6 @@ process.on("message", async (message) => {
|
|
|
673
757
|
if (typeof process.send === "function") {
|
|
674
758
|
process.send({ id: message.id, ok: false, error: formatted });
|
|
675
759
|
}
|
|
676
|
-
} finally {
|
|
677
|
-
globalThis.__RSC_BASENAME = previousBasename;
|
|
678
760
|
}
|
|
679
761
|
});
|
|
680
762
|
`;
|
|
@@ -786,7 +868,35 @@ ${stderrBuffer.trim()}` : "";
|
|
|
786
868
|
pending.set(requestId, { resolve, reject, timeout });
|
|
787
869
|
const request = {
|
|
788
870
|
id: requestId,
|
|
789
|
-
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",
|
|
790
900
|
payload
|
|
791
901
|
};
|
|
792
902
|
activeChild.send(request, (error) => {
|
|
@@ -1037,7 +1147,11 @@ function createNodeRequestHandler(options) {
|
|
|
1037
1147
|
} catch (retryError) {
|
|
1038
1148
|
console.error("[webframez-react] Retry for initial HTML failed", retryError);
|
|
1039
1149
|
try {
|
|
1040
|
-
|
|
1150
|
+
initialHtmlWorker.dispose();
|
|
1151
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1152
|
+
flightData: initialFlightData,
|
|
1153
|
+
moduleMap
|
|
1154
|
+
});
|
|
1041
1155
|
} catch (flightRenderError) {
|
|
1042
1156
|
console.error("[webframez-react] Flight-to-HTML render failed", flightRenderError);
|
|
1043
1157
|
res.statusCode = 500;
|