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