@cedarjs/vite 0.0.5 → 1.0.0-canary.12246

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 +1849 -28815
  2. package/dist/cjs/devFeServer.js +265 -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 -30
  13. package/dist/cjs/streaming/triggerRouteHooks.js +3 -3
  14. package/dist/devFeServer.js +265 -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 -29
  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 +13 -16
@@ -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.__rwjs__vite_ssr_runtime = void 0;
46
+ globalThis.__rwjs__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,76 @@ async function createServer() {
62
71
  "Vite config not found. You need to setup your project with Vite using `yarn rw 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/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
+ },
67
144
  plugins: [
68
145
  (0, import_vite_plugin_cjs_interop.cjsInterop)({
69
146
  dependencies: [
@@ -74,16 +151,182 @@ async function createServer() {
74
151
  "@cedarjs/auth-*-web"
75
152
  ]
76
153
  }),
77
- rscEnabled && (0, import_vite_plugin_rsc_routes_auto_loader.rscRoutesAutoLoader)()
154
+ rscEnabled && (0, import_vite_plugin_rsc_routes_auto_loader.rscRoutesAutoLoader)(),
155
+ rscEnabled && (0, import_vite_plugin_rsc_ssr_router_import.rscSsrRouterImport)()
78
156
  ],
79
157
  server: { middlewareMode: true },
80
158
  logLevel: "info",
81
159
  clearScreen: false,
82
160
  appType: "custom"
83
161
  });
