@vitejs/plugin-rsc 0.5.26 → 0.5.28

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 (57) hide show
  1. package/README.md +34 -18
  2. package/dist/browser.d.ts +3 -3
  3. package/dist/{cjs-BdahOUyh.js → cjs-Cxg_7upE.js} +3 -3
  4. package/dist/client-BrwlzXgg.d.ts +19 -0
  5. package/dist/core/browser.d.ts +1 -1
  6. package/dist/core/browser.js +2 -2
  7. package/dist/core/plugin.d.ts +0 -1
  8. package/dist/core/rsc.d.ts +1 -19
  9. package/dist/core/rsc.js +20 -4
  10. package/dist/core/ssr.d.ts +1 -2
  11. package/dist/core/ssr.js +2 -2
  12. package/dist/{encryption-utils-BblioYEx.js → encryption-utils-BNbYHtC4.js} +1 -1
  13. package/dist/{index-2GoUFmVR.d.ts → index-BjJe9jqG.d.ts} +52 -20
  14. package/dist/{index-D2a5dlVU.d.ts → index-CqNlZcWp.d.ts} +12 -1
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.js +1 -1
  17. package/dist/{picocolors-BDx0CW3k.js → picocolors-DFVOi1sR.js} +4 -2
  18. package/dist/{plugin-BhzHKRFo.js → plugin-BOTpkess.js} +89 -20
  19. package/dist/{plugin-DGxRH4Nv.d.ts → plugin-CaLiN8ED.d.ts} +71 -64
  20. package/dist/plugin.d.ts +2 -2
  21. package/dist/plugin.js +1 -1
  22. package/dist/plugins/cjs.d.ts +0 -1
  23. package/dist/plugins/cjs.js +1 -1
  24. package/dist/react/browser.d.ts +2 -3
  25. package/dist/react/rsc/client.d.ts +2 -0
  26. package/dist/react/rsc/client.js +16 -0
  27. package/dist/react/rsc/server.d.ts +3 -0
  28. package/dist/react/rsc/server.js +20 -0
  29. package/dist/react/rsc.d.ts +3 -24
  30. package/dist/react/rsc.js +3 -31
  31. package/dist/react/ssr.d.ts +4 -3
  32. package/dist/react/ssr.js +3 -1
  33. package/dist/rsc/client.d.ts +2 -0
  34. package/dist/rsc/client.js +3 -0
  35. package/dist/rsc/server.d.ts +16 -0
  36. package/dist/rsc/server.js +20 -0
  37. package/dist/rsc-CGkkhLG3.d.ts +21 -0
  38. package/dist/rsc.d.ts +4 -16
  39. package/dist/rsc.js +4 -41
  40. package/dist/{scope-DKCDtt0O.js → scope-Do08R7C2.js} +4 -38
  41. package/dist/server-DTkvSyJT.d.ts +20 -0
  42. package/dist/shared-D42sHPD1.js +25 -0
  43. package/dist/{shared-BViDMJTQ.js → shared-Y4B6DJ99.js} +2 -1
  44. package/dist/ssr.d.ts +12 -12
  45. package/dist/ssr.js +12 -7
  46. package/dist/transforms/index.d.ts +2 -2
  47. package/dist/transforms/index.js +133 -34
  48. package/dist/utils/encryption-runtime.js +5 -5
  49. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.browser.development.js +2 -2
  50. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.node.development.js +70 -33
  51. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.node.production.js +69 -29
  52. package/dist/vendor/react-server-dom/package.json +3 -3
  53. package/package.json +13 -13
  54. package/dist/chunk-DpdyVxdi.js +0 -25
  55. /package/dist/{browser-CUMAmYC3.d.ts → browser-DI_Wyg5Y.d.ts} +0 -0
  56. /package/dist/{dist-rz-Bnebz.js → dist-uqdtSkzK.js} +0 -0
  57. /package/dist/{shared-DeahDSXi.js → shared-B6H2TbnP.js} +0 -0
@@ -1,11 +1,10 @@
1
- import { n as __toESM } from "./chunk-DpdyVxdi.js";
2
- import { t as createDebug } from "./dist-rz-Bnebz.js";
1
+ import { t as createDebug } from "./dist-uqdtSkzK.js";
3
2
  import vitePluginRscCore from "./core/plugin.js";
4
- import { a as hasDirective } from "./scope-DKCDtt0O.js";
5
- import { t as cjsModuleRunnerPlugin } from "./cjs-BdahOUyh.js";
6
- import { i as toCssVirtual, n as parseIdQuery, r as parseReferenceValidationVirtual, t as parseCssVirtual } from "./shared-DeahDSXi.js";
7
- import { findDirectives, transformDirectiveProxyExport, transformServerActionServer, transformWrapExport } from "./transforms/index.js";
8
- import { o as generateEncryptionKey, s as toBase64 } from "./encryption-utils-BblioYEx.js";
3
+ import { i as hasDirective } from "./scope-Do08R7C2.js";
4
+ import { t as cjsModuleRunnerPlugin } from "./cjs-Cxg_7upE.js";
5
+ import { i as toCssVirtual, n as parseIdQuery, r as parseReferenceValidationVirtual, t as parseCssVirtual } from "./shared-B6H2TbnP.js";
6
+ import { findDirectives, transformDirectiveProxyExport, transformExpandExportAll, transformServerActionServer, transformWrapExport } from "./transforms/index.js";
7
+ import { o as generateEncryptionKey, s as toBase64 } from "./encryption-utils-BNbYHtC4.js";
9
8
  import { createRpcServer } from "./utils/rpc.js";
