@vitejs/plugin-rsc 0.4.32 → 0.4.34

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/README.md CHANGED
@@ -561,6 +561,10 @@ Note that while there are official npm packages [`server-only`](https://www.npmj
561
561
 
562
562
  This build-time validation is enabled by default and can be disabled by setting `validateImports: false` in the plugin options.
563
563
 
564
+ ### `react-server-dom-webpack`
565
+
566
+ Currently `@vitejs/plugin-rsc` includes a vendored version of `react-server-dom-webpack`. However, when `react-server-dom-webpack` is installed in user project's dependencies, the plugin will automatically use it instead. This allows you to stay up-to-date with the latest React Server Components runtime without waiting for plugin updates.
567
+
564
568
  ## Credits
565
569
 
566
570
  This project builds on fundamental techniques and insights from pioneering Vite RSC implementations.
@@ -1,7 +1,8 @@
1
1
  import { createDebug } from "./dist-DiJnRA1C.js";
2
- import { parseIdQuery } from "./shared-AvKUASD5.js";
2
+ import { parseIdQuery } from "./shared-n-ykEs15.js";
3
3
  import fs from "node:fs";
4
4
  import path from "node:path";
5
+ import { fileURLToPath, pathToFileURL } from "node:url";
5
6
  import * as esModuleLexer from "es-module-lexer";
6
7
  import MagicString from "magic-string";
7
8
  import { parseAstAsync } from "vite";
@@ -10,7 +11,8 @@ import { walk } from "estree-walker";
10
11
  import { analyze } from "periscopic";
11
12
 
12
13
  //#region src/transforms/cjs.ts
13
- function transformCjsToEsm(code, ast) {
14
+ const CJS_INTEROP_HELPER = `function __cjs_interop__(m) { return m.__cjs_module_runner_transform ? m.default : m; }`;
15
+ function transformCjsToEsm(code, ast, options) {
14
16
  const output = new MagicString(code);
15
17
  const analyzed = analyze(ast);
16
18
  const parentNodes = [];
@@ -27,12 +29,12 @@ function transformCjsToEsm(code, ast) {
27
29
  if (scope && scope.declarations.has("require")) return;
28
30
  }
29
31
  if (isTopLevel) {
30
- output.update(node.start, node.callee.end, "((await import");
31
- output.appendRight(node.end, ").default)");
32
+ output.update(node.start, node.callee.end, "(__cjs_interop__(await import");
33
+ output.appendRight(node.end, "))");
32
34
  } else {
33
35
  const hoisted = `__cjs_to_esm_hoist_${hoistIndex}`;
34
36
  const importee = code.slice(node.arguments[0].start, node.arguments[0].end);
35
- hoistedCodes.push(`const ${hoisted} = (await import(${importee})).default;\n`);
37
+ hoistedCodes.push(`const ${hoisted} = __cjs_interop__(await import(${importee}));\n`);
36
38
  output.update(node.start, node.end, hoisted);
37
39
  hoistIndex++;
38
40
  }
@@ -43,7 +45,16 @@ function transformCjsToEsm(code, ast) {
43
45
  }
44
46
  });
45
47
  for (const hoisted of hoistedCodes.reverse()) output.prepend(hoisted);
48
+ if (output.hasChanged()) output.prepend(`${CJS_INTEROP_HELPER}\n`);
46
49
  output.prepend(`let exports = {}; const module = { exports };\n`);
50
+ const __filename = fileURLToPath(pathToFileURL(options.id).href);
51
+ const __dirname = path.dirname(__filename);
52
+ output.prepend(`let __filename = ${JSON.stringify(__filename)}; let __dirname = ${JSON.stringify(__dirname)};\n`);
53
+ output.append(`
54
+ ;__vite_ssr_exportAll__(module.exports);
55
+ export default module.exports;
56
+ export const __cjs_module_runner_transform = true;
57
+ `);
47
58
  return { output };
48
59
  }
49
60
 
@@ -74,12 +85,7 @@ function cjsModuleRunnerPlugin() {
74
85
  debug(`non-optimized CJS dependency in '${this.environment.name}' environment: ${id}`);
75
86
  warnedPackages.add(packageKey);
76
87
  }
