@cedarjs/vite 1.0.0-canary.12748 → 1.0.0-rc.26
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/bundled/react-server-dom-webpack.server.js +28517 -1379
- package/dist/cjs/devFeServer.js +15 -265
- package/dist/cjs/lib/registerFwGlobalsAndShims.js +0 -9
- package/dist/cjs/plugins/vite-plugin-rsc-ssr-router-import.js +2 -2
- package/dist/cjs/plugins/vite-plugin-rsc-transform-server.js +0 -4
- package/dist/cjs/rsc/rscRenderer.js +9 -23
- package/dist/cjs/rsc/rscRequestHandler.js +6 -6
- package/dist/cjs/runFeServer.js +22 -3
- package/dist/cjs/streaming/createReactStreamingHandler.js +10 -13
- package/dist/cjs/streaming/streamHelpers.js +30 -49
- package/dist/cjs/streaming/triggerRouteHooks.js +3 -3
- package/dist/devFeServer.js +16 -265
- package/dist/lib/registerFwGlobalsAndShims.js +0 -9
- package/dist/plugins/vite-plugin-rsc-ssr-router-import.d.ts.map +1 -1
- package/dist/plugins/vite-plugin-rsc-ssr-router-import.js +2 -2
- package/dist/plugins/vite-plugin-rsc-transform-server.d.ts.map +1 -1
- package/dist/plugins/vite-plugin-rsc-transform-server.js +0 -4
- package/dist/rsc/rscRenderer.d.ts.map +1 -1
- package/dist/rsc/rscRenderer.js +5 -19
- package/dist/rsc/rscRequestHandler.d.ts +2 -2
- package/dist/rsc/rscRequestHandler.d.ts.map +1 -1
- package/dist/rsc/rscRequestHandler.js +4 -4
- package/dist/runFeServer.js +21 -2
- package/dist/streaming/createReactStreamingHandler.d.ts +1 -1
- package/dist/streaming/createReactStreamingHandler.d.ts.map +1 -1
- package/dist/streaming/createReactStreamingHandler.js +10 -13
- package/dist/streaming/streamHelpers.d.ts +2 -2
- package/dist/streaming/streamHelpers.d.ts.map +1 -1
- package/dist/streaming/streamHelpers.js +29 -49
- package/dist/streaming/triggerRouteHooks.d.ts +2 -2
- package/dist/streaming/triggerRouteHooks.d.ts.map +1 -1
- package/dist/streaming/triggerRouteHooks.js +3 -3
- package/package.json +12 -12
- package/dist/cjs/rsc/rscWebSocketServer.js +0 -56
- package/dist/cjs/rsc/utils.js +0 -56
- package/dist/rsc/rscWebSocketServer.d.ts +0 -2
- package/dist/rsc/rscWebSocketServer.d.ts.map +0 -1
- package/dist/rsc/rscWebSocketServer.js +0 -22
- package/dist/rsc/utils.d.ts +0 -10
- package/dist/rsc/utils.d.ts.map +0 -1
- package/dist/rsc/utils.js +0 -21
package/dist/cjs/devFeServer.js
CHANGED
|
@@ -21,7 +21,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
22
|
mod
|
|
23
23
|
));
|
|
24
|
-
var import_node_http = __toESM(require("node:http"), 1);
|
|
25
24
|
var import_server = require("@whatwg-node/server");
|
|
26
25
|
var import_express = __toESM(require("express"), 1);
|
|
27
26
|
var import_vite = require("vite");
|
|
@@ -33,22 +32,14 @@ var import_registerFwGlobalsAndShims = require("./lib/registerFwGlobalsAndShims.
|
|
|
33
32
|
var import_invokeMiddleware = require("./middleware/invokeMiddleware.js");
|
|
34
33
|
var import_register = require("./middleware/register.js");
|
|
35
34
|
var import_vite_plugin_rsc_routes_auto_loader = require("./plugins/vite-plugin-rsc-routes-auto-loader.js");
|
|
36
|
-
var import_vite_plugin_rsc_routes_imports = require("./plugins/vite-plugin-rsc-routes-imports.js");
|
|
37
|
-
var import_vite_plugin_rsc_ssr_router_import = require("./plugins/vite-plugin-rsc-ssr-router-import.js");
|
|
38
|
-
var import_vite_plugin_rsc_transform_server = require("./plugins/vite-plugin-rsc-transform-server.js");
|
|
39
|
-
var import_rscWebSocketServer = require("./rsc/rscWebSocketServer.js");
|
|
40
35
|
var import_collectCss = require("./streaming/collectCss.js");
|
|
41
36
|
var import_createReactStreamingHandler = require("./streaming/createReactStreamingHandler.js");
|
|
42
37
|
var import_utils = require("./utils.js");
|
|
43
|
-
const import_meta = {};
|
|
44
38
|
globalThis.__REDWOOD__PRERENDER_PAGES = {};
|
|
45
|
-
globalThis.__rwjs__vite_ssr_runtime = void 0;
|
|
46
|
-
globalThis.__rwjs__vite_rsc_runtime = void 0;
|
|
47
39
|
async function createServer() {
|
|
48
40
|
(0, import_utils.ensureProcessDirWeb)();
|
|
49
41
|
(0, import_registerFwGlobalsAndShims.registerFwGlobalsAndShims)();
|
|
50
42
|
const app = (0, import_express.default)();
|
|
51
|
-
const server = import_node_http.default.createServer(app);
|
|
52
43
|
const rwPaths = (0, import_project_config.getPaths)();
|
|
53
44
|
const rscEnabled = (0, import_project_config.getConfig)().experimental.rsc?.enabled ?? false;
|
|
54
45
|
const serverStorage = (0, import_server_store.createServerStorage)();
|
|
@@ -71,76 +62,8 @@ async function createServer() {
|
|
|
71
62
|
"Vite config not found. You need to setup your project with Vite using `yarn rw setup vite`"
|
|
72
63
|
);
|
|
73
64
|
}
|
|
74
|
-
const
|
|
65
|
+
const vite = await (0, import_vite.createServer)({
|
|
75
66
|
configFile: rwPaths.web.viteConfig,
|
|
76
|
-
envFile: false,
|
|
77
|
-
define: {
|
|
78
|
-
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
|
|
79
|
-
},
|
|
80
|
-
ssr: {
|
|
81
|
-
// Inline every file apart from node built-ins. We want vite/rollup to
|
|
82
|
-
// inline dependencies in the server build. This gets round runtime
|
|
83
|
-
// importing of "server-only" and other packages with poisoned imports.
|
|
84
|
-
//
|
|
85
|
-
// Files included in `noExternal` are files we want Vite to analyze
|
|
86
|
-
// As of vite 5.2 `true` here means "all except node built-ins"
|
|
87
|
-
// noExternal: true,
|
|
88
|
-
// TODO (RSC): Other frameworks build for RSC without `noExternal: true`.
|
|
89
|
-
// What are we missing here? When/why is that a better choice? I know
|
|
90
|
-
// we would have to explicitly add a bunch of packages to noExternal, if
|
|
91
|
-
// we wanted to go that route.
|
|
92
|
-
// noExternal: ['@tobbe.dev/rsc-test'],
|
|
93
|
-
// Can't inline prisma client (db calls fail at runtime) or react-dom
|
|
94
|
-
// (css pre-init failure)
|
|
95
|
-
// Server store has to be externalized, because it's a singleton (shared between FW and App)
|
|
96
|
-
external: [
|
|
97
|
-
"@prisma/client",
|
|
98
|
-
"@prisma/fetch-engine",
|
|
99
|
-
"@prisma/internals",
|
|
100
|
-
"@cedarjs/auth-dbauth-api",
|
|
101
|
-
"@cedarjs/cookie-jar",
|
|
102
|
-
"@cedarjs/server-store",
|
|
103
|
-
"@simplewebauthn/server",
|
|
104
|
-
"graphql-scalars",
|
|
105
|
-
"minimatch",
|
|
106
|
-
"playwright",
|
|
107
|
-
"react-dom"
|
|
108
|
-
],
|
|
109
|
-
resolve: {
|
|
110
|
-
// These conditions are used in the plugin pipeline, and only affect non-externalized
|
|
111
|
-
// dependencies during the SSR build. Which because of `noExternal: true` means all
|
|
112
|
-
// dependencies apart from node built-ins.
|
|
113
|
-
// TODO (RSC): What's the difference between `conditions` and
|
|
114
|
-
// `externalConditions`? When is one used over the other?
|
|
115
|
-
// conditions: ['react-server'],
|
|
116
|
-
// externalConditions: ['react-server'],
|
|
117
|
-
},
|
|
118
|
-
optimizeDeps: {
|
|
119
|
-
// We need Vite to optimize these dependencies so that they are resolved
|
|
120
|
-
// with the correct conditions. And so that CJS modules work correctly.
|
|
121
|
-
// include: [
|
|
122
|
-
// 'react/**/*',
|
|
123
|
-
// 'react-dom/server',
|
|
124
|
-
// 'react-dom/server.edge',
|
|
125
|
-
// 'rehackt',
|
|
126
|
-
// 'react-server-dom-webpack/server',
|
|
127
|
-
// 'react-server-dom-webpack/client',
|
|
128
|
-
// '@apollo/client/cache/*',
|
|
129
|
-
// '@apollo/client/utilities/*',
|
|
130
|
-
// '@apollo/client/react/hooks/*',
|
|
131
|
-
// 'react-fast-compare',
|
|
132
|
-
// 'invariant',
|
|
133
|
-
// 'shallowequal',
|
|
134
|
-
// 'graphql/language/*',
|
|
135
|
-
// 'stacktracey',
|
|
136
|
-
// 'deepmerge',
|
|
137
|
-
// 'fast-glob',
|
|
138
|
-
// ],
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
resolve: {
|
|
142
|
-
// conditions: ['react-server'],
|
|
143
|
-
},
|
|
144
67
|
plugins: [
|
|
145
68
|
(0, import_vite_plugin_cjs_interop.cjsInterop)({
|
|
146
69
|
dependencies: [
|
|
@@ -154,182 +77,16 @@ async function createServer() {
|
|
|
154
77
|
"@cedarjs/auth-!(dbauth)-web"
|
|
155
78
|
]
|
|
156
79
|
}),
|
|
157
|
-
rscEnabled && (0, import_vite_plugin_rsc_routes_auto_loader.rscRoutesAutoLoader)()
|
|
158
|
-
rscEnabled && (0, import_vite_plugin_rsc_ssr_router_import.rscSsrRouterImport)()
|
|
80
|
+
rscEnabled && (0, import_vite_plugin_rsc_routes_auto_loader.rscRoutesAutoLoader)()
|
|
159
81
|
],
|
|
160
82
|
server: { middlewareMode: true },
|
|
161
83
|
logLevel: "info",
|
|
162
84
|
clearScreen: false,
|
|
163
85
|
appType: "custom"
|
|
164
86
|
});
|
|
165
|
-
globalThis.__rwjs__vite_ssr_runtime = await (0, import_vite.createViteRuntime)(viteSsrDevServer);
|
|
166
|
-
globalThis.__rwjs__client_references = /* @__PURE__ */ new Set();
|
|
167
|
-
globalThis.__rwjs__server_references = /* @__PURE__ */ new Set();
|
|
168
|
-
const viteRscServer = await (0, import_vite.createServer)({
|
|
169
|
-
envFile: false,
|
|
170
|
-
define: {
|
|
171
|
-
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
|
|
172
|
-
},
|
|
173
|
-
ssr: {
|
|
174
|
-
// Inline every file apart from node built-ins. We want vite/rollup to
|
|
175
|
-
// inline dependencies in the server build. This gets round runtime
|
|
176
|
-
// importing of "server-only" and other packages with poisoned imports.
|
|
177
|
-
//
|
|
178
|
-
// Files included in `noExternal` are files we want Vite to analyze
|
|
179
|
-
// As of vite 5.2 `true` here means "all except node built-ins"
|
|
180
|
-
noExternal: true,
|
|
181
|
-
// TODO (RSC): Other frameworks build for RSC without `noExternal: true`.
|
|
182
|
-
// What are we missing here? When/why is that a better choice? I know
|
|
183
|
-
// we would have to explicitly add a bunch of packages to noExternal, if
|
|
184
|
-
// we wanted to go that route.
|
|
185
|
-
// noExternal: ['@tobbe.dev/rsc-test'],
|
|
186
|
-
// Can't inline prisma client (db calls fail at runtime) or react-dom
|
|
187
|
-
// (css pre-init failure)
|
|
188
|
-
// Server store has to be externalized, because it's a singleton (shared between FW and App)
|
|
189
|
-
external: [
|
|
190
|
-
"@prisma/client",
|
|
191
|
-
"@prisma/fetch-engine",
|
|
192
|
-
"@prisma/internals",
|
|
193
|
-
"@cedarjs/auth-dbauth-api",
|
|
194
|
-
"@cedarjs/cookie-jar",
|
|
195
|
-
"@cedarjs/server-store",
|
|
196
|
-
"@cedarjs/structure",
|
|
197
|
-
"@simplewebauthn/server",
|
|
198
|
-
"graphql-scalars",
|
|
199
|
-
"minimatch",
|
|
200
|
-
"playwright",
|
|
201
|
-
"react-dom"
|
|
202
|
-
],
|
|
203
|
-
resolve: {
|
|
204
|
-
// These conditions are used in the plugin pipeline, and only affect non-externalized
|
|
205
|
-
// dependencies during the SSR build. Which because of `noExternal: true` means all
|
|
206
|
-
// dependencies apart from node built-ins.
|
|
207
|
-
// TODO (RSC): What's the difference between `conditions` and
|
|
208
|
-
// `externalConditions`? When is one used over the other?
|
|
209
|
-
conditions: ["react-server"],
|
|
210
|
-
externalConditions: ["react-server"]
|
|
211
|
-
},
|
|
212
|
-
optimizeDeps: {
|
|
213
|
-
// We need Vite to optimize these dependencies so that they are resolved
|
|
214
|
-
// with the correct conditions. And so that CJS modules work correctly.
|
|
215
|
-
include: [
|
|
216
|
-
"react/**/*",
|
|
217
|
-
"react-dom/server",
|
|
218
|
-
"react-dom/server.edge",
|
|
219
|
-
"rehackt",
|
|
220
|
-
"react-server-dom-webpack/server",
|
|
221
|
-
"react-server-dom-webpack/server.edge",
|
|
222
|
-
"react-server-dom-webpack/client",
|
|
223
|
-
"react-server-dom-webpack/client.edge",
|
|
224
|
-
"@apollo/client/cache/*",
|
|
225
|
-
"@apollo/client/utilities/*",
|
|
226
|
-
"@apollo/client/react/hooks/*",
|
|
227
|
-
"react-fast-compare",
|
|
228
|
-
"invariant",
|
|
229
|
-
"shallowequal",
|
|
230
|
-
"graphql/language/*",
|
|
231
|
-
"stacktracey",
|
|
232
|
-
"deepmerge",
|
|
233
|
-
"fast-glob",
|
|
234
|
-
"@whatwg-node/fetch",
|
|
235
|
-
"busboy",
|
|
236
|
-
"cookie"
|
|
237
|
-
],
|
|
238
|
-
// Without excluding `util` we get "TypeError: util.TextEncoder is not
|
|
239
|
-
// a constructor" in react-server-dom-webpack.server because it'll try
|
|
240
|
-
// to use Browserify's `util` instead of Node's. And Browserify's
|
|
241
|
-
// polyfill is missing TextEncoder+TextDecoder. The reason it's using
|
|
242
|
-
// the Browserify polyfill is because we have
|
|
243
|
-
// `vite-plugin-node-polyfills` as a dependency, and that'll add
|
|
244
|
-
// Browserify's `node-util` to `node_modules`, so when Vite goes to
|
|
245
|
-
// resolve `import { TextEncoder } from 'util` it'll find the one in
|
|
246
|
-
// `node_modules` instead of Node's internal version.
|
|
247
|
-
// We only see this in dev, and not in prod. I'm not entirely sure why
|
|
248
|
-
// but I have two guesses: 1. When RSC is enabled we don't actually use
|
|
249
|
-
// `vite-plugin-node-polyfill`, so some kind of tree shaking is
|
|
250
|
-
// happening, which prevents the issue from occurring. 2. In prod we
|
|
251
|
-
// only use Node's dependency resolution. Vite is not involved. And
|
|
252
|
-
// that difference in resolution is what prevents the issue from
|
|
253
|
-
// occurring.
|
|
254
|
-
exclude: ["util"]
|
|
255
|
-
}
|
|
256
|
-
},
|
|
257
|
-
resolve: {
|
|
258
|
-
conditions: ["react-server"]
|
|
259
|
-
},
|
|
260
|
-
plugins: [
|
|
261
|
-
{
|
|
262
|
-
name: "rsc-record-and-tranform-use-client-plugin",
|
|
263
|
-
transform(code, id, _options) {
|
|
264
|
-
globalThis.__rwjs__client_references?.delete(id);
|
|
265
|
-
if (!/^(["'])use client\1/.test(code)) {
|
|
266
|
-
return void 0;
|
|
267
|
-
}
|
|
268
|
-
console.log(
|
|
269
|
-
"rsc-record-and-transform-use-client-plugin: adding client reference",
|
|
270
|
-
id
|
|
271
|
-
);
|
|
272
|
-
globalThis.__rwjs__client_references?.add(id);
|
|
273
|
-
const fns = code.matchAll(/export function (\w+)\(/g);
|
|
274
|
-
const consts = code.matchAll(/export const (\w+) = \(/g);
|
|
275
|
-
const names = [...fns, ...consts].map(([, name]) => name);
|
|
276
|
-
const result = [
|
|
277
|
-
`import { registerClientReference } from "react-server-dom-webpack/server.edge";`,
|
|
278
|
-
"",
|
|
279
|
-
...names.map((name) => {
|
|
280
|
-
return name === "default" ? `export default registerClientReference({}, "${id}", "${name}");` : `export const ${name} = registerClientReference({}, "${id}", "${name}");`;
|
|
281
|
-
})
|
|
282
|
-
].join("\n");
|
|
283
|
-
console.log("rsc-record-and-transform-use-client-plugin result");
|
|
284
|
-
console.log(
|
|
285
|
-
result.split("\n").map((line, i) => ` ${i + 1}: ${line}`).join("\n")
|
|
286
|
-
);
|
|
287
|
-
return { code: result, map: null };
|
|
288
|
-
}
|
|
289
|
-
},
|
|
290
|
-
(0, import_vite_plugin_rsc_transform_server.rscTransformUseServerPlugin)("", {}),
|
|
291
|
-
// The rscTransformUseClientPlugin maps paths like
|
|
292
|
-
// /Users/tobbe/.../rw-app/node_modules/@tobbe.dev/rsc-test/dist/rsc-test.es.js
|
|
293
|
-
// to
|
|
294
|
-
// /Users/tobbe/.../rw-app/web/dist/ssr/assets/rsc0.js
|
|
295
|
-
// That's why it needs the `clientEntryFiles` data
|
|
296
|
-
// (It does other things as well, but that's why it needs clientEntryFiles)
|
|
297
|
-
// rscTransformUseClientPlugin(clientEntryFiles),
|
|
298
|
-
// rscTransformUseServerPlugin(outDir, serverEntryFiles),
|
|
299
|
-
(0, import_vite_plugin_rsc_routes_imports.rscRoutesImports)(),
|
|
300
|
-
{
|
|
301
|
-
name: "rsc-hot-update",
|
|
302
|
-
handleHotUpdate(ctx) {
|
|
303
|
-
console.log("rsc-hot-update ctx.modules", ctx.modules);
|
|
304
|
-
return [];
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
],
|
|
308
|
-
build: {
|
|
309
|
-
ssr: true
|
|
310
|
-
},
|
|
311
|
-
server: {
|
|
312
|
-
// We never call `viteRscServer.listen()`, so we should run this in
|
|
313
|
-
// middleware mode
|
|
314
|
-
middlewareMode: true,
|
|
315
|
-
// The hmr/fast-refresh websocket in this server collides with the one in
|
|
316
|
-
// the other Vite server. So we can either disable it or run it on a
|
|
317
|
-
// different port.
|
|
318
|
-
// TODO (RSC): Figure out if we should disable or just pick a different
|
|
319
|
-
// port
|
|
320
|
-
ws: false
|
|
321
|
-
// hmr: {
|
|
322
|
-
// port: 24679,
|
|
323
|
-
// },
|
|
324
|
-
},
|
|
325
|
-
appType: "custom",
|
|
326
|
-
// Using a unique cache dir here to not clash with our other vite server
|
|
327
|
-
cacheDir: "../node_modules/.vite-rsc"
|
|
328
|
-
});
|
|
329
|
-
globalThis.__rwjs__vite_rsc_runtime = await (0, import_vite.createViteRuntime)(viteRscServer);
|
|
330
87
|
const handleWithMiddleware = (route) => {
|
|
331
88
|
return (0, import_server.createServerAdapter)(async (req) => {
|
|
332
|
-
const middlewareRouter = await (0, import_register.createMiddlewareRouter)(
|
|
89
|
+
const middlewareRouter = await (0, import_register.createMiddlewareRouter)(vite);
|
|
333
90
|
const middleware = middlewareRouter.find(
|
|
334
91
|
req.method,
|
|
335
92
|
req.url
|
|
@@ -339,22 +96,19 @@ async function createServer() {
|
|
|
339
96
|
}
|
|
340
97
|
const [mwRes] = await (0, import_invokeMiddleware.invoke)(req, middleware, {
|
|
341
98
|
route,
|
|
342
|
-
|
|
99
|
+
viteDevServer: vite
|
|
343
100
|
});
|
|
344
101
|
return mwRes.toResponse();
|
|
345
102
|
});
|
|
346
103
|
};
|
|
347
|
-
app.use(
|
|
104
|
+
app.use(vite.middlewares);
|
|
348
105
|
if (rscEnabled) {
|
|
349
|
-
(
|
|
350
|
-
const { createRscRequestHandler } = await globalThis.__rwjs__vite_rsc_runtime.executeUrl(
|
|
351
|
-
new URL("./rsc/rscRequestHandler.js", import_meta.url).pathname
|
|
352
|
-
);
|
|
106
|
+
const { createRscRequestHandler } = await import("./rsc/rscRequestHandler.js");
|
|
353
107
|
app.use(
|
|
354
108
|
"/rw-rsc",
|
|
355
|
-
|
|
356
|
-
getMiddlewareRouter: async () => (0, import_register.createMiddlewareRouter)(
|
|
357
|
-
|
|
109
|
+
createRscRequestHandler({
|
|
110
|
+
getMiddlewareRouter: async () => (0, import_register.createMiddlewareRouter)(vite),
|
|
111
|
+
viteDevServer: vite
|
|
358
112
|
})
|
|
359
113
|
);
|
|
360
114
|
}
|
|
@@ -364,22 +118,18 @@ async function createServer() {
|
|
|
364
118
|
routes,
|
|
365
119
|
clientEntryPath: rwPaths.web.entryClient,
|
|
366
120
|
getStylesheetLinks: (route) => {
|
|
367
|
-
return getCssLinks({
|
|
368
|
-
rwPaths,
|
|
369
|
-
route,
|
|
370
|
-
viteSsrDevServer
|
|
371
|
-
});
|
|
121
|
+
return getCssLinks({ rwPaths, route, vite });
|
|
372
122
|
},
|
|
373
123
|
// Recreate middleware router on each request in dev
|
|
374
|
-
getMiddlewareRouter: async () => (0, import_register.createMiddlewareRouter)(
|
|
124
|
+
getMiddlewareRouter: async () => (0, import_register.createMiddlewareRouter)(vite)
|
|
375
125
|
},
|
|
376
|
-
|
|
126
|
+
vite
|
|
377
127
|
);
|
|
378
128
|
app.get("*", (0, import_server.createServerAdapter)(routeHandler));
|
|
379
129
|
app.post("*", handleWithMiddleware());
|
|
380
130
|
const port = (0, import_project_config.getConfig)().web.port;
|
|
381
131
|
console.log(`Started server on http://localhost:${port}`);
|
|
382
|
-
return
|
|
132
|
+
return app.listen(port);
|
|
383
133
|
}
|
|
384
134
|
let devApp = createServer();
|
|
385
135
|
process.stdin.on("data", async (data) => {
|
|
@@ -394,11 +144,11 @@ process.stdin.on("data", async (data) => {
|
|
|
394
144
|
function getCssLinks({
|
|
395
145
|
rwPaths,
|
|
396
146
|
route,
|
|
397
|
-
|
|
147
|
+
vite
|
|
398
148
|
}) {
|
|
399
149
|
const appAndRouteModules = (0, import_collectCss.componentsModules)(
|
|
400
150
|
[rwPaths.web.app, route?.filePath].filter(Boolean),
|
|
401
|
-
|
|
151
|
+
vite
|
|
402
152
|
);
|
|
403
153
|
const collectedCss = (0, import_collectCss.collectCssPaths)(appAndRouteModules);
|
|
404
154
|
const cssLinks = Array.from(collectedCss);
|
|
@@ -77,15 +77,6 @@ function registerFwShims() {
|
|
|
77
77
|
globalThis.__rw_module_cache__ ||= /* @__PURE__ */ new Map();
|
|
78
78
|
globalThis.__webpack_chunk_load__ ||= async (id) => {
|
|
79
79
|
console.log("registerFwShims chunk load id", id);
|
|
80
|
-
if (globalThis.__rwjs__vite_ssr_runtime) {
|
|
81
|
-
return globalThis.__rwjs__vite_ssr_runtime?.executeUrl(id).then((mod) => {
|
|
82
|
-
console.log("registerFwShims chunk load mod", mod);
|
|
83
|
-
if (mod.default && typeof mod.default === "object") {
|
|
84
|
-
return globalThis.__rw_module_cache__.set(id, mod.default);
|
|
85
|
-
}
|
|
86
|
-
return globalThis.__rw_module_cache__.set(id, mod);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
80
|
return import(id).then((mod) => {
|
|
90
81
|
console.log("registerFwShims chunk load mod", mod);
|
|
91
82
|
if (mod.default && typeof mod.default === "object") {
|
|
@@ -44,8 +44,8 @@ function rscSsrRouterImport() {
|
|
|
44
44
|
const routesFileId = (0, import_vite.normalizePath)((0, import_project_config.getPaths)().web.routes);
|
|
45
45
|
return {
|
|
46
46
|
name: "rsc-ssr-router-import",
|
|
47
|
-
transform: async function(code, id
|
|
48
|
-
if (
|
|
47
|
+
transform: async function(code, id) {
|
|
48
|
+
if (id !== routesFileId) {
|
|
49
49
|
return null;
|
|
50
50
|
}
|
|
51
51
|
const ext = import_node_path.default.extname(id);
|
|
@@ -41,10 +41,6 @@ function rscTransformUseServerPlugin(outDir, serverEntryFiles) {
|
|
|
41
41
|
if (!code.includes("use server")) {
|
|
42
42
|
return code;
|
|
43
43
|
}
|
|
44
|
-
if (id.includes("node_modules/.vite") || id.includes("/react-server-dom-webpack/") || id.includes("/react-server-dom-webpack.server")) {
|
|
45
|
-
console.log("vite-plugin-rsc-transform-server.ts: Skipping", id);
|
|
46
|
-
return code;
|
|
47
|
-
}
|
|
48
44
|
let mod;
|
|
49
45
|
const isTypescript = id.endsWith(".ts") || id.endsWith(".tsx");
|
|
50
46
|
try {
|
|
@@ -33,28 +33,20 @@ __export(rscRenderer_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(rscRenderer_exports);
|
|
35
35
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
36
|
+
var import_react = require("react");
|
|
37
|
+
var import_server = require("react-server-dom-webpack/server.edge");
|
|
36
38
|
var import_project_config = require("@cedarjs/project-config");
|
|
37
39
|
var import_entries = require("../lib/entries.js");
|
|
38
40
|
var import_StatusError = require("../lib/StatusError.js");
|
|
39
|
-
var import_utils = require("./utils.js");
|
|
40
41
|
let absoluteClientEntries = {};
|
|
41
|
-
|
|
42
|
+
function renderRscToStream(input) {
|
|
42
43
|
return input.rscId ? renderRsc(input) : executeRsa(input);
|
|
43
44
|
}
|
|
44
45
|
async function loadServerFile(filePath) {
|
|
45
46
|
console.log("rscRenderer.ts loadServerFile filePath", filePath);
|
|
46
|
-
if (globalThis.__rwjs__vite_rsc_runtime) {
|
|
47
|
-
const serverMod = await globalThis.__rwjs__vite_rsc_runtime.executeUrl(filePath);
|
|
48
|
-
return serverMod.default ? serverMod.default : serverMod;
|
|
49
|
-
}
|
|
50
47
|
return import(`file://${filePath}`);
|
|
51
48
|
}
|
|
52
49
|
const getRoutesComponent = async () => {
|
|
53
|
-
if (globalThis.__rwjs__vite_rsc_runtime) {
|
|
54
|
-
const routesPath2 = (0, import_project_config.getPaths)().web.routes;
|
|
55
|
-
const routesMod = await globalThis.__rwjs__vite_rsc_runtime.executeUrl(routesPath2);
|
|
56
|
-
return routesMod.default;
|
|
57
|
-
}
|
|
58
50
|
const serverEntries = await (0, import_entries.getEntriesFromDist)();
|
|
59
51
|
console.log("rscRenderer.ts serverEntries", serverEntries);
|
|
60
52
|
const routesPath = import_node_path.default.join(
|
|
@@ -95,12 +87,10 @@ function getBundlerConfig() {
|
|
|
95
87
|
{},
|
|
96
88
|
{
|
|
97
89
|
get(_target, encodedId) {
|
|
98
|
-
console.log("
|
|
90
|
+
console.log("Proxy get encodedId", encodedId);
|
|
99
91
|
const [filePath, name] = encodedId.split("#");
|
|
100
|
-
console.log("filePath", filePath);
|
|
101
|
-
console.log("name", name);
|
|
102
92
|
const filePathSlash = filePath.replaceAll("\\", "/");
|
|
103
|
-
const id =
|
|
93
|
+
const id = absoluteClientEntries[filePathSlash];
|
|
104
94
|
console.log("absoluteClientEntries", absoluteClientEntries);
|
|
105
95
|
console.log("filePath", filePathSlash);
|
|
106
96
|
if (!id) {
|
|
@@ -123,14 +113,12 @@ async function renderRsc(input) {
|
|
|
123
113
|
throw new Error("Unexpected input. Missing rscId or props.");
|
|
124
114
|
}
|
|
125
115
|
console.log("renderRsc input", input);
|
|
126
|
-
const { createElement } = await (0, import_utils.importRscReact)();
|
|
127
|
-
const { renderToReadableStream } = await (0, import_utils.importRsdwServer)();
|
|
128
116
|
const serverRoutes = await getRoutesComponent();
|
|
129
117
|
const model = {
|
|
130
|
-
__rwjs__Routes: createElement(serverRoutes)
|
|
118
|
+
__rwjs__Routes: (0, import_react.createElement)(serverRoutes)
|
|
131
119
|
};
|
|
132
120
|
console.log("rscRenderer.ts renderRsc model", model);
|
|
133
|
-
return renderToReadableStream(model, getBundlerConfig());
|
|
121
|
+
return (0, import_server.renderToReadableStream)(model, getBundlerConfig());
|
|
134
122
|
}
|
|
135
123
|
function isSerializedFormData(data) {
|
|
136
124
|
return !!data && data?.__formData__;
|
|
@@ -161,16 +149,14 @@ async function executeRsa(input) {
|
|
|
161
149
|
console.log("rscRenderer.ts args", ...input.args);
|
|
162
150
|
const data = await method(...input.args);
|
|
163
151
|
console.log("rscRenderer.ts rsa return data", data);
|
|
164
|
-
const { createElement } = await (0, import_utils.importRscReact)();
|
|
165
|
-
const { renderToReadableStream } = await (0, import_utils.importRsdwServer)();
|
|
166
152
|
const serverRoutes = await getRoutesComponent();
|
|
167
153
|
console.log("rscRenderer.ts executeRsa serverRoutes", serverRoutes);
|
|
168
154
|
const model = {
|
|
169
|
-
__rwjs__Routes: createElement(serverRoutes),
|
|
155
|
+
__rwjs__Routes: (0, import_react.createElement)(serverRoutes),
|
|
170
156
|
__rwjs__rsa_data: data
|
|
171
157
|
};
|
|
172
158
|
console.log("rscRenderer.ts executeRsa model", model);
|
|
173
|
-
return renderToReadableStream(model, getBundlerConfig());
|
|
159
|
+
return (0, import_server.renderToReadableStream)(model, getBundlerConfig());
|
|
174
160
|
}
|
|
175
161
|
// Annotate the CommonJS export names for ESM import in node:
|
|
176
162
|
0 && (module.exports = {
|
|
@@ -38,10 +38,10 @@ var import_busboy = __toESM(require("busboy"), 1);
|
|
|
38
38
|
var import_react_server_dom_webpack_server = require("../bundled/react-server-dom-webpack.server.js");
|
|
39
39
|
var import_StatusError = require("../lib/StatusError.js");
|
|
40
40
|
var import_invokeMiddleware = require("../middleware/invokeMiddleware.js");
|
|
41
|
+
var import_rscRenderer = require("./rscRenderer.js");
|
|
42
|
+
var import_rscStudioHandlers = require("./rscStudioHandlers.js");
|
|
41
43
|
const BASE_PATH = "/rw-rsc/";
|
|
42
|
-
|
|
43
|
-
const { renderRscToStream } = await import("./rscRenderer.js");
|
|
44
|
-
const { sendRscFlightToStudio } = await import("./rscStudioHandlers.js");
|
|
44
|
+
function createRscRequestHandler(options) {
|
|
45
45
|
return async (req, res, next) => {
|
|
46
46
|
console.log("BASE_PATH", BASE_PATH);
|
|
47
47
|
console.log("req.originalUrl", req.originalUrl, "req.url", req.url);
|
|
@@ -56,7 +56,7 @@ async function createRscRequestHandler(options) {
|
|
|
56
56
|
matchedMw?.handler,
|
|
57
57
|
{
|
|
58
58
|
params: matchedMw?.params,
|
|
59
|
-
|
|
59
|
+
viteDevServer: options.viteDevServer
|
|
60
60
|
}
|
|
61
61
|
);
|
|
62
62
|
const webRes = mwResponse.toResponse();
|
|
@@ -101,9 +101,9 @@ async function createRscRequestHandler(options) {
|
|
|
101
101
|
res.end(String(err));
|
|
102
102
|
};
|
|
103
103
|
try {
|
|
104
|
-
const readable = await renderRscToStream({ rscId, rsaId, args });
|
|
104
|
+
const readable = await (0, import_rscRenderer.renderRscToStream)({ rscId, rsaId, args });
|
|
105
105
|
import_node_stream.Readable.fromWeb(readable).pipe(res);
|
|
106
|
-
await sendRscFlightToStudio({
|
|
106
|
+
await (0, import_rscStudioHandlers.sendRscFlightToStudio)({
|
|
107
107
|
rscId,
|
|
108
108
|
rsaId,
|
|
109
109
|
args,
|
package/dist/cjs/runFeServer.js
CHANGED
|
@@ -37,13 +37,13 @@ var import_server = require("@whatwg-node/server");
|
|
|
37
37
|
var import_dotenv_defaults = require("dotenv-defaults");
|
|
38
38
|
var import_express = __toESM(require("express"), 1);
|
|
39
39
|
var import_http_proxy_middleware = require("http-proxy-middleware");
|
|
40
|
+
var import_ws = __toESM(require("ws"), 1);
|
|
40
41
|
var import_project_config = require("@cedarjs/project-config");
|
|
41
42
|
var import_rscCss = require("@cedarjs/router/rscCss");
|
|
42
43
|
var import_server_store = require("@cedarjs/server-store");
|
|
43
44
|
var import_registerFwGlobalsAndShims = require("./lib/registerFwGlobalsAndShims.js");
|
|
44
45
|
var import_invokeMiddleware = require("./middleware/invokeMiddleware.js");
|
|
45
46
|
var import_register = require("./middleware/register.js");
|
|
46
|
-
var import_rscWebSocketServer = require("./rsc/rscWebSocketServer.js");
|
|
47
47
|
var import_createReactStreamingHandler = require("./streaming/createReactStreamingHandler.js");
|
|
48
48
|
var import_utils = require("./utils.js");
|
|
49
49
|
(0, import_dotenv_defaults.config)({
|
|
@@ -61,7 +61,7 @@ async function runFeServer() {
|
|
|
61
61
|
(0, import_registerFwGlobalsAndShims.registerFwGlobalsAndShims)();
|
|
62
62
|
if (rscEnabled) {
|
|
63
63
|
const { setClientEntries } = await import("./rsc/rscRenderer.js");
|
|
64
|
-
|
|
64
|
+
createWebSocketServer();
|
|
65
65
|
try {
|
|
66
66
|
await setClientEntries();
|
|
67
67
|
} catch (e) {
|
|
@@ -120,7 +120,7 @@ async function runFeServer() {
|
|
|
120
120
|
const { createRscRequestHandler } = await import("./rsc/rscRequestHandler.js");
|
|
121
121
|
app.use(
|
|
122
122
|
"/rw-rsc",
|
|
123
|
-
|
|
123
|
+
createRscRequestHandler({
|
|
124
124
|
getMiddlewareRouter: async () => middlewareRouter
|
|
125
125
|
})
|
|
126
126
|
);
|
|
@@ -140,6 +140,25 @@ async function runFeServer() {
|
|
|
140
140
|
`Started production FE server on http://localhost:${rwConfig.web.port}`
|
|
141
141
|
);
|
|
142
142
|
}
|
|
143
|
+
function createWebSocketServer() {
|
|
144
|
+
const wsServer = new import_ws.WebSocketServer({ port: 18998 });
|
|
145
|
+
wsServer.on("connection", (ws) => {
|
|
146
|
+
console.log("A new client connected.");
|
|
147
|
+
ws.on("message", (data) => {
|
|
148
|
+
const message = data.toString();
|
|
149
|
+
console.log("runFeServer.ts: Received message:");
|
|
150
|
+
console.log(message.slice(0, 120) + "...");
|
|
151
|
+
wsServer.clients.forEach((client) => {
|
|
152
|
+
if (client.readyState === import_ws.default.OPEN) {
|
|
153
|
+
client.send(message);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
ws.on("close", () => {
|
|
158
|
+
console.log("A client disconnected.");
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
}
|
|
143
162
|
runFeServer();
|
|
144
163
|
// Annotate the CommonJS export names for ESM import in node:
|
|
145
164
|
0 && (module.exports = {
|
|
@@ -50,10 +50,10 @@ const createReactStreamingHandler = async ({
|
|
|
50
50
|
clientEntryPath,
|
|
51
51
|
getStylesheetLinks,
|
|
52
52
|
getMiddlewareRouter
|
|
53
|
-
},
|
|
53
|
+
}, viteDevServer) => {
|
|
54
54
|
const rwPaths = (0, import_project_config.getPaths)();
|
|
55
55
|
const rwConfig = (0, import_project_config.getConfig)();
|
|
56
|
-
const isProd = !
|
|
56
|
+
const isProd = !viteDevServer;
|
|
57
57
|
const middlewareRouter = await getMiddlewareRouter();
|
|
58
58
|
let entryServerImport;
|
|
59
59
|
let fallbackDocumentImport;
|
|
@@ -97,7 +97,7 @@ const createReactStreamingHandler = async ({
|
|
|
97
97
|
route: currentRoute,
|
|
98
98
|
cssPaths: cssLinks,
|
|
99
99
|
params: matchedMw?.params,
|
|
100
|
-
|
|
100
|
+
viteDevServer
|
|
101
101
|
}
|
|
102
102
|
);
|
|
103
103
|
if (mwResponse.isRedirect() || mwResponse.body) {
|
|
@@ -116,8 +116,8 @@ const createReactStreamingHandler = async ({
|
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
if (!isProd) {
|
|
119
|
-
entryServerImport = await (0, import_utils.ssrLoadEntryServer)(
|
|
120
|
-
fallbackDocumentImport = await
|
|
119
|
+
entryServerImport = await (0, import_utils.ssrLoadEntryServer)(viteDevServer);
|
|
120
|
+
fallbackDocumentImport = await viteDevServer.ssrLoadModule(
|
|
121
121
|
rwPaths.web.document
|
|
122
122
|
);
|
|
123
123
|
}
|
|
@@ -134,12 +134,10 @@ const createReactStreamingHandler = async ({
|
|
|
134
134
|
req,
|
|
135
135
|
parsedParams
|
|
136
136
|
},
|
|
137
|
-
|
|
137
|
+
viteDevServer
|
|
138
138
|
});
|
|
139
139
|
metaTags = routeHookOutput.meta;
|
|
140
|
-
const jsBundles = [
|
|
141
|
-
viteSsrDevServer ? clientEntryPath : "/" + clientEntryPath
|
|
142
|
-
];
|
|
140
|
+
const jsBundles = [viteDevServer ? clientEntryPath : "/" + clientEntryPath];
|
|
143
141
|
if (currentRoute.bundle) {
|
|
144
142
|
jsBundles.push("/" + currentRoute.bundle);
|
|
145
143
|
}
|
|
@@ -159,13 +157,12 @@ const createReactStreamingHandler = async ({
|
|
|
159
157
|
{
|
|
160
158
|
waitForAllReady: isSeoCrawler,
|
|
161
159
|
onError: (err) => {
|
|
162
|
-
if (!isProd &&
|
|
163
|
-
|
|
160
|
+
if (!isProd && viteDevServer) {
|
|
161
|
+
viteDevServer.ssrFixStacktrace(err);
|
|
164
162
|
}
|
|
165
163
|
console.error(err);
|
|
166
164
|
}
|
|
167
|
-
}
|
|
168
|
-
viteSsrDevServer
|
|
165
|
+
}
|
|
169
166
|
);
|
|
170
167
|
return reactResponse;
|
|
171
168
|
};
|