@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/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 = {},
|
|
@@ -202,6 +180,7 @@ function createRSCHandler(options) {
|
|
|
202
180
|
|
|
203
181
|
// src/file-router.tsx
|
|
204
182
|
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
183
|
+
var import_node_module2 = __toESM(require("node:module"), 1);
|
|
205
184
|
var import_node_path2 = __toESM(require("node:path"), 1);
|
|
206
185
|
|
|
207
186
|
// src/router-runtime.tsx
|
|
@@ -264,6 +243,23 @@ function injectRouteChildren(node, routeChildren) {
|
|
|
264
243
|
|
|
265
244
|
// src/file-router.tsx
|
|
266
245
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
246
|
+
var FORCED_PACKAGE_REQUESTS = [
|
|
247
|
+
"@webtypen/webframez-core",
|
|
248
|
+
"@webtypen/webframez-react",
|
|
249
|
+
"react",
|
|
250
|
+
"react/jsx-runtime",
|
|
251
|
+
"react/jsx-dev-runtime",
|
|
252
|
+
"react-dom",
|
|
253
|
+
"react-dom/client",
|
|
254
|
+
"react-dom/server",
|
|
255
|
+
"react-dom/server.node",
|
|
256
|
+
"react-server-dom-webpack",
|
|
257
|
+
"react-server-dom-webpack/server",
|
|
258
|
+
"react-server-dom-webpack/client",
|
|
259
|
+
"react-server-dom-webpack/client.node",
|
|
260
|
+
"scheduler"
|
|
261
|
+
];
|
|
262
|
+
var forcedPackageResolutionInstalled = false;
|
|
267
263
|
function normalizePathname(pathname) {
|
|
268
264
|
const trimmed = pathname.replace(/\/+$/, "") || "/";
|
|
269
265
|
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
@@ -312,6 +308,34 @@ var MANAGED_HEAD_ATTR = "data-webframez-head";
|
|
|
312
308
|
function createManagedAttributes() {
|
|
313
309
|
return `${MANAGED_HEAD_ATTR}="true"`;
|
|
314
310
|
}
|
|
311
|
+
function shouldForcePackageResolution(request) {
|
|
312
|
+
return FORCED_PACKAGE_REQUESTS.some(
|
|
313
|
+
(candidate) => request === candidate || request.startsWith(`${candidate}/`)
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
function installForcedPackageResolution() {
|
|
317
|
+
if (forcedPackageResolutionInstalled) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
const moduleWithPrivateResolver = import_node_module2.default;
|
|
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
|
+
};
|
|
328
|
+
moduleWithPrivateResolver._resolveFilename = function patchedResolveFilename(request, parent, isMain, options) {
|
|
329
|
+
if (typeof request === "string" && shouldForcePackageResolution(request)) {
|
|
330
|
+
try {
|
|
331
|
+
return originalResolveFilename.call(this, request, rootParent, false, options);
|
|
332
|
+
} catch {
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
336
|
+
};
|
|
337
|
+
forcedPackageResolutionInstalled = true;
|
|
338
|
+
}
|
|
315
339
|
function toRouteEntry(pagesDir, filePath) {
|
|
316
340
|
const normalized = filePath.replace(/\\/g, "/");
|
|
317
341
|
if (!normalized.endsWith("/index.js")) {
|
|
@@ -459,6 +483,7 @@ function isRouteAbort(value) {
|
|
|
459
483
|
}
|
|
460
484
|
}
|
|
461
485
|
function createFileRouter(options) {
|
|
486
|
+
installForcedPackageResolution();
|
|
462
487
|
const pagesDir = options.pagesDir;
|
|
463
488
|
const layoutPath = import_node_path2.default.join(pagesDir, "layout.js");
|
|
464
489
|
const errorPath = import_node_path2.default.join(pagesDir, "errors.js");
|
|
@@ -646,24 +671,46 @@ var INITIAL_HTML_WORKER_SCRIPT = `
|
|
|
646
671
|
const path = require("node:path");
|
|
647
672
|
const Module = require("node:module");
|
|
648
673
|
const { Writable } = require("node:stream");
|
|
674
|
+
const { createFromReadableStream } = require("react-server-dom-webpack/client.node");
|
|
649
675
|
|
|
650
676
|
const pagesDir = process.env.WEBFRAMEZ_REACT_PAGES_DIR || "";
|
|
651
677
|
if (!pagesDir) {
|
|
652
678
|
throw new Error("Missing WEBFRAMEZ_REACT_PAGES_DIR");
|
|
653
679
|
}
|
|
654
680
|
|
|
655
|
-
const appRequire = Module.createRequire(path.join(pagesDir, "__webframez_react_worker__.js"));
|
|
656
681
|
const originalResolveFilename = Module._resolveFilename;
|
|
657
|
-
const
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
682
|
+
const rootParent = {
|
|
683
|
+
id: "__webframez_react_worker__",
|
|
684
|
+
filename: path.join(process.cwd(), "__webframez_react_worker__.js"),
|
|
685
|
+
path: process.cwd(),
|
|
686
|
+
paths: Module._nodeModulePaths(process.cwd()),
|
|
687
|
+
};
|
|
688
|
+
const forcedPackageRequests = [
|
|
689
|
+
"@webtypen/webframez-core",
|
|
690
|
+
"@webtypen/webframez-react",
|
|
691
|
+
"react",
|
|
692
|
+
"react/jsx-runtime",
|
|
693
|
+
"react/jsx-dev-runtime",
|
|
694
|
+
"react-dom",
|
|
695
|
+
"react-dom/client",
|
|
696
|
+
"react-dom/server",
|
|
697
|
+
"react-dom/server.node",
|
|
698
|
+
"react-server-dom-webpack",
|
|
699
|
+
"react-server-dom-webpack/server",
|
|
700
|
+
"react-server-dom-webpack/client",
|
|
701
|
+
"react-server-dom-webpack/client.node",
|
|
702
|
+
"scheduler"
|
|
703
|
+
];
|
|
704
|
+
|
|
705
|
+
function shouldForcePackageResolution(request) {
|
|
706
|
+
return forcedPackageRequests.some((candidate) =>
|
|
707
|
+
request === candidate || request.startsWith(candidate + "/")
|
|
708
|
+
);
|
|
709
|
+
}
|
|
663
710
|
|
|
664
711
|
Module._resolveFilename = function(request, parent, isMain, options) {
|
|
665
|
-
if (
|
|
666
|
-
return
|
|
712
|
+
if (typeof request === "string" && shouldForcePackageResolution(request)) {
|
|
713
|
+
return originalResolveFilename.call(this, request, rootParent, false, options);
|
|
667
714
|
}
|
|
668
715
|
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
669
716
|
};
|
|
@@ -710,21 +757,58 @@ function renderHtml(model) {
|
|
|
710
757
|
});
|
|
711
758
|
}
|
|
712
759
|
|
|
760
|
+
function createReadableStreamFromString(value) {
|
|
761
|
+
const encoder = new TextEncoder();
|
|
762
|
+
|
|
763
|
+
return new ReadableStream({
|
|
764
|
+
start(controller) {
|
|
765
|
+
controller.enqueue(encoder.encode(value));
|
|
766
|
+
controller.close();
|
|
767
|
+
}
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
772
|
+
const model = await createFromReadableStream(createReadableStreamFromString(flightData), {
|
|
773
|
+
serverConsumerManifest: {
|
|
774
|
+
moduleMap: moduleMap || {},
|
|
775
|
+
serverModuleMap: null,
|
|
776
|
+
moduleLoading: null
|
|
777
|
+
}
|
|
778
|
+
});
|
|
779
|
+
|
|
780
|
+
return renderHtml(model);
|
|
781
|
+
}
|
|
782
|
+
|
|
713
783
|
process.on("message", async (message) => {
|
|
714
|
-
if (!message || message.type !== "render") {
|
|
784
|
+
if (!message || (message.type !== "render-route" && message.type !== "render-flight")) {
|
|
715
785
|
return;
|
|
716
786
|
}
|
|
717
787
|
|
|
718
|
-
const previousBasename = globalThis.__RSC_BASENAME;
|
|
719
|
-
globalThis.__RSC_BASENAME = message.payload.basename || "";
|
|
720
|
-
|
|
721
788
|
try {
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
789
|
+
let html = "";
|
|
790
|
+
|
|
791
|
+
if (message.type === "render-route") {
|
|
792
|
+
const previousBasename = globalThis.__RSC_BASENAME;
|
|
793
|
+
globalThis.__RSC_BASENAME = message.payload.basename || "";
|
|
794
|
+
|
|
795
|
+
try {
|
|
796
|
+
const resolved = await router.resolve({
|
|
797
|
+
pathname: message.payload.pathname,
|
|
798
|
+
searchParams: message.payload.searchParams || {},
|
|
799
|
+
cookies: message.payload.cookies || {},
|
|
800
|
+
});
|
|
801
|
+
html = await renderHtml(resolved.model);
|
|
802
|
+
} finally {
|
|
803
|
+
globalThis.__RSC_BASENAME = previousBasename;
|
|
804
|
+
}
|
|
805
|
+
} else {
|
|
806
|
+
html = await renderHtmlFromFlightData(
|
|
807
|
+
message.payload.flightData || "",
|
|
808
|
+
message.payload.moduleMap || {},
|
|
809
|
+
);
|
|
810
|
+
}
|
|
811
|
+
|
|
728
812
|
if (typeof process.send === "function") {
|
|
729
813
|
process.send({ id: message.id, ok: true, html });
|
|
730
814
|
}
|
|
@@ -735,8 +819,6 @@ process.on("message", async (message) => {
|
|
|
735
819
|
if (typeof process.send === "function") {
|
|
736
820
|
process.send({ id: message.id, ok: false, error: formatted });
|
|
737
821
|
}
|
|
738
|
-
} finally {
|
|
739
|
-
globalThis.__RSC_BASENAME = previousBasename;
|
|
740
822
|
}
|
|
741
823
|
});
|
|
742
824
|
`;
|
|
@@ -848,7 +930,35 @@ ${stderrBuffer.trim()}` : "";
|
|
|
848
930
|
pending.set(requestId, { resolve, reject, timeout });
|
|
849
931
|
const request = {
|
|
850
932
|
id: requestId,
|
|
851
|
-
type: "render",
|
|
933
|
+
type: "render-route",
|
|
934
|
+
payload
|
|
935
|
+
};
|
|
936
|
+
activeChild.send(request, (error) => {
|
|
937
|
+
if (!error) {
|
|
938
|
+
return;
|
|
939
|
+
}
|
|
940
|
+
const entry = pending.get(requestId);
|
|
941
|
+
if (!entry) {
|
|
942
|
+
return;
|
|
943
|
+
}
|
|
944
|
+
pending.delete(requestId);
|
|
945
|
+
clearTimeout(entry.timeout);
|
|
946
|
+
entry.reject(error instanceof Error ? error : new Error(String(error)));
|
|
947
|
+
});
|
|
948
|
+
});
|
|
949
|
+
},
|
|
950
|
+
renderFromFlightData(payload) {
|
|
951
|
+
const activeChild = startWorker();
|
|
952
|
+
const requestId = nextRequestId++;
|
|
953
|
+
return new Promise((resolve, reject) => {
|
|
954
|
+
const timeout = setTimeout(() => {
|
|
955
|
+
rejectPending(new Error("[webframez-react] Initial HTML worker timed out"));
|
|
956
|
+
stopWorker();
|
|
957
|
+
}, 1e4);
|
|
958
|
+
pending.set(requestId, { resolve, reject, timeout });
|
|
959
|
+
const request = {
|
|
960
|
+
id: requestId,
|
|
961
|
+
type: "render-flight",
|
|
852
962
|
payload
|
|
853
963
|
};
|
|
854
964
|
activeChild.send(request, (error) => {
|
|
@@ -1099,7 +1209,11 @@ function createNodeRequestHandler(options) {
|
|
|
1099
1209
|
} catch (retryError) {
|
|
1100
1210
|
console.error("[webframez-react] Retry for initial HTML failed", retryError);
|
|
1101
1211
|
try {
|
|
1102
|
-
|
|
1212
|
+
initialHtmlWorker.dispose();
|
|
1213
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1214
|
+
flightData: initialFlightData,
|
|
1215
|
+
moduleMap
|
|
1216
|
+
});
|
|
1103
1217
|
} catch (flightRenderError) {
|
|
1104
1218
|
console.error("[webframez-react] Flight-to-HTML render failed", flightRenderError);
|
|
1105
1219
|
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 = {},
|
|
@@ -166,6 +144,7 @@ function createRSCHandler(options) {
|
|
|
166
144
|
|
|
167
145
|
// src/file-router.tsx
|
|
168
146
|
import fs from "node:fs";
|
|
147
|
+
import Module from "node:module";
|
|
169
148
|
import path2 from "node:path";
|
|
170
149
|
|
|
171
150
|
// src/router-runtime.tsx
|
|
@@ -228,6 +207,23 @@ function injectRouteChildren(node, routeChildren) {
|
|
|
228
207
|
|
|
229
208
|
// src/file-router.tsx
|
|
230
209
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
210
|
+
var FORCED_PACKAGE_REQUESTS = [
|
|
211
|
+
"@webtypen/webframez-core",
|
|
212
|
+
"@webtypen/webframez-react",
|
|
213
|
+
"react",
|
|
214
|
+
"react/jsx-runtime",
|
|
215
|
+
"react/jsx-dev-runtime",
|
|
216
|
+
"react-dom",
|
|
217
|
+
"react-dom/client",
|
|
218
|
+
"react-dom/server",
|
|
219
|
+
"react-dom/server.node",
|
|
220
|
+
"react-server-dom-webpack",
|
|
221
|
+
"react-server-dom-webpack/server",
|
|
222
|
+
"react-server-dom-webpack/client",
|
|
223
|
+
"react-server-dom-webpack/client.node",
|
|
224
|
+
"scheduler"
|
|
225
|
+
];
|
|
226
|
+
var forcedPackageResolutionInstalled = false;
|
|
231
227
|
function normalizePathname(pathname) {
|
|
232
228
|
const trimmed = pathname.replace(/\/+$/, "") || "/";
|
|
233
229
|
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
@@ -276,6 +272,34 @@ var MANAGED_HEAD_ATTR = "data-webframez-head";
|
|
|
276
272
|
function createManagedAttributes() {
|
|
277
273
|
return `${MANAGED_HEAD_ATTR}="true"`;
|
|
278
274
|
}
|
|
275
|
+
function shouldForcePackageResolution(request) {
|
|
276
|
+
return FORCED_PACKAGE_REQUESTS.some(
|
|
277
|
+
(candidate) => request === candidate || request.startsWith(`${candidate}/`)
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
function installForcedPackageResolution() {
|
|
281
|
+
if (forcedPackageResolutionInstalled) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const moduleWithPrivateResolver = Module;
|
|
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
|
+
};
|
|
292
|
+
moduleWithPrivateResolver._resolveFilename = function patchedResolveFilename(request, parent, isMain, options) {
|
|
293
|
+
if (typeof request === "string" && shouldForcePackageResolution(request)) {
|
|
294
|
+
try {
|
|
295
|
+
return originalResolveFilename.call(this, request, rootParent, false, options);
|
|
296
|
+
} catch {
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
300
|
+
};
|
|
301
|
+
forcedPackageResolutionInstalled = true;
|
|
302
|
+
}
|
|
279
303
|
function toRouteEntry(pagesDir, filePath) {
|
|
280
304
|
const normalized = filePath.replace(/\\/g, "/");
|
|
281
305
|
if (!normalized.endsWith("/index.js")) {
|
|
@@ -423,6 +447,7 @@ function isRouteAbort(value) {
|
|
|
423
447
|
}
|
|
424
448
|
}
|
|
425
449
|
function createFileRouter(options) {
|
|
450
|
+
installForcedPackageResolution();
|
|
426
451
|
const pagesDir = options.pagesDir;
|
|
427
452
|
const layoutPath = path2.join(pagesDir, "layout.js");
|
|
428
453
|
const errorPath = path2.join(pagesDir, "errors.js");
|
|
@@ -610,24 +635,46 @@ var INITIAL_HTML_WORKER_SCRIPT = `
|
|
|
610
635
|
const path = require("node:path");
|
|
611
636
|
const Module = require("node:module");
|
|
612
637
|
const { Writable } = require("node:stream");
|
|
638
|
+
const { createFromReadableStream } = require("react-server-dom-webpack/client.node");
|
|
613
639
|
|
|
614
640
|
const pagesDir = process.env.WEBFRAMEZ_REACT_PAGES_DIR || "";
|
|
615
641
|
if (!pagesDir) {
|
|
616
642
|
throw new Error("Missing WEBFRAMEZ_REACT_PAGES_DIR");
|
|
617
643
|
}
|
|
618
644
|
|
|
619
|
-
const appRequire = Module.createRequire(path.join(pagesDir, "__webframez_react_worker__.js"));
|
|
620
645
|
const originalResolveFilename = Module._resolveFilename;
|
|
621
|
-
const
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
646
|
+
const rootParent = {
|
|
647
|
+
id: "__webframez_react_worker__",
|
|
648
|
+
filename: path.join(process.cwd(), "__webframez_react_worker__.js"),
|
|
649
|
+
path: process.cwd(),
|
|
650
|
+
paths: Module._nodeModulePaths(process.cwd()),
|
|
651
|
+
};
|
|
652
|
+
const forcedPackageRequests = [
|
|
653
|
+
"@webtypen/webframez-core",
|
|
654
|
+
"@webtypen/webframez-react",
|
|
655
|
+
"react",
|
|
656
|
+
"react/jsx-runtime",
|
|
657
|
+
"react/jsx-dev-runtime",
|
|
658
|
+
"react-dom",
|
|
659
|
+
"react-dom/client",
|
|
660
|
+
"react-dom/server",
|
|
661
|
+
"react-dom/server.node",
|
|
662
|
+
"react-server-dom-webpack",
|
|
663
|
+
"react-server-dom-webpack/server",
|
|
664
|
+
"react-server-dom-webpack/client",
|
|
665
|
+
"react-server-dom-webpack/client.node",
|
|
666
|
+
"scheduler"
|
|
667
|
+
];
|
|
668
|
+
|
|
669
|
+
function shouldForcePackageResolution(request) {
|
|
670
|
+
return forcedPackageRequests.some((candidate) =>
|
|
671
|
+
request === candidate || request.startsWith(candidate + "/")
|
|
672
|
+
);
|
|
673
|
+
}
|
|
627
674
|
|
|
628
675
|
Module._resolveFilename = function(request, parent, isMain, options) {
|
|
629
|
-
if (
|
|
630
|
-
return
|
|
676
|
+
if (typeof request === "string" && shouldForcePackageResolution(request)) {
|
|
677
|
+
return originalResolveFilename.call(this, request, rootParent, false, options);
|
|
631
678
|
}
|
|
632
679
|
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
633
680
|
};
|
|
@@ -674,21 +721,58 @@ function renderHtml(model) {
|
|
|
674
721
|
});
|
|
675
722
|
}
|
|
676
723
|
|
|
724
|
+
function createReadableStreamFromString(value) {
|
|
725
|
+
const encoder = new TextEncoder();
|
|
726
|
+
|
|
727
|
+
return new ReadableStream({
|
|
728
|
+
start(controller) {
|
|
729
|
+
controller.enqueue(encoder.encode(value));
|
|
730
|
+
controller.close();
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
736
|
+
const model = await createFromReadableStream(createReadableStreamFromString(flightData), {
|
|
737
|
+
serverConsumerManifest: {
|
|
738
|
+
moduleMap: moduleMap || {},
|
|
739
|
+
serverModuleMap: null,
|
|
740
|
+
moduleLoading: null
|
|
741
|
+
}
|
|
742
|
+
});
|
|
743
|
+
|
|
744
|
+
return renderHtml(model);
|
|
745
|
+
}
|
|
746
|
+
|
|
677
747
|
process.on("message", async (message) => {
|
|
678
|
-
if (!message || message.type !== "render") {
|
|
748
|
+
if (!message || (message.type !== "render-route" && message.type !== "render-flight")) {
|
|
679
749
|
return;
|
|
680
750
|
}
|
|
681
751
|
|
|
682
|
-
const previousBasename = globalThis.__RSC_BASENAME;
|
|
683
|
-
globalThis.__RSC_BASENAME = message.payload.basename || "";
|
|
684
|
-
|
|
685
752
|
try {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
753
|
+
let html = "";
|
|
754
|
+
|
|
755
|
+
if (message.type === "render-route") {
|
|
756
|
+
const previousBasename = globalThis.__RSC_BASENAME;
|
|
757
|
+
globalThis.__RSC_BASENAME = message.payload.basename || "";
|
|
758
|
+
|
|
759
|
+
try {
|
|
760
|
+
const resolved = await router.resolve({
|
|
761
|
+
pathname: message.payload.pathname,
|
|
762
|
+
searchParams: message.payload.searchParams || {},
|
|
763
|
+
cookies: message.payload.cookies || {},
|
|
764
|
+
});
|
|
765
|
+
html = await renderHtml(resolved.model);
|
|
766
|
+
} finally {
|
|
767
|
+
globalThis.__RSC_BASENAME = previousBasename;
|
|
768
|
+
}
|
|
769
|
+
} else {
|
|
770
|
+
html = await renderHtmlFromFlightData(
|
|
771
|
+
message.payload.flightData || "",
|
|
772
|
+
message.payload.moduleMap || {},
|
|
773
|
+
);
|
|
774
|
+
}
|
|
775
|
+
|
|
692
776
|
if (typeof process.send === "function") {
|
|
693
777
|
process.send({ id: message.id, ok: true, html });
|
|
694
778
|
}
|
|
@@ -699,8 +783,6 @@ process.on("message", async (message) => {
|
|
|
699
783
|
if (typeof process.send === "function") {
|
|
700
784
|
process.send({ id: message.id, ok: false, error: formatted });
|
|
701
785
|
}
|
|
702
|
-
} finally {
|
|
703
|
-
globalThis.__RSC_BASENAME = previousBasename;
|
|
704
786
|
}
|
|
705
787
|
});
|
|
706
788
|
`;
|
|
@@ -812,7 +894,35 @@ ${stderrBuffer.trim()}` : "";
|
|
|
812
894
|
pending.set(requestId, { resolve, reject, timeout });
|
|
813
895
|
const request = {
|
|
814
896
|
id: requestId,
|
|
815
|
-
type: "render",
|
|
897
|
+
type: "render-route",
|
|
898
|
+
payload
|
|
899
|
+
};
|
|
900
|
+
activeChild.send(request, (error) => {
|
|
901
|
+
if (!error) {
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
const entry = pending.get(requestId);
|
|
905
|
+
if (!entry) {
|
|
906
|
+
return;
|
|
907
|
+
}
|
|
908
|
+
pending.delete(requestId);
|
|
909
|
+
clearTimeout(entry.timeout);
|
|
910
|
+
entry.reject(error instanceof Error ? error : new Error(String(error)));
|
|
911
|
+
});
|
|
912
|
+
});
|
|
913
|
+
},
|
|
914
|
+
renderFromFlightData(payload) {
|
|
915
|
+
const activeChild = startWorker();
|
|
916
|
+
const requestId = nextRequestId++;
|
|
917
|
+
return new Promise((resolve, reject) => {
|
|
918
|
+
const timeout = setTimeout(() => {
|
|
919
|
+
rejectPending(new Error("[webframez-react] Initial HTML worker timed out"));
|
|
920
|
+
stopWorker();
|
|
921
|
+
}, 1e4);
|
|
922
|
+
pending.set(requestId, { resolve, reject, timeout });
|
|
923
|
+
const request = {
|
|
924
|
+
id: requestId,
|
|
925
|
+
type: "render-flight",
|
|
816
926
|
payload
|
|
817
927
|
};
|
|
818
928
|
activeChild.send(request, (error) => {
|
|
@@ -1063,7 +1173,11 @@ function createNodeRequestHandler(options) {
|
|
|
1063
1173
|
} catch (retryError) {
|
|
1064
1174
|
console.error("[webframez-react] Retry for initial HTML failed", retryError);
|
|
1065
1175
|
try {
|
|
1066
|
-
|
|
1176
|
+
initialHtmlWorker.dispose();
|
|
1177
|
+
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1178
|
+
flightData: initialFlightData,
|
|
1179
|
+
moduleMap
|
|
1180
|
+
});
|
|
1067
1181
|
} catch (flightRenderError) {
|
|
1068
1182
|
console.error("[webframez-react] Flight-to-HTML render failed", flightRenderError);
|
|
1069
1183
|
res.statusCode = 500;
|
package/dist/router.cjs
CHANGED
|
@@ -38,6 +38,7 @@ module.exports = __toCommonJS(router_exports);
|
|
|
38
38
|
|
|
39
39
|
// src/file-router.tsx
|
|
40
40
|
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
41
|
+
var import_node_module = __toESM(require("node:module"), 1);
|
|
41
42
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
42
43
|
|
|
43
44
|
// src/router-runtime.tsx
|
|
@@ -100,6 +101,23 @@ function injectRouteChildren(node, routeChildren) {
|
|
|
100
101
|
|
|
101
102
|
// src/file-router.tsx
|
|
102
103
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
104
|
+
var FORCED_PACKAGE_REQUESTS = [
|
|
105
|
+
"@webtypen/webframez-core",
|
|
106
|
+
"@webtypen/webframez-react",
|
|
107
|
+
"react",
|
|
108
|
+
"react/jsx-runtime",
|
|
109
|
+
"react/jsx-dev-runtime",
|
|
110
|
+
"react-dom",
|
|
111
|
+
"react-dom/client",
|
|
112
|
+
"react-dom/server",
|
|
113
|
+
"react-dom/server.node",
|
|
114
|
+
"react-server-dom-webpack",
|
|
115
|
+
"react-server-dom-webpack/server",
|
|
116
|
+
"react-server-dom-webpack/client",
|
|
117
|
+
"react-server-dom-webpack/client.node",
|
|
118
|
+
"scheduler"
|
|
119
|
+
];
|
|
120
|
+
var forcedPackageResolutionInstalled = false;
|
|
103
121
|
function normalizePathname(pathname) {
|
|
104
122
|
const trimmed = pathname.replace(/\/+$/, "") || "/";
|
|
105
123
|
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
@@ -148,6 +166,34 @@ var MANAGED_HEAD_ATTR = "data-webframez-head";
|
|
|
148
166
|
function createManagedAttributes() {
|
|
149
167
|
return `${MANAGED_HEAD_ATTR}="true"`;
|
|
150
168
|
}
|
|
169
|
+
function shouldForcePackageResolution(request) {
|
|
170
|
+
return FORCED_PACKAGE_REQUESTS.some(
|
|
171
|
+
(candidate) => request === candidate || request.startsWith(`${candidate}/`)
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
function installForcedPackageResolution() {
|
|
175
|
+
if (forcedPackageResolutionInstalled) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
const moduleWithPrivateResolver = import_node_module.default;
|
|
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
|
+
};
|
|
186
|
+
moduleWithPrivateResolver._resolveFilename = function patchedResolveFilename(request, parent, isMain, options) {
|
|
187
|
+
if (typeof request === "string" && shouldForcePackageResolution(request)) {
|
|
188
|
+
try {
|
|
189
|
+
return originalResolveFilename.call(this, request, rootParent, false, options);
|
|
190
|
+
} catch {
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
194
|
+
};
|
|
195
|
+
forcedPackageResolutionInstalled = true;
|
|
196
|
+
}
|
|
151
197
|
function toRouteEntry(pagesDir, filePath) {
|
|
152
198
|
const normalized = filePath.replace(/\\/g, "/");
|
|
153
199
|
if (!normalized.endsWith("/index.js")) {
|
|
@@ -295,6 +341,7 @@ function isRouteAbort(value) {
|
|
|
295
341
|
}
|
|
296
342
|
}
|
|
297
343
|
function createFileRouter(options) {
|
|
344
|
+
installForcedPackageResolution();
|
|
298
345
|
const pagesDir = options.pagesDir;
|
|
299
346
|
const layoutPath = import_node_path.default.join(pagesDir, "layout.js");
|
|
300
347
|
const errorPath = import_node_path.default.join(pagesDir, "errors.js");
|