77
- const ast = await parseAstAsync(code);
78
- const output = transformCjsToEsm(code, ast).output;
79
- output.append(`
80
- ;__vite_ssr_exportAll__(module.exports);
81
- export default module.exports;
82
- `);
88
+ const output = transformCjsToEsm(code, await parseAstAsync(code), { id }).output;
83
89
  return {
84
90
  code: output.toString(),
85
91
  map: output.generateMap({ hires: "boundary" })
@@ -5,14 +5,11 @@ import encryptionKeySource from "virtual:vite-rsc/encryption-key";
5
5
 
6
6
  //#region src/utils/encryption-runtime.ts
7
7
  async function encryptActionBoundArgs(originalValue) {
8
- const serialized = renderToReadableStream(originalValue);
9
- const serializedBuffer = await concatArrayStream(serialized);
10
- return encryptBuffer(serializedBuffer, await getEncryptionKey());
8
+ return encryptBuffer(await concatArrayStream(renderToReadableStream(originalValue)), await getEncryptionKey());
11
9
  }
12
10
  async function decryptActionBoundArgs(encrypted) {
13
11
  const serializedBuffer = await decryptBuffer(await encrypted, await getEncryptionKey());
14
- const serialized = arrayToStream(new Uint8Array(serializedBuffer));
15
- return createFromReadableStream(serialized);
12
+ return createFromReadableStream(arrayToStream(new Uint8Array(serializedBuffer)));
16
13
  }
17
14
  const getEncryptionKey = /* @__PURE__ */ once(async () => {
18
15
  const resolved = await encryptionKeySource();
package/dist/extra/rsc.js CHANGED
@@ -3,7 +3,7 @@ import "../shared-CXg_u-4h.js";
3
3
  import "../encryption-utils-BDwwcMVT.js";
4
4
  import { loadServerAction } from "../rsc-GFzFWyhT.js";
5
5
  import { createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, renderToReadableStream } from "../rsc-BdCB3621.js";
6
- import "../encryption-runtime-CugTJCLM.js";
6
+ import "../encryption-runtime-DT6dtlC5.js";
7
7
  import "../rsc-CiAoLCx8.js";
8
8
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
9
 
@@ -13,11 +13,10 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
13
13
  */
14
14
  async function renderRequest(request, root, options) {
15
15
  function RscRoot() {
16
- const nonceMeta = options?.nonce && /* @__PURE__ */ jsx("meta", {
16
+ return /* @__PURE__ */ jsxs(Fragment, { children: [options?.nonce && /* @__PURE__ */ jsx("meta", {
17
17
  property: "csp-nonce",
18
18
  nonce: options.nonce
19
- });
20
- return /* @__PURE__ */ jsxs(Fragment, { children: [nonceMeta, root] });
19
+ }), root] });
21
20
  }
22
21
  const url = new URL(request.url);
23
22
  const isAction = request.method === "POST";
@@ -34,8 +33,7 @@ async function renderRequest(request, root, options) {
34
33
  returnValue = await (await loadServerAction(actionId)).apply(null, args);
35
34
  } else {
36
35
  const formData = await request.formData();
37
- const result = await (await decodeAction(formData))();
38
- formState = await decodeFormState(result, formData);
36
+ formState = await decodeFormState(await (await decodeAction(formData))(), formData);
39
37
  }
40
38
  }
41
39
  const rscStream = renderToReadableStream({
package/dist/extra/ssr.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import "../dist-DiJnRA1C.js";
2
2
  import "../shared-CXg_u-4h.js";
3
- import "../shared-AvKUASD5.js";
3
+ import "../shared-n-ykEs15.js";
4
4
  import "../ssr-Cm2FP2zD.js";
5
5
  import { createFromReadableStream } from "../ssr-Cd4SbAaO.js";
6
- import "../ssr-8BA2nj0-.js";
7
- import { injectRSCPayload } from "../server-BTo03tXh.js";
6
+ import "../ssr-BQwZitKq.js";
7
+ import { injectRSCPayload } from "../server-DMhFuTz_.js";
8
8
  import React from "react";
9
9
  import { jsx } from "react/jsx-runtime";
10
10
  import ReactDomServer from "react-dom/server.edge";
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import "./dist-DiJnRA1C.js";
2
2
  import "./plugin-CZbI4rhS.js";
3
- import "./transforms-zLwPjso_.js";
3
+ import "./transforms-CpF3zNE0.js";
4
4
  import "./encryption-utils-BDwwcMVT.js";
5
5
  import "./rpc-CUvSZurk.js";
6
- import { getPluginApi, vitePluginRsc } from "./plugin-CiDpxrwJ.js";
7
- import "./cjs-WQBk0zA_.js";
8
- import "./shared-AvKUASD5.js";
6
+ import { getPluginApi, vitePluginRsc } from "./plugin-BLedJFh7.js";
7
+ import "./cjs-BamOAUgw.js";
8
+ import "./shared-n-ykEs15.js";
9
9
 
10
10
  export { vitePluginRsc as default, getPluginApi };
@@ -1,10 +1,10 @@
1
1
  import { createDebug } from "./dist-DiJnRA1C.js";
2
2
  import { vitePluginRscCore } from "./plugin-CZbI4rhS.js";
3
- import { findDirectives, hasDirective, transformDirectiveProxyExport, transformServerActionServer, transformWrapExport } from "./transforms-zLwPjso_.js";
3
+ import { findDirectives, hasDirective, transformDirectiveProxyExport, transformServerActionServer, transformWrapExport } from "./transforms-CpF3zNE0.js";
4
4
  import { generateEncryptionKey, toBase64 } from "./encryption-utils-BDwwcMVT.js";
5
5
  import { createRpcServer } from "./rpc-CUvSZurk.js";
6
- import { cjsModuleRunnerPlugin } from "./cjs-WQBk0zA_.js";
7
- import { parseCssVirtual, parseIdQuery, toCssVirtual } from "./shared-AvKUASD5.js";
6
+ import { cjsModuleRunnerPlugin } from "./cjs-BamOAUgw.js";
7
+ import { parseCssVirtual, parseIdQuery, toCssVirtual } from "./shared-n-ykEs15.js";
8
8
  import { createRequire } from "node:module";
9
9
  import assert from "node:assert";
10
10
  import fs from "node:fs";
@@ -164,8 +164,7 @@ async function transformScanBuildStrip(code) {
164
164
  const [imports] = esModuleLexer.parse(code);
165
165
  let output = imports.map((e) => e.n && `import ${JSON.stringify(e.n)};\n`).filter(Boolean).join("");
166
166
  if (importGlobRE.test(code)) {
167
- const ast = await parseAstAsync(code);
168
- walk(ast, { enter(node) {
167
+ walk(await parseAstAsync(code), { enter(node) {
169
168
  if (node.type === "CallExpression" && node.callee.type === "MemberExpression" && node.callee.object.type === "MetaProperty" && node.callee.object.meta.type === "Identifier" && node.callee.object.meta.name === "import" && node.callee.object.property.type === "Identifier" && node.callee.object.property.name === "meta" && node.callee.property.type === "Identifier" && node.callee.property.name === "glob") {
170
169
  const importMetaGlob = code.slice(node.start, node.end);
171
170
  output += `console.log(${importMetaGlob});\n`;
@@ -205,19 +204,14 @@ function validateImportPlugin() {
205
204
  order: "post",
206
205
  async handler(_code, id) {
207
206
  if (this.environment.mode === "dev") {
208
- if (id.startsWith(`\0virtual:vite-rsc/validate-imports/invalid/`)) {
209
- const chain = getImportChainDev(this.environment, id);
210
- validateImportChain(chain, this.environment.name, this.environment.config.root);
211
- }
207
+ if (id.startsWith(`\0virtual:vite-rsc/validate-imports/invalid/`)) validateImportChain(getImportChainDev(this.environment, id), this.environment.name, this.environment.config.root);
212
208
  }
213
209
  }
214
210
  },
215
211
  buildEnd() {
216
212
  if (this.environment.mode === "build") {
217
- const serverOnly = getImportChainBuild(this, "\0virtual:vite-rsc/validate-imports/invalid/server-only");
218
- validateImportChain(serverOnly, this.environment.name, this.environment.config.root);
219
- const clientOnly = getImportChainBuild(this, "\0virtual:vite-rsc/validate-imports/invalid/client-only");
220
- validateImportChain(clientOnly, this.environment.name, this.environment.config.root);
213
+ validateImportChain(getImportChainBuild(this, "\0virtual:vite-rsc/validate-imports/invalid/server-only"), this.environment.name, this.environment.config.root);
214
+ validateImportChain(getImportChainBuild(this, "\0virtual:vite-rsc/validate-imports/invalid/client-only"), this.environment.name, this.environment.config.root);
221
215
  }
222
216
  }
223
217
  };
@@ -429,6 +423,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
429
423
  fs.writeFileSync(manifestPath, assetsManifestCode);
430
424
  }
431
425
  }
426
+ let hasReactServerDomWebpack = false;
432
427
  return [
433
428
  {
434
429
  name: "rsc",
@@ -451,6 +446,8 @@ function vitePluginRsc(rscPluginOptions = {}) {
451
446
  PKG_NAME,
452
447
  ...result.ssr.noExternal.sort()
453
448
  ];
449
+ hasReactServerDomWebpack = result.ssr.noExternal.includes("react-server-dom-webpack");
450
+ const reactServerDomPackageName = hasReactServerDomWebpack ? "react-server-dom-webpack" : REACT_SERVER_DOM_NAME;
454
451
  return {
455
452
  appType: config.appType ?? "custom",
456
453
  define: { "import.meta.env.__vite_rsc_build__": JSON.stringify(env.command === "build") },
@@ -461,7 +458,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
461
458
  rollupOptions: { input: rscPluginOptions.entries?.client && { index: rscPluginOptions.entries.client } }
462
459
  },
463
460
  optimizeDeps: {
464
- include: ["react-dom/client", `${REACT_SERVER_DOM_NAME}/client.browser`],
461
+ include: ["react-dom/client", `${reactServerDomPackageName}/client.browser`],
465
462
  exclude: [PKG_NAME]
466
463
  }
467
464
  },
@@ -480,7 +477,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
480
477
  "react/jsx-dev-runtime",
481
478
  "react-dom/server.edge",
482
479
  "react-dom/static.edge",
483
- `${REACT_SERVER_DOM_NAME}/client.edge`
480
+ `${reactServerDomPackageName}/client.edge`
484
481
  ],
485
482
  exclude: [PKG_NAME]
486
483
  }
@@ -502,8 +499,8 @@ function vitePluginRsc(rscPluginOptions = {}) {
502
499
  "react-dom",
503
500
  "react/jsx-runtime",
504
501
  "react/jsx-dev-runtime",
505
- `${REACT_SERVER_DOM_NAME}/server.edge`,
506
- `${REACT_SERVER_DOM_NAME}/client.edge`
502
+ `${reactServerDomPackageName}/server.edge`,
503
+ `${reactServerDomPackageName}/client.edge`
507
504
  ],
508
505
  exclude: [PKG_NAME]
509
506
  }
@@ -553,8 +550,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
553
550
  try {
554
551
  const resolved = await environment.pluginContainer.resolveId(source);
555
552
  assert(resolved, `[vite-rsc] failed to resolve server handler '${source}'`);
556
- const mod = await environment.runner.import(resolved.id);
557
- const fetchHandler = getFetchHandlerExport(mod);
553
+ const fetchHandler = getFetchHandlerExport(await environment.runner.import(resolved.id));
558
554
  req.url = req.originalUrl ?? req.url;
559
555
  await createRequestListener(fetchHandler)(req, res);
560
556
  } catch (e) {
@@ -570,10 +566,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
570
566
  environmentName: "rsc",
571
567
  entryName: "index"
572
568
  };
573
- const entryFile = path.join(manager.config.environments[options.environmentName].build.outDir, `${options.entryName}.js`);
574
- const mod = await import(pathToFileURL(entryFile).href);
575
- const fetchHandler = getFetchHandlerExport(mod);
576
- const handler = createRequestListener(fetchHandler);
569
+ const handler = createRequestListener(getFetchHandlerExport(await import(pathToFileURL(path.join(manager.config.environments[options.environmentName].build.outDir, `${options.entryName}.js`)).href)));
577
570
  server.middlewares.use((req, _res, next) => {
578
571
  delete req.headers["accept-encoding"];
579
572
  next();
@@ -641,6 +634,21 @@ function vitePluginRsc(rscPluginOptions = {}) {
641
634
  }
642
635
  }
643
636
  },
637
+ {
638
+ name: "rsc:react-server-dom-webpack-alias",
639
+ resolveId: {
640
+ order: "pre",
641
+ async handler(source, importer, options) {
642
+ if (hasReactServerDomWebpack && source.startsWith(`${PKG_NAME}/vendor/react-server-dom/`)) {
643
+ const newSource = source.replace(`${PKG_NAME}/vendor/react-server-dom`, "react-server-dom-webpack");
644
+ return await this.resolve(newSource, importer, {
645
+ ...options,
646
+ skipSelf: true
647
+ });
648
+ }
649
+ }
650
+ }
651
+ },
644
652
  {
645
653
  name: "rsc:load-ssr-module",
646
654
  transform(code) {
@@ -654,8 +662,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
654
662
  const { server } = manager;
655
663
  const s = new MagicString(code);
656
664
  for (const match of code.matchAll(/import\.meta\.viteRsc\.loadModule\(([\s\S]*?)\)/dg)) {
657
- const argCode = match[1].trim();
658
- const [environmentName, entryName] = evalValue(`[${argCode}]`);
665
+ const [environmentName, entryName] = evalValue(`[${match[1].trim()}]`);
659
666
  let replacement;
660
667
  if (this.environment.mode === "dev" && rscPluginOptions.loadModuleDevProxy) {
661
668
  const origin = server.resolvedUrls?.local[0];
@@ -710,20 +717,18 @@ function vitePluginRsc(rscPluginOptions = {}) {
710
717
  const source = getEntrySource(environment.config, entryName);
711
718
  const resolvedEntry = await environment.pluginContainer.resolveId(source);
712
719
  assert(resolvedEntry, `[vite-rsc] failed to resolve entry '${source}'`);
713
- const runnerProxy = new Proxy({}, { get(_target, p, _receiver) {
720
+ return createRpcServer(new Proxy({}, { get(_target, p, _receiver) {
714
721
  if (typeof p !== "string" || p === "then") return;
715
722
  return async (...args) => {
716
723
  return (await environment.runner.import(resolvedEntry.id))[p](...args);
717
724
  };
718
- } });
719
- return createRpcServer(runnerProxy);
725
+ } }));
720
726
  }
721
727
  server.middlewares.use(async (req, res, next) => {
722
728
  const url = new URL(req.url ?? "/", `http://localhost`);
723
729
  if (url.pathname === "/__vite_rsc_load_module_dev_proxy") {
724
730
  try {
725
- const handler = await createHandler(url);
726
- createRequestListener(handler)(req, res);
731
+ createRequestListener(await createHandler(url))(req, res);
727
732
  } catch (e) {
728
733
  next(e);
729
734
  }
@@ -748,9 +753,8 @@ function vitePluginRsc(rscPluginOptions = {}) {
748
753
  if (id === "\0virtual:vite-rsc/assets-manifest") {
749
754
  assert(this.environment.name !== "client");
750
755
  assert(this.environment.mode === "dev");
751
- const entryUrl = assetsURL("@id/__x00__" + VIRTUAL_ENTRIES.browser, manager);
752
756
  const manifest = {
753
- bootstrapScriptContent: `import(${serializeValueWithRuntime(entryUrl)})`,
757
+ bootstrapScriptContent: `import(${serializeValueWithRuntime(assetsURL("@id/__x00__" + VIRTUAL_ENTRIES.browser, manager))})`,
754
758
  clientReferenceDeps: {}
755
759
  };
756
760
  return `export default ${JSON.stringify(manifest, null, 2)}`;
@@ -822,8 +826,7 @@ export default assetsManifest.bootstrapScriptContent;
822
826
  const output = new MagicString(code);
823
827
  for (const match of code.matchAll(/import\s*\.\s*meta\s*\.\s*viteRsc\s*\.\s*loadBootstrapScriptContent\(([\s\S]*?)\)/dg)) {
824
828
  const argCode = match[1].trim();
825
- const entryName = evalValue(argCode);
826
- assert(entryName, `[vite-rsc] expected 'loadBootstrapScriptContent("index")' but got ${argCode}`);
829
+ assert(evalValue(argCode), `[vite-rsc] expected 'loadBootstrapScriptContent("index")' but got ${argCode}`);
827
830
  let replacement = `Promise.resolve(__vite_rsc_assets_manifest.bootstrapScriptContent)`;
828
831
  const [start, end] = match.indices[0];
829
832
  output.overwrite(start, end, replacement);
@@ -1138,8 +1141,7 @@ function customOptimizerMetadataPlugin({ setMetadata }) {
1138
1141
  configResolved(config) {
1139
1142
  const file = path.join(config.cacheDir, "deps", MEATADATA_FILE);
1140
1143
  if (fs.existsSync(file)) try {
1141
- const metadata = JSON.parse(fs.readFileSync(file, "utf-8"));
1142
- setMetadata(metadata);
1144
+ setMetadata(JSON.parse(fs.readFileSync(file, "utf-8")));
1143
1145
  } catch (e) {
1144
1146
  this.warn(`failed to load '${file}'`);
1145
1147
  }
@@ -1244,7 +1246,7 @@ function vitePluginUseServer(useServerPluginOptions, manager) {
1244
1246
  }
1245
1247
  const result = withRollupError(this, transformDirectiveProxyExport)(ast, {
1246
1248
  code,
1247
- runtime: (name$1) => `$$ReactClient.createServerReference(${JSON.stringify(getNormalizedId() + "#" + name$1)},$$ReactClient.callServer, undefined, ` + (this.environment.mode === "dev" ? `$$ReactClient.findSourceMapURL,` : "undefined,") + `${JSON.stringify(name$1)})`,
1249
+ runtime: (name) => `$$ReactClient.createServerReference(${JSON.stringify(getNormalizedId() + "#" + name)},$$ReactClient.callServer, undefined, ` + (this.environment.mode === "dev" ? `$$ReactClient.findSourceMapURL,` : "undefined,") + `${JSON.stringify(name)})`,
1248
1250
  directive: "use server",
1249
1251
  rejectNonAsyncFunction: true
1250
1252
  });
@@ -1256,8 +1258,7 @@ function vitePluginUseServer(useServerPluginOptions, manager) {
1256
1258
  referenceKey: getNormalizedId(),
1257
1259
  exportNames: result.exportNames
1258
1260
  };
1259
- const name = this.environment.name === browserEnvironmentName ? "browser" : "ssr";
1260
- const importSource = resolvePackage(`${PKG_NAME}/react/${name}`);
1261
+ const importSource = resolvePackage(`${PKG_NAME}/react/${this.environment.name === browserEnvironmentName ? "browser" : "ssr"}`);
1261
1262
  output.prepend(`import * as $$ReactClient from "${importSource}";\n`);
1262
1263
  return {
1263
1264
  code: output.toString(),
@@ -1424,9 +1425,8 @@ function vitePluginRscCss(rscCssOptions = {}, manager) {
1424
1425
  code
1425
1426
  });
1426
1427
  if (!filter) return;
1427
- const ast = await parseAstAsync(code);
1428
1428
  const result = await transformRscCssExport({
1429
- ast,
1429
+ ast: await parseAstAsync(code),
1430
1430
  code,
1431
1431
  filter
1432
1432
  });
@@ -1463,8 +1463,7 @@ function vitePluginRscCss(rscCssOptions = {}, manager) {
1463
1463
  if (!mod?.id || !mod?.file) return `export default []`;
1464
1464
  const result = collectCss(server.environments.ssr, mod.id);
1465
1465
  for (const file of [mod.file, ...result.visitedFiles]) this.addWatchFile(file);
1466
- const hrefs = result.hrefs.map((href) => assetsURL(href.slice(1), manager));
1467
- return `export default ${serializeValueWithRuntime(hrefs)}`;
1466
+ return `export default ${serializeValueWithRuntime(result.hrefs.map((href) => assetsURL(href.slice(1), manager)))}`;
1468
1467
  }
1469
1468
  }
1470
1469
  },
@@ -1538,12 +1537,10 @@ function vitePluginRscCss(rscCssOptions = {}, manager) {
1538
1537
  if (this.environment.mode === "dev") {
1539
1538
  const result = collectCss(server.environments.rsc, importer);
1540
1539
  for (const file of [importer, ...result.visitedFiles]) this.addWatchFile(file);
1541
- const cssHrefs = result.hrefs.map((href) => href.slice(1));
1542
- const deps = assetsURLOfDeps({
1543
- css: cssHrefs,
1540
+ return generateResourcesCode(serializeValueWithRuntime(assetsURLOfDeps({
1541
+ css: result.hrefs.map((href) => href.slice(1)),
1544
1542
  js: []
1545
- }, manager);
1546
- return generateResourcesCode(serializeValueWithRuntime(deps), manager);
1543
+ }, manager)), manager);
1547
1544
  } else {
1548
1545
  const key = manager.toRelativeId(importer);
1549
1546
  manager.serverResourcesMetaMap[importer] = { key };
package/dist/plugin.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import "./dist-DiJnRA1C.js";
2
2
  import "./plugin-CZbI4rhS.js";
3
- import "./transforms-zLwPjso_.js";
3
+ import "./transforms-CpF3zNE0.js";
4
4
  import "./encryption-utils-BDwwcMVT.js";
5
5
  import "./rpc-CUvSZurk.js";
6
- import { getPluginApi, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal } from "./plugin-CiDpxrwJ.js";
7
- import "./cjs-WQBk0zA_.js";
8
- import "./shared-AvKUASD5.js";
6
+ import { getPluginApi, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal } from "./plugin-BLedJFh7.js";
7
+ import "./cjs-BamOAUgw.js";
8
+ import "./shared-n-ykEs15.js";
9
9
 
10
10
  export { vitePluginRsc as default, getPluginApi, transformRscCssExport, vitePluginRscMinimal };
@@ -1,5 +1,5 @@
1
1
  import "../dist-DiJnRA1C.js";
2
- import { cjsModuleRunnerPlugin } from "../cjs-WQBk0zA_.js";
3
- import "../shared-AvKUASD5.js";
2
+ import { cjsModuleRunnerPlugin } from "../cjs-BamOAUgw.js";
3
+ import "../shared-n-ykEs15.js";
4
4
 
5
5
  export { cjsModuleRunnerPlugin };
@@ -1,4 +1,4 @@
1
- import { injectRSCPayload } from "../server-BTo03tXh.js";
1
+ import { injectRSCPayload } from "../server-DMhFuTz_.js";
2
2
 
3
3
  //#region src/rsc-html-stream/ssr.ts
4
4
  /** @deprecated use `rsc-html-stream/server` instead */
package/dist/rsc.js CHANGED
@@ -3,7 +3,7 @@ import "./shared-CXg_u-4h.js";
3
3
  import "./encryption-utils-BDwwcMVT.js";
4
4
  import { createClientManifest, createServerManifest, loadServerAction, setRequireModule } from "./rsc-GFzFWyhT.js";
5
5
  import { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, registerClientReference, registerServerReference, renderToReadableStream } from "./rsc-BdCB3621.js";
6
- import { decryptActionBoundArgs, encryptActionBoundArgs } from "./encryption-runtime-CugTJCLM.js";
6
+ import { decryptActionBoundArgs, encryptActionBoundArgs } from "./encryption-runtime-DT6dtlC5.js";
7
7
  import "./rsc-CiAoLCx8.js";
8
8
 
9
9
  export { createClientManifest, createClientTemporaryReferenceSet, createFromReadableStream, createServerManifest, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, decryptActionBoundArgs, encodeReply, encryptActionBoundArgs, loadServerAction, registerClientReference, registerServerReference, renderToReadableStream, setRequireModule };
@@ -56,8 +56,7 @@ async function writeRSCStream(rscStream, controller, nonce) {
56
56
  for await (let chunk of rscStream) try {
57
57
  writeChunk(JSON.stringify(decoder.decode(chunk, { stream: true })), controller, nonce);
58
58
  } catch (err) {
59
- let base64 = JSON.stringify(btoa(String.fromCodePoint(...chunk)));
60
- writeChunk(`Uint8Array.from(atob(${base64}), m => m.codePointAt(0))`, controller, nonce);
59
+ writeChunk(`Uint8Array.from(atob(${JSON.stringify(btoa(String.fromCodePoint(...chunk)))}), m => m.codePointAt(0))`, controller, nonce);
61
60
  }
62
61
  let remaining = decoder.decode();
63
62
  if (remaining.length) writeChunk(JSON.stringify(remaining), controller, nonce);
@@ -11,10 +11,9 @@ function parseIdQuery(id) {
11
11
  query: {}
12
12
  };
13
13
  const [filename, rawQuery] = id.split(`?`, 2);
14
- const query = Object.fromEntries(new URLSearchParams(rawQuery));
15
14
  return {
16
15
  filename,
17
- query
16
+ query: Object.fromEntries(new URLSearchParams(rawQuery))
18
17
  };
19
18
  }
20
19
 
@@ -1,4 +1,4 @@
1
- import { toCssVirtual } from "./shared-AvKUASD5.js";
1
+ import { toCssVirtual } from "./shared-n-ykEs15.js";
2
2
  import { setRequireModule } from "./ssr-Cm2FP2zD.js";
3
3
  import * as clientReferences from "virtual:vite-rsc/client-references";
4
4
  import assetsManifest from "virtual:vite-rsc/assets-manifest";
@@ -8,29 +8,25 @@ import * as ReactDOM from "react-dom";
8
8
  initialize();
9
9
  function initialize() {
10
10
  setRequireModule({ load: async (id) => {
11
- if (!import.meta.env.__vite_rsc_build__) {
12
- const mod = await import(
13
- /* @vite-ignore */
14
- id
15
- );
16
- const modCss = await import(
11
+ if (!import.meta.env.__vite_rsc_build__) return wrapResourceProxy(await import(
12
+ /* @vite-ignore */
13
+ id
14
+ ), {
15
+ js: [],
16
+ css: (await import(
17
17
  /* @vite-ignore */
18
18
  "/@id/__x00__" + toCssVirtual({
19
19
  id,
20
20
  type: "ssr"
21
21
  })
22
- );
23
- return wrapResourceProxy(mod, {
24
- js: [],
25
- css: modCss.default
26
- });
27
- } else {
22
+ )).default
23
+ });
24
+ else {
28
25
  const import_ = clientReferences.default[id];
29
26
  if (!import_) throw new Error(`client reference not found '${id}'`);
30
27
  const deps = assetsManifest.clientReferenceDeps[id];
31
28
  if (deps) preloadDeps(deps);
32
- const mod = await import_();
33
- return wrapResourceProxy(mod, deps);
29
+ return wrapResourceProxy(await import_(), deps);
34
30
  }
35
31
  } });
36
32
  }
package/dist/ssr.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import "./dist-DiJnRA1C.js";
2
2
  import "./shared-CXg_u-4h.js";
3
- import "./shared-AvKUASD5.js";
3
+ import "./shared-n-ykEs15.js";
4
4
  import { createServerConsumerManifest, setRequireModule } from "./ssr-Cm2FP2zD.js";
5
5
  import { callServer, createFromReadableStream, createServerReference, findSourceMapURL } from "./ssr-Cd4SbAaO.js";
6
- import "./ssr-8BA2nj0-.js";
6
+ import "./ssr-BQwZitKq.js";
7
7
 
8
8
  export { callServer, createFromReadableStream, createServerConsumerManifest, createServerReference, findSourceMapURL, setRequireModule };
@@ -1,4 +1,4 @@
1
1
  import "../dist-DiJnRA1C.js";
2
- import { findDirectives, getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport } from "../transforms-zLwPjso_.js";
2
+ import { findDirectives, getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport } from "../transforms-CpF3zNE0.js";
3
3
 
4
4
  export { findDirectives, getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport };
@@ -290,8 +290,7 @@ function transformProxyExport(ast, options) {
290
290
  }
291
291
  }
292
292
  }
293
- const names = node.declaration.declarations.flatMap((decl) => extract_names(decl.id));
294
- createExport(node, names);
293
+ createExport(node, node.declaration.declarations.flatMap((decl) => extract_names(decl.id)));
295
294
  } else node.declaration;
296
295
  else {
297
296
  /**
@@ -3,6 +3,6 @@ import "../shared-CXg_u-4h.js";
3
3
  import "../encryption-utils-BDwwcMVT.js";
4
4
  import "../rsc-GFzFWyhT.js";
5
5
  import "../rsc-BdCB3621.js";
6
- import { decryptActionBoundArgs, encryptActionBoundArgs } from "../encryption-runtime-CugTJCLM.js";
6
+ import { decryptActionBoundArgs, encryptActionBoundArgs } from "../encryption-runtime-DT6dtlC5.js";
7
7
 
8
8
  export { decryptActionBoundArgs, encryptActionBoundArgs };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitejs/plugin-rsc",
3
- "version": "0.4.32",
3
+ "version": "0.4.34",
4
4
  "description": "React Server Components (RSC) support for Vite.",
5
5
  "keywords": [
6
6
  "vite",
@@ -39,7 +39,7 @@
39
39
  "prepack": "tsdown"
40
40
  },
41
41
  "dependencies": {
42
- "@remix-run/node-fetch-server": "^0.9.0",
42
+ "@remix-run/node-fetch-server": "^0.10.0",
43
43
  "es-module-lexer": "^1.7.0",
44
44
  "estree-walker": "^3.0.3",
45
45
  "magic-string": "^0.30.19",
@@ -49,23 +49,30 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "@hiogawa/utils": "^1.7.0",
52
- "@playwright/test": "^1.55.0",
53
- "@tsconfig/strictest": "^2.0.5",
52
+ "@playwright/test": "^1.55.1",
53
+ "@tsconfig/strictest": "^2.0.6",
54
54
  "@types/estree": "^1.0.8",
55
- "@types/node": "^22.18.6",
56
- "@types/react": "^19.1.13",
55
+ "@types/node": "^22.18.8",
56
+ "@types/react": "^19.1.16",
57
57
  "@types/react-dom": "^19.1.9",
58
58
  "@vitejs/plugin-react": "workspace:*",
59
+ "@vitejs/test-dep-cjs-and-esm": "./test-dep/cjs-and-esm",
59
60
  "react": "^19.1.1",
60
61
  "react-dom": "^19.1.1",
61
62
  "react-server-dom-webpack": "^19.1.1",
62
63
  "rsc-html-stream": "^0.0.7",
63
64
  "tinyexec": "^1.0.1",
64
- "tsdown": "^0.15.4"
65
+ "tsdown": "^0.15.6"
65
66
  },
66
67
  "peerDependencies": {
67
68
  "react": "*",
68
69
  "react-dom": "*",
70
+ "react-server-dom-webpack": "*",
69
71
  "vite": "*"
72
+ },
73
+ "peerDependenciesMeta": {
74
+ "react-server-dom-webpack": {
75
+ "optional": true
76
+ }
70
77
  }
71
78
  }