162
+ globalThis.__rwjs__vite_ssr_runtime = await (0, import_vite.createViteRuntime)(viteSsrDevServer);
163
+ globalThis.__rwjs__client_references = /* @__PURE__ */ new Set();
164
+ globalThis.__rwjs__server_references = /* @__PURE__ */ new Set();
165
+ const viteRscServer = await (0, import_vite.createServer)({
166
+ envFile: false,
167
+ define: {
168
+ "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
169
+ },
170
+ ssr: {
171
+ // Inline every file apart from node built-ins. We want vite/rollup to
172
+ // inline dependencies in the server build. This gets round runtime
173
+ // importing of "server-only" and other packages with poisoned imports.
174
+ //
175
+ // Files included in `noExternal` are files we want Vite to analyze
176
+ // As of vite 5.2 `true` here means "all except node built-ins"
177
+ noExternal: true,
178
+ // TODO (RSC): Other frameworks build for RSC without `noExternal: true`.
179
+ // What are we missing here? When/why is that a better choice? I know
180
+ // we would have to explicitly add a bunch of packages to noExternal, if
181
+ // we wanted to go that route.
182
+ // noExternal: ['@tobbe.dev/rsc-test'],
183
+ // Can't inline prisma client (db calls fail at runtime) or react-dom
184
+ // (css pre-init failure)
185
+ // Server store has to be externalized, because it's a singleton (shared between FW and App)
186
+ external: [
187
+ "@prisma/client",
188
+ "@prisma/fetch-engine",
189
+ "@prisma/internals",
190
+ "@cedarjs/auth-dbauth-api",
191
+ "@cedarjs/cookie-jar",
192
+ "@cedarjs/server-store",
193
+ "@cedarjs/structure",
194
+ "@simplewebauthn/server",
195
+ "graphql-scalars",
196
+ "minimatch",
197
+ "playwright",
198
+ "react-dom"
199
+ ],
200
+ resolve: {
201
+ // These conditions are used in the plugin pipeline, and only affect non-externalized
202
+ // dependencies during the SSR build. Which because of `noExternal: true` means all
203
+ // dependencies apart from node built-ins.
204
+ // TODO (RSC): What's the difference between `conditions` and
205
+ // `externalConditions`? When is one used over the other?
206
+ conditions: ["react-server"],
207
+ externalConditions: ["react-server"]
208
+ },
209
+ optimizeDeps: {
210
+ // We need Vite to optimize these dependencies so that they are resolved
211
+ // with the correct conditions. And so that CJS modules work correctly.
212
+ include: [
213
+ "react/**/*",
214
+ "react-dom/server",
215
+ "react-dom/server.edge",
216
+ "rehackt",
217
+ "react-server-dom-webpack/server",
218
+ "react-server-dom-webpack/server.edge",
219
+ "react-server-dom-webpack/client",
220
+ "react-server-dom-webpack/client.edge",
221
+ "@apollo/client/cache/*",
222
+ "@apollo/client/utilities/*",
223
+ "@apollo/client/react/hooks/*",
224
+ "react-fast-compare",
225
+ "invariant",
226
+ "shallowequal",
227
+ "graphql/language/*",
228
+ "stacktracey",
229
+ "deepmerge",
230
+ "fast-glob",
231
+ "@whatwg-node/fetch",
232
+ "busboy",
233
+ "cookie"
234
+ ],
235
+ // Without excluding `util` we get "TypeError: util.TextEncoder is not
236
+ // a constructor" in react-server-dom-webpack.server because it'll try
237
+ // to use Browserify's `util` instead of Node's. And Browserify's
238
+ // polyfill is missing TextEncoder+TextDecoder. The reason it's using
239
+ // the Browserify polyfill is because we have
240
+ // `vite-plugin-node-polyfills` as a dependency, and that'll add
241
+ // Browserify's `node-util` to `node_modules`, so when Vite goes to
242
+ // resolve `import { TextEncoder } from 'util` it'll find the one in
243
+ // `node_modules` instead of Node's internal version.
244
+ // We only see this in dev, and not in prod. I'm not entirely sure why
245
+ // but I have two guesses: 1. When RSC is enabled we don't actually use
246
+ // `vite-plugin-node-polyfill`, so some kind of tree shaking is
247
+ // happening, which prevents the issue from occurring. 2. In prod we
248
+ // only use Node's dependency resolution. Vite is not involved. And
249
+ // that difference in resolution is what prevents the issue from
250
+ // occurring.
251
+ exclude: ["util"]
252
+ }
253
+ },
254
+ resolve: {
255
+ conditions: ["react-server"]
256
+ },
257
+ plugins: [
258
+ {
259
+ name: "rsc-record-and-tranform-use-client-plugin",
260
+ transform(code, id, _options) {
261
+ globalThis.__rwjs__client_references?.delete(id);
262
+ if (!/^(["'])use client\1/.test(code)) {
263
+ return void 0;
264
+ }
265
+ console.log(
266
+ "rsc-record-and-transform-use-client-plugin: adding client reference",
267
+ id
268
+ );
269
+ globalThis.__rwjs__client_references?.add(id);
270
+ const fns = code.matchAll(/export function (\w+)\(/g);
271
+ const consts = code.matchAll(/export const (\w+) = \(/g);
272
+ const names = [...fns, ...consts].map(([, name]) => name);
273
+ const result = [
274
+ `import { registerClientReference } from "react-server-dom-webpack/server.edge";`,
275
+ "",
276
+ ...names.map((name) => {
277
+ return name === "default" ? `export default registerClientReference({}, "${id}", "${name}");` : `export const ${name} = registerClientReference({}, "${id}", "${name}");`;
278
+ })
279
+ ].join("\n");
280
+ console.log("rsc-record-and-transform-use-client-plugin result");
281
+ console.log(
282
+ result.split("\n").map((line, i) => ` ${i + 1}: ${line}`).join("\n")
283
+ );
284
+ return { code: result, map: null };
285
+ }
286
+ },
287
+ (0, import_vite_plugin_rsc_transform_server.rscTransformUseServerPlugin)("", {}),
288
+ // The rscTransformUseClientPlugin maps paths like
289
+ // /Users/tobbe/.../rw-app/node_modules/@tobbe.dev/rsc-test/dist/rsc-test.es.js
290
+ // to
291
+ // /Users/tobbe/.../rw-app/web/dist/ssr/assets/rsc0.js
292
+ // That's why it needs the `clientEntryFiles` data
293
+ // (It does other things as well, but that's why it needs clientEntryFiles)
294
+ // rscTransformUseClientPlugin(clientEntryFiles),
295
+ // rscTransformUseServerPlugin(outDir, serverEntryFiles),
296
+ (0, import_vite_plugin_rsc_routes_imports.rscRoutesImports)(),
297
+ {
298
+ name: "rsc-hot-update",
299
+ handleHotUpdate(ctx) {
300
+ console.log("rsc-hot-update ctx.modules", ctx.modules);
301
+ return [];
302
+ }
303
+ }
304
+ ],
305
+ build: {
306
+ ssr: true
307
+ },
308
+ server: {
309
+ // We never call `viteRscServer.listen()`, so we should run this in
310
+ // middleware mode
311
+ middlewareMode: true,
312
+ // The hmr/fast-refresh websocket in this server collides with the one in
313
+ // the other Vite server. So we can either disable it or run it on a
314
+ // different port.
315
+ // TODO (RSC): Figure out if we should disable or just pick a different
316
+ // port
317
+ ws: false
318
+ // hmr: {
319
+ // port: 24679,
320
+ // },
321
+ },
322
+ appType: "custom",
323
+ // Using a unique cache dir here to not clash with our other vite server
324
+ cacheDir: "../node_modules/.vite-rsc"
325
+ });
326
+ globalThis.__rwjs__vite_rsc_runtime = await (0, import_vite.createViteRuntime)(viteRscServer);
84
327
  const handleWithMiddleware = (route) => {
85
328
  return (0, import_server.createServerAdapter)(async (req) => {
86
- const middlewareRouter = await (0, import_register.createMiddlewareRouter)(vite);
329
+ const middlewareRouter = await (0, import_register.createMiddlewareRouter)(viteSsrDevServer);
87
330
  const middleware = middlewareRouter.find(
88
331
  req.method,
89
332
  req.url
@@ -93,19 +336,22 @@ async function createServer() {
93
336
  }
94
337
  const [mwRes] = await (0, import_invokeMiddleware.invoke)(req, middleware, {
95
338
  route,
96
- viteDevServer: vite
339
+ viteSsrDevServer
97
340
  });
98
341
  return mwRes.toResponse();
99
342
  });
100
343
  };
101
- app.use(vite.middlewares);
344
+ app.use(viteSsrDevServer.middlewares);
102
345
  if (rscEnabled) {
103
- const { createRscRequestHandler } = await import("./rsc/rscRequestHandler.js");
346
+ (0, import_rscWebSocketServer.createWebSocketServer)();
347
+ const { createRscRequestHandler } = await globalThis.__rwjs__vite_rsc_runtime.executeUrl(
348
+ new URL("./rsc/rscRequestHandler.js", import_meta.url).pathname
349
+ );
104
350
  app.use(
105
351
  "/rw-rsc",
106
- createRscRequestHandler({
107
- getMiddlewareRouter: async () => (0, import_register.createMiddlewareRouter)(vite),
108
- viteDevServer: vite
352
+ await createRscRequestHandler({
353
+ getMiddlewareRouter: async () => (0, import_register.createMiddlewareRouter)(viteSsrDevServer),
354
+ viteSsrDevServer
109
355
  })
110
356
  );
111
357
  }
@@ -115,18 +361,22 @@ async function createServer() {
115
361
  routes,
116
362
  clientEntryPath: rwPaths.web.entryClient,
117
363
  getStylesheetLinks: (route) => {
118
- return getCssLinks({ rwPaths, route, vite });
364
+ return getCssLinks({
365
+ rwPaths,
366
+ route,
367
+ viteSsrDevServer
368
+ });
119
369
  },
120
370
  // Recreate middleware router on each request in dev
121
- getMiddlewareRouter: async () => (0, import_register.createMiddlewareRouter)(vite)
371
+ getMiddlewareRouter: async () => (0, import_register.createMiddlewareRouter)(viteSsrDevServer)
122
372
  },
123
- vite
373
+ viteSsrDevServer
124
374
  );
125
375
  app.get("*", (0, import_server.createServerAdapter)(routeHandler));
126
376
  app.post("*", handleWithMiddleware());
127
377
  const port = (0, import_project_config.getConfig)().web.port;
128
378
  console.log(`Started server on http://localhost:${port}`);
129
- return app.listen(port);
379
+ return server.listen(port);
130
380
  }
131
381
  let devApp = createServer();
132
382
  process.stdin.on("data", async (data) => {
@@ -141,11 +391,11 @@ process.stdin.on("data", async (data) => {
141
391
  function getCssLinks({
142
392
  rwPaths,
143
393
  route,
144
- vite
394
+ viteSsrDevServer
145
395
  }) {
146
396
  const appAndRouteModules = (0, import_collectCss.componentsModules)(
147
397
  [rwPaths.web.app, route?.filePath].filter(Boolean),
148
- vite
398
+ viteSsrDevServer
149
399
  );
150
400
  const collectedCss = (0, import_collectCss.collectCssPaths)(appAndRouteModules);
151
401
  const cssLinks = Array.from(collectedCss);
@@ -95,6 +95,15 @@ function registerFwShims() {
95
95
  globalThis.__rw_module_cache__ ||= /* @__PURE__ */ new Map();
96
96
  globalThis.__webpack_chunk_load__ ||= async (id) => {
97
97
  console.log("registerFwShims chunk load id", id);
98
+ if (globalThis.__rwjs__vite_ssr_runtime) {
99
+ return globalThis.__rwjs__vite_ssr_runtime?.executeUrl(id).then((mod) => {
100
+ console.log("registerFwShims chunk load mod", mod);
101
+ if (mod.default && typeof mod.default === "object") {
102
+ return globalThis.__rw_module_cache__.set(id, mod.default);
103
+ }
104
+ return globalThis.__rw_module_cache__.set(id, mod);
105
+ });
106
+ }
98
107
  return import(id).then((mod) => {
99
108
  console.log("registerFwShims chunk load mod", mod);
100
109
  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.__rwjs__vite_rsc_runtime) {
47
+ const serverMod = await globalThis.__rwjs__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.__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
+ }
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.__rwjs__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
- __rwjs__Routes: (0, import_react.createElement)(serverRoutes)
130
+ __rwjs__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
- __rwjs__Routes: (0, import_react.createElement)(serverRoutes),
169
+ __rwjs__Routes: createElement(serverRoutes),
156
170
  __rwjs__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.__rwjs__vite_rsc_runtime) {
37
+ const reactMod = await globalThis.__rwjs__vite_rsc_runtime.executeUrl("react");
38
+ return reactMod.default;
39
+ }
40
+ return import("react");
41
+ }
42
+ async function importRsdwServer() {
43
+ if (globalThis.__rwjs__vite_rsc_runtime) {
44
+ const rsdwServerMod = await globalThis.__rwjs__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
+ });