@cedarjs/vite 3.0.1-next.0 → 4.0.0-canary.13651

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.
Files changed (41) hide show
  1. package/dist/bundled/react-server-dom-webpack.server.js +1224 -28468
  2. package/dist/cjs/devFeServer.js +269 -15
  3. package/dist/cjs/lib/registerFwGlobalsAndShims.js +9 -0
  4. package/dist/cjs/plugins/vite-plugin-rsc-ssr-router-import.js +2 -2
  5. package/dist/cjs/plugins/vite-plugin-rsc-transform-server.js +4 -0
  6. package/dist/cjs/rsc/rscRenderer.js +23 -9
  7. package/dist/cjs/rsc/rscRequestHandler.js +6 -6
  8. package/dist/cjs/rsc/rscWebSocketServer.js +56 -0
  9. package/dist/cjs/rsc/utils.js +56 -0
  10. package/dist/cjs/runFeServer.js +3 -22
  11. package/dist/cjs/streaming/createReactStreamingHandler.js +13 -10
  12. package/dist/cjs/streaming/streamHelpers.js +49 -32
  13. package/dist/cjs/streaming/triggerRouteHooks.js +3 -3
  14. package/dist/devFeServer.js +269 -16
  15. package/dist/lib/registerFwGlobalsAndShims.js +9 -0
  16. package/dist/plugins/vite-plugin-rsc-ssr-router-import.d.ts.map +1 -1
  17. package/dist/plugins/vite-plugin-rsc-ssr-router-import.js +2 -2
  18. package/dist/plugins/vite-plugin-rsc-transform-server.d.ts.map +1 -1
  19. package/dist/plugins/vite-plugin-rsc-transform-server.js +4 -0
  20. package/dist/rsc/rscRenderer.d.ts.map +1 -1
  21. package/dist/rsc/rscRenderer.js +19 -5
  22. package/dist/rsc/rscRequestHandler.d.ts +2 -2
  23. package/dist/rsc/rscRequestHandler.d.ts.map +1 -1
  24. package/dist/rsc/rscRequestHandler.js +4 -4
  25. package/dist/rsc/rscWebSocketServer.d.ts +2 -0
  26. package/dist/rsc/rscWebSocketServer.d.ts.map +1 -0
  27. package/dist/rsc/rscWebSocketServer.js +22 -0
  28. package/dist/rsc/utils.d.ts +10 -0
  29. package/dist/rsc/utils.d.ts.map +1 -0
  30. package/dist/rsc/utils.js +21 -0
  31. package/dist/runFeServer.js +2 -21
  32. package/dist/streaming/createReactStreamingHandler.d.ts +1 -1
  33. package/dist/streaming/createReactStreamingHandler.d.ts.map +1 -1
  34. package/dist/streaming/createReactStreamingHandler.js +13 -10
  35. package/dist/streaming/streamHelpers.d.ts +2 -2
  36. package/dist/streaming/streamHelpers.d.ts.map +1 -1
  37. package/dist/streaming/streamHelpers.js +49 -31
  38. package/dist/streaming/triggerRouteHooks.d.ts +2 -2
  39. package/dist/streaming/triggerRouteHooks.d.ts.map +1 -1
  40. package/dist/streaming/triggerRouteHooks.js +3 -3
  41. package/package.json +11 -11