10
9
  import { createRequire } from "node:module";
11
10
  import assert from "node:assert";
@@ -23,6 +22,29 @@ import { crawlFrameworkPkgs } from "vitefu";
23
22
  import { walk } from "estree-walker";
24
23
  import { stripVTControlCharacters } from "node:util";
25
24
  import { createHash } from "node:crypto";
25
+ //#region \0rolldown/runtime.js
26
+ var __create = Object.create;
27
+ var __defProp = Object.defineProperty;
28
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
29
+ var __getOwnPropNames = Object.getOwnPropertyNames;
30
+ var __getProtoOf = Object.getPrototypeOf;
31
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
32
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
33
+ var __copyProps = (to, from, except, desc) => {
34
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
35
+ key = keys[i];
36
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
37
+ get: ((k) => from[k]).bind(null, key),
38
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
39
+ });
40
+ }
41
+ return to;
42
+ };
43
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
44
+ value: mod,
45
+ enumerable: true
46
+ }) : target, mod));
47
+ //#endregion
26
48
  //#region src/plugins/vite-utils.ts
27
49
  const VALID_ID_PREFIX = `/@id/`;
28
50
  const NULL_BYTE_PLACEHOLDER = `__x00__`;
@@ -583,15 +605,24 @@ function vitePluginRscMinimal(rscPluginOptions = {}, manager = new RscPluginMana
583
605
  apply: "serve",
584
606
  load: {
585
607
  filter: { id: prefixRegex("\0virtual:vite-rsc/reference-validation?") },
586
- handler(id, _options) {
608
+ async handler(id, _options) {
587
609
  if (id.startsWith("\0virtual:vite-rsc/reference-validation?")) {
588
610
  const parsed = parseReferenceValidationVirtual(id);
589
611
  assert(parsed);
612
+ assert(this.environment.mode === "dev");
590
613
  if (parsed.type === "client") {
591
614
  if (Object.values(manager.clientReferenceMetaMap).find((meta) => meta.referenceKey === parsed.id)) return `export {}`;
592
615
  }
593
616
  if (parsed.type === "server") {
594
- if (Object.values(manager.serverReferenceMetaMap).find((meta) => meta.referenceKey === parsed.id)) return `export {}`;
617
+ let meta = Object.values(manager.serverReferenceMetaMap).find((meta) => meta.referenceKey === parsed.id);
618
+ if (!meta) {
619
+ try {
620
+ const id = (await this.resolve(parsed.id))?.id ?? parsed.id;
621
+ if (isFileLoadingAllowed(manager.config, slash(cleanUrl(id)))) await this.environment.transformRequest(parsed.id);
622
+ } catch {}
623
+ meta = Object.values(manager.serverReferenceMetaMap).find((meta) => meta.referenceKey === parsed.id);
624
+ }
625
+ if (meta) return `export {}`;
595
626
  }
596
627
  this.error(`[vite-rsc] invalid ${parsed.type} reference '${parsed.id}'`);
597
628
  }
@@ -605,7 +636,7 @@ function vitePluginRscMinimal(rscPluginOptions = {}, manager = new RscPluginMana
605
636
  function vitePluginRsc(rscPluginOptions = {}) {
606
637
  const manager = new RscPluginManager();
607
638
  const buildApp = async (builder) => {
608
- const colors = await import("./picocolors-BDx0CW3k.js").then((m) => /* @__PURE__ */ __toESM(m.default, 1));
639
+ const colors = await import("./picocolors-DFVOi1sR.js").then((m) => /* @__PURE__ */ __toESM(m.default, 1));
609
640
  const logStep = (msg) => {
610
641
  builder.config.logger.info(colors.blue(msg));
611
642
  };
@@ -1074,6 +1105,7 @@ export function createRpcClient(params) {
1074
1105
  }, manager);
1075
1106
  const assetDeps = collectAssetDeps(bundle);
1076
1107
  let bootstrapScriptContent = "";
1108
+ let clientEntryDeps;
1077
1109
  const clientReferenceDeps = {};
1078
1110
  for (const meta of Object.values(manager.clientReferenceMetaMap)) {
1079
1111
  const deps = assetDeps[meta.groupChunkId]?.deps ?? {
@@ -1085,14 +1117,15 @@ export function createRpcClient(params) {
1085
1117
  if (!rscPluginOptions.customClientEntry) {
1086
1118
  const entry = Object.values(assetDeps).find((v) => v.chunk.name === "index" && v.chunk.isEntry);
1087
1119
  if (!entry) throw new Error(`[vite-rsc] Client build must have an entry chunk named "index". Use 'customClientEntry' option to disable this requirement.`);
1088
- const entryDeps = assetsURLOfDeps(entry.deps, manager);
1089
- for (const [key, deps] of Object.entries(clientReferenceDeps)) clientReferenceDeps[key] = mergeAssetDeps(deps, entryDeps);
1120
+ clientEntryDeps = assetsURLOfDeps(entry.deps, manager);
1121
+ for (const [key, deps] of Object.entries(clientReferenceDeps)) clientReferenceDeps[key] = mergeAssetDeps(deps, clientEntryDeps);
1090
1122
  const entryUrl = assetsURL(entry.chunk.fileName, manager);
1091
1123
  if (typeof entryUrl === "string") bootstrapScriptContent = `import(${JSON.stringify(entryUrl)})`;
1092
1124
  else bootstrapScriptContent = new RuntimeAsset(`"import(" + JSON.stringify(${entryUrl.runtime}) + ")"`);
1093
1125
  }
1094
1126
  manager.buildAssetsManifest = {
1095
1127
  bootstrapScriptContent,
1128
+ clientEntryDeps,
1096
1129
  clientReferenceDeps,
1097
1130
  serverResources,
1098
1131
  cssLinkPrecedence: rscPluginOptions.cssLinkPrecedence
@@ -1202,6 +1235,17 @@ function globalAsyncLocalStoragePlugin() {
1202
1235
  }
1203
1236
  }];
1204
1237
  }
1238
+ function createTransformExpandExportAllContext(ctx) {
1239
+ return {
1240
+ resolve: async (source, importer) => {
1241
+ return (await ctx.resolve(source, importer))?.id;
1242
+ },
1243
+ load: async (id) => {
1244
+ const raw = await fs.promises.readFile(id, "utf-8");
1245
+ return parseAstAsync((await (vite.transformWithOxc ?? vite.transformWithEsbuild)(raw, id, { sourcemap: false })).code);
1246
+ }
1247
+ };
1248
+ }
1205
1249
  function vitePluginUseClient(useClientPluginOptions, manager) {
1206
1250
  const packageSources = /* @__PURE__ */ new Map();
1207
1251
  const bareImportRE = /^(?![a-zA-Z]:)[\w@](?!.*:\/\/)/;
@@ -1222,7 +1266,7 @@ function vitePluginUseClient(useClientPluginOptions, manager) {
1222
1266
  delete manager.clientReferenceMetaMap[id];
1223
1267
  return;
1224
1268
  }
1225
- const ast = await parseAstAsync(code);
1269
+ let ast = await parseAstAsync(code);
1226
1270
  if (!hasDirective(ast.body, "use client")) {
1227
1271
  delete manager.clientReferenceMetaMap[id];
1228
1272
  return;
@@ -1231,6 +1275,16 @@ function vitePluginUseClient(useClientPluginOptions, manager) {
1231
1275
  const directives = findDirectives(ast, "use server");
1232
1276
  if (directives.length > 0) this.error(`'use server' directive is not allowed inside 'use client'`, directives[0]?.start);
1233
1277
  }
1278
+ const expanded = await transformExpandExportAll({
1279
+ code,
1280
+ ast,
1281
+ importer: id,
1282
+ ...createTransformExpandExportAllContext(this)
1283
+ });
1284
+ if (expanded) {
1285
+ code = expanded.code;
1286
+ ast = await parseAstAsync(code);
1287
+ }
1234
1288
  let importId;
1235
1289
  let referenceKey;
1236
1290
  const packageSource = packageSources.get(id);
@@ -1273,7 +1327,7 @@ function vitePluginUseClient(useClientPluginOptions, manager) {
1273
1327
  exportNames,
1274
1328
  renderedExports: []
1275
1329
  };
1276
- const importSource = resolvePackage(`${PKG_NAME}/react/rsc`);
1330
+ const importSource = resolvePackage(`${PKG_NAME}/react/rsc/server`);
1277
1331
  output.prepend(`import * as $$ReactServer from "${importSource}";\n`);
1278
1332
  return {
1279
1333
  code: output.toString(),
@@ -1380,6 +1434,8 @@ function vitePluginUseClient(useClientPluginOptions, manager) {
1380
1434
  if (this.environment.name === serverEnvironmentName && bareImportRE.test(source) && !(source === "client-only" || source === "server-only")) {
1381
1435
  const resolved = await this.resolve(source, importer, options);
1382
1436
  if (resolved && resolved.id.includes("/node_modules/")) {
1437
+ const resolvedAtRoot = await this.resolve(source, void 0, options);
1438
+ if (!resolvedAtRoot || resolvedAtRoot.id !== resolved.id) return;
1383
1439
  packageSources.set(resolved.id, source);
1384
1440
  return resolved;
1385
1441
  }
@@ -1521,7 +1577,19 @@ function vitePluginUseServer(useServerPluginOptions, manager) {
1521
1577
  delete manager.serverReferenceMetaMap[id];
1522
1578
  return;
1523
1579
  }
1524
- const ast = await parseAstAsync(code);
1580
+ let ast = await parseAstAsync(code);
1581
+ if (hasDirective(ast.body, "use server")) {
1582
+ const expanded = await transformExpandExportAll({
1583
+ code,
1584
+ ast,
1585
+ importer: id,
1586
+ ...createTransformExpandExportAllContext(this)
1587
+ });
1588
+ if (expanded) {
1589
+ code = expanded.code;
1590
+ ast = await parseAstAsync(code);
1591
+ }
1592
+ }
1525
1593
  let normalizedId_;
1526
1594
  const getNormalizedId = () => {
1527
1595
  if (!normalizedId_) {
@@ -1553,7 +1621,7 @@ function vitePluginUseServer(useServerPluginOptions, manager) {
1553
1621
  referenceKey: getNormalizedId(),
1554
1622
  exportNames: "names" in result ? result.names : result.exportNames
1555
1623
  };
1556
- const importSource = resolvePackage(`${PKG_NAME}/react/rsc`);
1624
+ const importSource = resolvePackage(`${PKG_NAME}/react/rsc/server`);
1557
1625
  output.prepend(`import * as $$ReactServer from "${importSource}";\n`);
1558
1626
  if (enableEncryption) {
1559
1627
  const importSource = resolvePackage(`${PKG_NAME}/utils/encryption-runtime`);
@@ -1582,7 +1650,8 @@ function vitePluginUseServer(useServerPluginOptions, manager) {
1582
1650
  referenceKey: getNormalizedId(),
1583
1651
  exportNames: result.exportNames
1584
1652
  };
1585
- const importSource = resolvePackage(`${PKG_NAME}/react/${this.environment.name === browserEnvironmentName ? "browser" : "ssr"}`);
1653
+ const name = this.environment.name === browserEnvironmentName ? "browser" : "ssr";
1654
+ const importSource = resolvePackage(`${PKG_NAME}/react/${name}`);
1586
1655
  output.prepend(`import * as $$ReactClient from "${importSource}";\n`);
1587
1656
  return {
1588
1657
  code: output.toString(),
@@ -1663,8 +1732,8 @@ function assetsURLOfDeps(deps, manager) {
1663
1732
  }
1664
1733
  function mergeAssetDeps(a, b) {
1665
1734
  return {
1666
- js: [...new Set([...a.js, ...b.js])],
1667
- css: [...new Set([...a.css, ...b.css])]
1735
+ js: [.../* @__PURE__ */ new Set([...a.js, ...b.js])],
1736
+ css: [.../* @__PURE__ */ new Set([...a.css, ...b.css])]
1668
1737
  };
1669
1738
  }
1670
1739
  function collectAssetDeps(bundle) {
@@ -1967,4 +2036,4 @@ function __vite_rsc_wrap_css__(value, name) {
1967
2036
  }
1968
2037
  }
1969
2038
  //#endregion
1970
- export { vitePluginRscMinimal as i, transformRscCssExport as n, vitePluginRsc as r, getPluginApi as t };
2039
+ export { __commonJSMin as a, vitePluginRscMinimal as i, transformRscCssExport as n, vitePluginRsc as r, getPluginApi as t };
@@ -1,7 +1,6 @@
1
- import { u as TransformWrapExportFilter } from "./index-2GoUFmVR.js";
1
+ import { f as TransformWrapExportFilter } from "./index-BjJe9jqG.js";
2
2
  import MagicString from "magic-string";
3
3
  import { Plugin, ResolvedConfig, Rollup, ViteDevServer, parseAstAsync } from "vite";
4
-
5
4
  //#region src/plugins/import-environment.d.ts
6
5
  type EnvironmentImportMeta = {
7
6
  resolvedId: string;
@@ -20,23 +19,23 @@ type ClientReferenceMeta = {
20
19
  serverChunk?: string;
21
20
  groupChunkId?: string;
22
21
  };
23
- type ServerRerferenceMeta = {
22
+ type ServerReferenceMeta = {
24
23
  importId: string;
25
24
  referenceKey: string;
26
25
  exportNames: string[];
27
26
  };
28
27
  /**
29
- * @experimental
30
- */
28
+ * @experimental
29
+ */
31
30
  declare class RscPluginManager {
32
- server!: ViteDevServer;
33
- config!: ResolvedConfig;
31
+ server: ViteDevServer;
32
+ config: ResolvedConfig;
34
33
  bundles: Record<string, Rollup.OutputBundle>;
35
34
  buildAssetsManifest: AssetsManifest | undefined;
36
35
  isScanBuild: boolean;
37
36
  clientReferenceMetaMap: Record<string, ClientReferenceMeta>;
38
37
  clientReferenceGroups: Record<string, ClientReferenceMeta[]>;
39
- serverReferenceMetaMap: Record<string, ServerRerferenceMeta>;
38
+ serverReferenceMetaMap: Record<string, ServerReferenceMeta>;
40
39
  serverResourcesMetaMap: Record<string, {
41
40
  key: string;
42
41
  }>;
@@ -48,94 +47,100 @@ declare class RscPluginManager {
48
47
  }
49
48
  type RscPluginOptions = {
50
49
  /**
51
- * shorthand for configuring `environments.(name).build.rollupOptions.input.index`
52
- */
53
- entries?: Partial<Record<"client" | "ssr" | "rsc", string>>; /** @default { enviornmentName: "rsc", entryName: "index" } */
50
+ * shorthand for configuring `environments.(name).build.rollupOptions.input.index`
51
+ */
52
+ entries?: Partial<Record<"client" | "ssr" | "rsc", string>>;
53
+ /** @default { enviornmentName: "rsc", entryName: "index" } */
54
54
  serverHandler?: {
55
55
  environmentName: string;
56
56
  entryName: string;
57
- } | false; /** @default false */
57
+ } | false;
58
+ /** @default false */
58
59
  loadModuleDevProxy?: boolean;
59
60
  rscCssTransform?: false | {
60
61
  filter?: (id: string) => boolean;
61
62
  };
62
63
  /**
63
- * @deprecated This option is a no-op and will be removed in a future major.
64
- */
64
+ * @deprecated This option is a no-op and will be removed in a future major.
65
+ */
65
66
  copyServerAssetsToClient?: (fileName: string) => boolean;
66
67
  /**
67
- * This option allows disabling action closure encryption for debugging purpose.
68
- * @default true
69
- */
68
+ * This option allows disabling action closure encryption for debugging purpose.
69
+ * @default true
70
+ */
70
71
  enableActionEncryption?: boolean;
71
72
  /**
72
- * By default, the plugin uses a build-time generated encryption key for
73
- * "use server" closure argument binding.
74
- * This can be overwritten by configuring `defineEncryptionKey` option,
75
- * for example, to obtain a key through environment variable during runtime.
76
- * cf. https://nextjs.org/docs/app/guides/data-security#overwriting-encryption-keys-advanced
77
- */
78
- defineEncryptionKey?: string; /** Escape hatch for Waku's `allowServer` */
73
+ * By default, the plugin uses a build-time generated encryption key for
74
+ * "use server" closure argument binding.
75
+ * This can be overwritten by configuring `defineEncryptionKey` option,
76
+ * for example, to obtain a key through environment variable during runtime.
77
+ * cf. https://nextjs.org/docs/app/guides/data-security#overwriting-encryption-keys-advanced
78
+ */
79
+ defineEncryptionKey?: string;
80
+ /** Escape hatch for Waku's `allowServer` */
79
81
  keepUseCientProxy?: boolean;
80
82
  /**
81
- * Enable build-time validation of 'client-only' and 'server-only' imports
82
- * @default true
83
- */
83
+ * Enable build-time validation of 'client-only' and 'server-only' imports
84
+ * @default true
85
+ */
84
86
  validateImports?: boolean;
85
87
  /**
86
- * use `Plugin.buildApp` hook (introduced on Vite 7) instead of `builder.buildApp` configuration
87
- * for better composability with other plugins.
88
- * @default true since Vite 7
89
- */
88
+ * use `Plugin.buildApp` hook (introduced on Vite 7) instead of `builder.buildApp` configuration
89
+ * for better composability with other plugins.
90
+ * @default true since Vite 7
91
+ */
90
92
  useBuildAppHook?: boolean;
91
93
  /**
92
- * Skip the default buildApp orchestration for downstream frameworks
93
- * to implement custom build pipelines using `getPluginApi()`.
94
- * @experimental
95
- * @default false
96
- */
94
+ * Skip the default buildApp orchestration for downstream frameworks
95
+ * to implement custom build pipelines using `getPluginApi()`.
96
+ * @experimental
97
+ * @default false
98
+ */
97
99
  customBuildApp?: boolean;
98
100
  /**
99
- * Custom environment configuration
100
- * @experimental
101
- * @default { browser: 'client', ssr: 'ssr', rsc: 'rsc' }
102
- */
101
+ * Custom environment configuration
102
+ * @experimental
103
+ * @default { browser: 'client', ssr: 'ssr', rsc: 'rsc' }
104
+ */
103
105
  environment?: {
104
106
  browser?: string;
105
107
  ssr?: string;
106
108
  rsc?: string;
107
109
  };
108
110
  /**
109
- * Custom chunking strategy for client reference modules.
110
- *
111
- * This function allows you to group multiple client components into
112
- * custom chunks instead of having each module in its own chunk.
113
- * By default, client chunks are grouped by `meta.serverChunk`.
114
- */
111
+ * Custom chunking strategy for client reference modules.
112
+ *
113
+ * This function allows you to group multiple client components into
114
+ * custom chunks instead of having each module in its own chunk.
115
+ * By default, client chunks are grouped by `meta.serverChunk`.
116
+ */
115
117
  clientChunks?: (meta: {
116
- /** client reference module id */id: string; /** normalized client reference module id */
117
- normalizedId: string; /** server chunk which includes a corresponding client reference proxy module */
118
+ /** client reference module id */
119
+ id: string;
120
+ /** normalized client reference module id */
121
+ normalizedId: string;
122
+ /** server chunk which includes a corresponding client reference proxy module */
118
123
  serverChunk: string;
119
124
  }) => string | undefined;
120
125
  /**
121
- * Controls whether CSS links use React's `precedence` attribute.
122
- * @experimental
123
- * @default true
124
- */
126
+ * Controls whether CSS links use React's `precedence` attribute.
127
+ * @experimental
128
+ * @default true
129
+ */
125
130
  cssLinkPrecedence?: boolean;
126
131
  /**
127
- * Opt out of the default "index" client entry convention.
128
- * When enabled, the plugin will not:
129
- * - Require an entry chunk named "index"
130
- * - Automatically include client entry deps in each client reference's dependencies
131
- *
132
- * Note: `import.meta.viteRsc.loadBootstrapScriptContent` cannot be used with this option.
133
- *
134
- * Use this when you manually handle client entry setup and preloading.
135
- *
136
- * @experimental
137
- * @default false
138
- */
132
+ * Opt out of the default "index" client entry convention.
133
+ * When enabled, the plugin will not:
134
+ * - Require an entry chunk named "index"
135
+ * - Automatically include client entry deps in each client reference's dependencies
136
+ *
137
+ * Note: `import.meta.viteRsc.loadBootstrapScriptContent` cannot be used with this option.
138
+ *
139
+ * Use this when you manually handle client entry setup and preloading.
140
+ *
141
+ * @experimental
142
+ * @default false
143
+ */
139
144
  customClientEntry?: boolean;
140
145
  };
141
146
  type PluginApi = {
@@ -155,6 +160,7 @@ declare class RuntimeAsset {
155
160
  }
156
161
  type AssetsManifest = {
157
162
  bootstrapScriptContent: string | RuntimeAsset;
163
+ clientEntryDeps?: AssetDeps;
158
164
  clientReferenceDeps: Record<string, AssetDeps>;
159
165
  serverResources?: Record<string, Pick<AssetDeps, "css">>;
160
166
  cssLinkPrecedence?: boolean;
@@ -165,6 +171,7 @@ type AssetDeps = {
165
171
  };
166
172
  type ResolvedAssetsManifest = {
167
173
  bootstrapScriptContent: string;
174
+ clientEntryDeps?: ResolvedAssetDeps;
168
175
  clientReferenceDeps: Record<string, ResolvedAssetDeps>;
169
176
  serverResources?: Record<string, Pick<ResolvedAssetDeps, "css">>;
170
177
  cssLinkPrecedence?: boolean;
package/dist/plugin.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as ResolvedAssetsManifest, c as getPluginApi, d as vitePluginRscMinimal, i as ResolvedAssetDeps, l as transformRscCssExport, n as AssetsManifest, o as RscPluginManager, r as PluginApi, s as RscPluginOptions, t as AssetDeps, u as vitePluginRsc } from "./plugin-DGxRH4Nv.js";
2
- export { AssetDeps, AssetsManifest, PluginApi, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginManager, RscPluginOptions, vitePluginRsc as default, getPluginApi, transformRscCssExport, vitePluginRscMinimal };
1
+ import { a as ResolvedAssetsManifest, c as getPluginApi, d as vitePluginRscMinimal, i as ResolvedAssetDeps, l as transformRscCssExport, n as AssetsManifest, o as RscPluginManager, r as PluginApi, s as RscPluginOptions, t as AssetDeps, u as vitePluginRsc } from "./plugin-CaLiN8ED.js";
2
+ export { AssetDeps, AssetsManifest, PluginApi, ResolvedAssetDeps, ResolvedAssetsManifest, type RscPluginManager, RscPluginOptions, vitePluginRsc as default, getPluginApi, transformRscCssExport, vitePluginRscMinimal };
package/dist/plugin.js CHANGED
@@ -1,2 +1,2 @@
1
- import { i as vitePluginRscMinimal, n as transformRscCssExport, r as vitePluginRsc, t as getPluginApi } from "./plugin-BhzHKRFo.js";
1
+ import { i as vitePluginRscMinimal, n as transformRscCssExport, r as vitePluginRsc, t as getPluginApi } from "./plugin-BOTpkess.js";
2
2
  export { vitePluginRsc as default, getPluginApi, transformRscCssExport, vitePluginRscMinimal };
@@ -1,5 +1,4 @@
1
1
  import { Plugin } from "vite";
2
-
3
2
  //#region src/plugins/cjs.d.ts
4
3
  declare function cjsModuleRunnerPlugin(): Plugin[];
5
4
  //#endregion
@@ -1,2 +1,2 @@
1
- import { t as cjsModuleRunnerPlugin } from "../cjs-BdahOUyh.js";
1
+ import { t as cjsModuleRunnerPlugin } from "../cjs-Cxg_7upE.js";
2
2
  export { cjsModuleRunnerPlugin };
@@ -1,6 +1,5 @@
1
- import { i as CreateFromReadableStreamBrowserOptions, n as CallServerCallback, r as ClientTemporaryReferenceSet, s as EncodeReplyFunction } from "../index-D2a5dlVU.js";
2
- import { t as setRequireModule } from "../browser-CUMAmYC3.js";
3
-
1
+ import { c as EncodeReplyFunction, i as CreateFromReadableStreamBrowserOptions, n as CallServerCallback, r as ClientTemporaryReferenceSet } from "../index-CqNlZcWp.js";
2
+ import { t as setRequireModule } from "../browser-DI_Wyg5Y.js";
4
3
  //#region src/react/browser.d.ts
5
4
  declare function createFromReadableStream<T>(stream: ReadableStream<Uint8Array>, options?: CreateFromReadableStreamBrowserOptions): Promise<T>;
6
5
  declare function createFromFetch<T>(promiseForResponse: Promise<Response>, options?: CreateFromReadableStreamBrowserOptions): Promise<T>;
@@ -0,0 +1,2 @@
1
+ import { n as createFromReadableStream, r as encodeReply, t as createClientTemporaryReferenceSet } from "../../client-BrwlzXgg.js";
2
+ export { createClientTemporaryReferenceSet, createFromReadableStream, encodeReply };
@@ -0,0 +1,16 @@
1
+ import { createServerDecodeClientManifest, createServerManifest } from "../../core/rsc.js";
2
+ import * as ReactClient from "@vitejs/plugin-rsc/vendor/react-server-dom/client.edge";
3
+ //#region src/react/rsc/client.ts
4
+ function createFromReadableStream(stream, options = {}, extraOptions) {
5
+ return ReactClient.createFromReadableStream(stream, {
6
+ serverConsumerManifest: {
7
+ serverModuleMap: createServerManifest({ preserveServerReferences: extraOptions?.preserveServerReferences }),
8
+ moduleMap: createServerDecodeClientManifest()
9
+ },
10
+ ...options
11
+ });
12
+ }
13
+ const encodeReply = ReactClient.encodeReply;
14
+ const createClientTemporaryReferenceSet = ReactClient.createTemporaryReferenceSet;
15
+ //#endregion
16
+ export { createClientTemporaryReferenceSet, createFromReadableStream, encodeReply };
@@ -0,0 +1,3 @@
1
+ import { a as setRequireModule, i as loadServerAction } from "../../rsc-CGkkhLG3.js";
2
+ import { a as registerClientReference, i as decodeReply, n as decodeAction, o as registerServerReference, r as decodeFormState, s as renderToReadableStream, t as createTemporaryReferenceSet } from "../../server-DTkvSyJT.js";
3
+ export { createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, loadServerAction, registerClientReference, registerServerReference, renderToReadableStream, setRequireModule };
@@ -0,0 +1,20 @@
1
+ import { createClientManifest, createServerManifest, loadServerAction, setRequireModule } from "../../core/rsc.js";
2
+ import * as ReactServer from "@vitejs/plugin-rsc/vendor/react-server-dom/server.edge";
3
+ //#region src/react/rsc/server.ts
4
+ function renderToReadableStream(data, options, extraOptions) {
5
+ return ReactServer.renderToReadableStream(data, createClientManifest({ onClientReference: extraOptions?.onClientReference }), options);
6
+ }
7
+ function registerClientReference(proxy, id, name) {
8
+ return ReactServer.registerClientReference(proxy, id, name);
9
+ }
10
+ const registerServerReference = ReactServer.registerServerReference;
11
+ const decodeReply = (body, options) => ReactServer.decodeReply(body, createServerManifest(), options);
12
+ function decodeAction(body) {
13
+ return ReactServer.decodeAction(body, createServerManifest());
14
+ }
15
+ function decodeFormState(actionResult, body) {
16
+ return ReactServer.decodeFormState(actionResult, body, createServerManifest());
17
+ }
18
+ const createTemporaryReferenceSet = ReactServer.createTemporaryReferenceSet;
19
+ //#endregion
20
+ export { createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, loadServerAction, registerClientReference, registerServerReference, renderToReadableStream, setRequireModule };
@@ -1,25 +1,4 @@
1
- import { a as CreateFromReadableStreamEdgeOptions, d as ServerTemporaryReferenceSet, l as RenderToReadableStreamOptions, o as DecodeReplyFunction, r as ClientTemporaryReferenceSet, s as EncodeReplyFunction } from "../index-D2a5dlVU.js";
2
- import { loadServerAction, setRequireModule } from "../core/rsc.js";
3
- import { ReactFormState } from "react-dom/client";
4
-
5
- //#region src/react/rsc.d.ts
6
- declare function renderToReadableStream<T>(data: T, options?: RenderToReadableStreamOptions, extraOptions?: {
7
- /**
8
- * @internal
9
- */
10
- onClientReference?: (metadata: {
11
- id: string;
12
- name: string;
13
- }) => void;
14
- }): ReadableStream<Uint8Array>;
15
- declare function createFromReadableStream<T>(stream: ReadableStream<Uint8Array>, options?: CreateFromReadableStreamEdgeOptions): Promise<T>;
16
- declare function registerClientReference<T>(proxy: T, id: string, name: string): T;
17
- declare const registerServerReference: <T>(ref: T, id: string, name: string) => T;
18
- declare const decodeReply: DecodeReplyFunction;
19
- declare function decodeAction(body: FormData): Promise<() => Promise<void>>;
20
- declare function decodeFormState(actionResult: unknown, body: FormData): Promise<ReactFormState | undefined>;
21
- declare const createTemporaryReferenceSet: () => ServerTemporaryReferenceSet;
22
- declare const encodeReply: EncodeReplyFunction;
23
- declare const createClientTemporaryReferenceSet: () => ClientTemporaryReferenceSet;
24
- //#endregion
1
+ import { a as setRequireModule, i as loadServerAction } from "../rsc-CGkkhLG3.js";
2
+ import { a as registerClientReference, i as decodeReply, n as decodeAction, o as registerServerReference, r as decodeFormState, s as renderToReadableStream, t as createTemporaryReferenceSet } from "../server-DTkvSyJT.js";
3
+ import { n as createFromReadableStream, r as encodeReply, t as createClientTemporaryReferenceSet } from "../client-BrwlzXgg.js";
25
4
  export { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, loadServerAction, registerClientReference, registerServerReference, renderToReadableStream, setRequireModule };
package/dist/react/rsc.js CHANGED
@@ -1,32 +1,4 @@
1
- import { createClientManifest, createServerDecodeClientManifest, createServerManifest, loadServerAction, setRequireModule } from "../core/rsc.js";
2
- import * as ReactClient from "@vitejs/plugin-rsc/vendor/react-server-dom/client.edge";
3
- import * as ReactServer from "@vitejs/plugin-rsc/vendor/react-server-dom/server.edge";
4
- //#region src/react/rsc.ts
5
- function renderToReadableStream(data, options, extraOptions) {
6
- return ReactServer.renderToReadableStream(data, createClientManifest({ onClientReference: extraOptions?.onClientReference }), options);
7
- }
8
- function createFromReadableStream(stream, options = {}) {
9
- return ReactClient.createFromReadableStream(stream, {
10
- serverConsumerManifest: {
11
- serverModuleMap: createServerManifest(),
12
- moduleMap: createServerDecodeClientManifest()
13
- },
14
- ...options
15
- });
16
- }
17
- function registerClientReference(proxy, id, name) {
18
- return ReactServer.registerClientReference(proxy, id, name);
19
- }
20
- const registerServerReference = ReactServer.registerServerReference;
21
- const decodeReply = (body, options) => ReactServer.decodeReply(body, createServerManifest(), options);
22
- function decodeAction(body) {
23
- return ReactServer.decodeAction(body, createServerManifest());
24
- }
25
- function decodeFormState(actionResult, body) {
26
- return ReactServer.decodeFormState(actionResult, body, createServerManifest());
27
- }
28
- const createTemporaryReferenceSet = ReactServer.createTemporaryReferenceSet;
29
- const encodeReply = ReactClient.encodeReply;
30
- const createClientTemporaryReferenceSet = ReactClient.createTemporaryReferenceSet;
31
- //#endregion
1
+ import { loadServerAction, setRequireModule } from "../core/rsc.js";
2
+ import { createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, registerClientReference, registerServerReference, renderToReadableStream } from "./rsc/server.js";
3
+ import { createClientTemporaryReferenceSet, createFromReadableStream, encodeReply } from "./rsc/client.js";
32
4
  export { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, loadServerAction, registerClientReference, registerServerReference, renderToReadableStream, setRequireModule };
@@ -1,10 +1,11 @@
1
- import { a as CreateFromReadableStreamEdgeOptions } from "../index-D2a5dlVU.js";
1
+ import { a as CreateFromReadableStreamEdgeOptions, c as EncodeReplyFunction, r as ClientTemporaryReferenceSet, s as EncodeFormActionCallback } from "../index-CqNlZcWp.js";
2
2
  import { setRequireModule } from "../core/ssr.js";
3
-
4
3
  //#region src/react/ssr.d.ts
5
4
  declare function createFromReadableStream<T>(stream: ReadableStream<Uint8Array>, options?: CreateFromReadableStreamEdgeOptions): Promise<T>;
6
5
  declare function createServerReference(id: string): unknown;
6
+ declare const encodeReply: EncodeReplyFunction;
7
+ declare const createTemporaryReferenceSet: () => ClientTemporaryReferenceSet;
7
8
  declare const callServer: null;
8
9
  declare const findSourceMapURL: null;
9
10
  //#endregion
10
- export { callServer, createFromReadableStream, createServerReference, findSourceMapURL, setRequireModule };
11
+ export { type EncodeFormActionCallback, callServer, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setRequireModule };
package/dist/react/ssr.js CHANGED
@@ -10,7 +10,9 @@ function createFromReadableStream(stream, options = {}) {
10
10
  function createServerReference(id) {
11
11
  return ReactClient.createServerReference(id);
12
12
  }
13
+ const encodeReply = ReactClient.encodeReply;
14
+ const createTemporaryReferenceSet = ReactClient.createTemporaryReferenceSet;
13
15
  const callServer = null;
14
16
  const findSourceMapURL = null;
15
17
  //#endregion
16
- export { callServer, createFromReadableStream, createServerReference, findSourceMapURL, setRequireModule };
18
+ export { callServer, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setRequireModule };
@@ -0,0 +1,2 @@
1
+ import { n as createFromReadableStream, r as encodeReply, t as createClientTemporaryReferenceSet } from "../client-BrwlzXgg.js";
2
+ export { createClientTemporaryReferenceSet, createFromReadableStream, encodeReply };
@@ -0,0 +1,3 @@
1
+ import "../shared-D42sHPD1.js";
2
+ import { createClientTemporaryReferenceSet, createFromReadableStream, encodeReply } from "../react/rsc/client.js";
3
+ export { createClientTemporaryReferenceSet, createFromReadableStream, encodeReply };
@@ -0,0 +1,16 @@
1
+ import { a as setRequireModule, i as loadServerAction, r as createServerManifest, t as createClientManifest } from "../rsc-CGkkhLG3.js";
2
+ import { i as ResolvedAssetDeps } from "../plugin-CaLiN8ED.js";
3
+ import { a as registerClientReference, i as decodeReply, n as decodeAction, o as registerServerReference, r as decodeFormState, t as createTemporaryReferenceSet } from "../server-DTkvSyJT.js";
4
+ //#region src/rsc/server.d.ts
5
+ declare function renderToReadableStream<T>(data: T, options?: object, extraOptions?: {
6
+ /**
7
+ * @experimental
8
+ */
9
+ onClientReference?: (metadata: {
10
+ id: string;
11
+ name: string;
12
+ deps: ResolvedAssetDeps;
13
+ }) => void;
14
+ }): ReadableStream<Uint8Array>;
15
+ //#endregion
16
+ export { createClientManifest, createServerManifest, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, loadServerAction, registerClientReference, registerServerReference, renderToReadableStream, setRequireModule };