@@ -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 vite = await (0, import_vite.createServer)({
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,184 @@ 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 = await (0, import_vite.createViteRuntime)(viteSsrDevServer);
168
+ globalThis.__cedarjs__client_references = /* @__PURE__ */ new Set();
169
+ globalThis.__cedarjs__server_references = /* @__PURE__ */ new Set();
170
+ const viteRscServer = await (0, import_vite.createServer)({
171
+ envFile: false,
172
+ define: {
173
+ "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
174
+ },
175
+ ssr: {
176
+ // Inline every file apart from node built-ins. We want vite/rollup to
177
+ // inline dependencies in the server build. This gets round runtime
178
+ // importing of "server-only" and other packages with poisoned imports.
179
+ //
180
+ // Files included in `noExternal` are files we want Vite to analyze
181
+ // As of vite 5.2 `true` here means "all except node built-ins"
182
+ noExternal: true,
183
+ // TODO (RSC): Other frameworks build for RSC without `noExternal: true`.
184
+ // What are we missing here? When/why is that a better choice? I know
185
+ // we would have to explicitly add a bunch of packages to noExternal, if
186
+ // we wanted to go that route.
187
+ // noExternal: ['@tobbe.dev/rsc-test'],
188
+ // Can't inline prisma client (db calls fail at runtime) or react-dom
189
+ // (css pre-init failure)
190
+ // Server store has to be externalized, because it's a singleton (shared between FW and App)
191
+ external: [
192
+ "@prisma/client",
193
+ "@prisma/adapter-better-sqlite3",
194
+ "@prisma/fetch-engine",
195
+ "@prisma/internals",
196
+ "better-sqlite3",
197
+ "@cedarjs/auth-dbauth-api",
198
+ "@cedarjs/cookie-jar",
199
+ "@cedarjs/server-store",
200
+ "@cedarjs/structure",
201
+ "@simplewebauthn/server",
202
+ "graphql-scalars",
203
+ "minimatch",
204
+ "playwright",
205
+ "react-dom"
206
+ ],
207
+ resolve: {
208
+ // These conditions are used in the plugin pipeline, and only affect non-externalized
209
+ // dependencies during the SSR build. Which because of `noExternal: true` means all
210
+ // dependencies apart from node built-ins.
211
+ // TODO (RSC): What's the difference between `conditions` and
212
+ // `externalConditions`? When is one used over the other?
213
+ conditions: ["react-server"],
214
+ externalConditions: ["react-server"]
215
+ },
216
+ optimizeDeps: {
217
+ // We need Vite to optimize these dependencies so that they are resolved
218
+ // with the correct conditions. And so that CJS modules work correctly.
219
+ include: [
220
+ "react/**/*",
221
+ "react-dom/server",
222
+ "react-dom/server.edge",
223
+ "rehackt",
224
+ "react-server-dom-webpack/server",
225
+ "react-server-dom-webpack/server.edge",
226
+ "react-server-dom-webpack/client",
227
+ "react-server-dom-webpack/client.edge",
228
+ "@apollo/client/cache/*",
229
+ "@apollo/client/utilities/*",
230
+ "@apollo/client/react/hooks/*",
231
+ "react-fast-compare",
232
+ "invariant",
233
+ "shallowequal",
234
+ "graphql/language/*",
235
+ "stacktracey",
236
+ "deepmerge",
237
+ "fast-glob",
238
+ "@whatwg-node/fetch",
239
+ "busboy",
240
+ "cookie"
241
+ ],
242
+ // Without excluding `util` we get "TypeError: util.TextEncoder is not
243
+ // a constructor" in react-server-dom-webpack.server because it'll try
244
+ // to use Browserify's `util` instead of Node's. And Browserify's
245
+ // polyfill is missing TextEncoder+TextDecoder. The reason it's using
246
+ // the Browserify polyfill is because we have
247
+ // `vite-plugin-node-polyfills` as a dependency, and that'll add
248
+ // Browserify's `node-util` to `node_modules`, so when Vite goes to
249
+ // resolve `import { TextEncoder } from 'util` it'll find the one in
250
+ // `node_modules` instead of Node's internal version.
251
+ // We only see this in dev, and not in prod. I'm not entirely sure why
252
+ // but I have two guesses: 1. When RSC is enabled we don't actually use
253
+ // `vite-plugin-node-polyfill`, so some kind of tree shaking is
254
+ // happening, which prevents the issue from occurring. 2. In prod we
255
+ // only use Node's dependency resolution. Vite is not involved. And
256
+ // that difference in resolution is what prevents the issue from
257
+ // occurring.
258
+ exclude: ["util"]
259
+ }
260
+ },
261
+ resolve: {
262
+ conditions: ["react-server"]
263
+ },
264
+ plugins: [
265
+ {
266
+ name: "rsc-record-and-tranform-use-client-plugin",
267
+ transform(code, id, _options) {
268
+ globalThis.__cedarjs__client_references?.delete(id);
269
+ if (!/^(["'])use client\1/.test(code)) {
270
+ return void 0;
271
+ }
272
+ console.log(
273
+ "rsc-record-and-transform-use-client-plugin: adding client reference",
274
+ id
275
+ );
276
+ globalThis.__cedarjs__client_references?.add(id);
277
+ const fns = code.matchAll(/export function (\w+)\(/g);
278
+ const consts = code.matchAll(/export const (\w+) = \(/g);
279
+ const names = [...fns, ...consts].map(([, name]) => name);
280
+ const result = [
281
+ `import { registerClientReference } from "react-server-dom-webpack/server.edge";`,
282
+ "",
283
+ ...names.map((name) => {
284
+ return name === "default" ? `export default registerClientReference({}, "${id}", "${name}");` : `export const ${name} = registerClientReference({}, "${id}", "${name}");`;
285
+ })
286
+ ].join("\n");
287
+ console.log("rsc-record-and-transform-use-client-plugin result");
288
+ console.log(
289
+ result.split("\n").map((line, i) => ` ${i + 1}: ${line}`).join("\n")
290
+ );
291
+ return { code: result, map: null };
292
+ }
293
+ },
294
+ (0, import_vite_plugin_rsc_transform_server.rscTransformUseServerPlugin)("", {}),
295
+ // The rscTransformUseClientPlugin maps paths like
296
+ // /Users/tobbe/.../rw-app/node_modules/@tobbe.dev/rsc-test/dist/rsc-test.es.js
297
+ // to
298
+ // /Users/tobbe/.../rw-app/web/dist/ssr/assets/rsc0.js
299
+ // That's why it needs the `clientEntryFiles` data
300
+ // (It does other things as well, but that's why it needs clientEntryFiles)
301
+ // rscTransformUseClientPlugin(clientEntryFiles),
302
+ // rscTransformUseServerPlugin(outDir, serverEntryFiles),
303
+ (0, import_vite_plugin_rsc_routes_imports.rscRoutesImports)(),
304
+ {
305
+ name: "rsc-hot-update",
306
+ handleHotUpdate(ctx) {
307
+ console.log("rsc-hot-update ctx.modules", ctx.modules);
308
+ return [];
309
+ }
310
+ }
311
+ ],
312
+ build: {
313
+ ssr: true
314
+ },
315
+ server: {
316
+ // We never call `viteRscServer.listen()`, so we should run this in
317
+ // middleware mode
318
+ middlewareMode: true,
319
+ // The hmr/fast-refresh websocket in this server collides with the one in
320
+ // the other Vite server. So we can either disable it or run it on a
321
+ // different port.
322
+ // TODO (RSC): Figure out if we should disable or just pick a different
323
+ // port
324
+ ws: false
325
+ // hmr: {
326
+ // port: 24679,
327
+ // },
328
+ },
329
+ appType: "custom",
330
+ // Using a unique cache dir here to not clash with our other vite server
331
+ cacheDir: "../node_modules/.vite-rsc"
332
+ });
333
+ globalThis.__cedarjs__vite_rsc_runtime = await (0, import_vite.createViteRuntime)(viteRscServer);
87
334
  const handleWithMiddleware = (route) => {
88
335
  return (0, import_server.createServerAdapter)(async (req) => {
89
- const middlewareRouter = await (0, import_register.createMiddlewareRouter)(vite);
336
+ const middlewareRouter = await (0, import_register.createMiddlewareRouter)(viteSsrDevServer);
90
337
  const middleware = middlewareRouter.find(
91
338
  req.method,
92
339
  req.url
@@ -96,19 +343,22 @@ async function createServer() {
96
343
  }
97
344
  const [mwRes] = await (0, import_invokeMiddleware.invoke)(req, middleware, {
98
345
  route,
99
- viteDevServer: vite
346
+ viteSsrDevServer
100
347
  });
101
348
  return mwRes.toResponse();
102
349
  });
103
350
  };
104
- app.use(vite.middlewares);
351
+ app.use(viteSsrDevServer.middlewares);
105
352
  if (rscEnabled) {
106
- const { createRscRequestHandler } = await import("./rsc/rscRequestHandler.js");
353
+ (0, import_rscWebSocketServer.createWebSocketServer)();
354
+ const { createRscRequestHandler } = await globalThis.__cedarjs__vite_rsc_runtime.executeUrl(
355
+ new URL("./rsc/rscRequestHandler.js", import_meta.url).pathname
356
+ );
107
357
  app.use(
108
358
  "/rw-rsc",
109
- createRscRequestHandler({
110
- getMiddlewareRouter: async () => (0, import_register.createMiddlewareRouter)(vite),
111
- viteDevServer: vite
359
+ await createRscRequestHandler({
360
+ getMiddlewareRouter: async () => (0, import_register.createMiddlewareRouter)(viteSsrDevServer),
361
+ viteSsrDevServer
112
362
  })
113
363
  );
114
364
  }
@@ -118,18 +368,22 @@ async function createServer() {
118
368
  routes,
119
369
  clientEntryPath: rwPaths.web.entryClient,
120
370
  getStylesheetLinks: (route) => {
121
- return getCssLinks({ rwPaths, route, vite });
371
+ return getCssLinks({
372
+ rwPaths,
373
+ route,
374
+ viteSsrDevServer
375
+ });
122
376
  },
123
377
  // Recreate middleware router on each request in dev
124
- getMiddlewareRouter: async () => (0, import_register.createMiddlewareRouter)(vite)
378
+ getMiddlewareRouter: async () => (0, import_register.createMiddlewareRouter)(viteSsrDevServer)
125
379
  },
126
- vite
380
+ viteSsrDevServer
127
381
  );
128
382
  app.get("*", (0, import_server.createServerAdapter)(routeHandler));
129
383
  app.post("*", handleWithMiddleware());
130
384
  const port = (0, import_project_config.getConfig)().web.port;
131
385
  console.log(`Started server on http://localhost:${port}`);
132
- return app.listen(port);
386
+ return server.listen(port);
133
387
  }
134
388
  let devApp = createServer();
135
389
  process.stdin.on("data", async (data) => {
@@ -144,11 +398,11 @@ process.stdin.on("data", async (data) => {
144
398
  function getCssLinks({
145
399
  rwPaths,
146
400
  route,
147
- vite
401
+ viteSsrDevServer
148
402
  }) {
149
403
  const appAndRouteModules = (0, import_collectCss.componentsModules)(
150
404
  [rwPaths.web.app, route?.filePath].filter(Boolean),
151
- vite
405
+ viteSsrDevServer
152
406
  );
153
407
  const collectedCss = (0, import_collectCss.collectCssPaths)(appAndRouteModules);
154
408
  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?.executeUrl(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.executeUrl(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.executeUrl(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: (0, import_react.createElement)(serverRoutes)
130
+ __cedarjs__Routes: createElement(serverRoutes)
119
131
  };
120
132
  console.log("rscRenderer.ts renderRsc model", model);
121
- return (0, import_server.renderToReadableStream)(model, getBundlerConfig());
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: (0, import_react.createElement)(serverRoutes),
169
+ __cedarjs__Routes: createElement(serverRoutes),
156
170
  __cedarjs__rsa_data: data
157
171
  };
158
172
  console.log("rscRenderer.ts executeRsa model", model);
159
- return (0, import_server.renderToReadableStream)(model, getBundlerConfig());
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
- viteDevServer: options.viteDevServer
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 (0, import_rscRenderer.renderRscToStream)({ rscId, rsaId, args });
104
+ const readable = await renderRscToStream({ rscId, rsaId, args });
105
105
  import_node_stream.Readable.fromWeb(readable).pipe(res);
106
- await (0, import_rscStudioHandlers.sendRscFlightToStudio)({
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.executeUrl("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.executeUrl(
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
+ });