@vitejs/plugin-rsc 0.4.19 → 0.4.20

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.
@@ -18,4 +18,5 @@ function withTrailingSlash(path) {
18
18
  return path;
19
19
  }
20
20
 
21
- //#endregion
21
+ //#endregion
22
+ export { };
package/dist/browser.js CHANGED
@@ -2,6 +2,6 @@ import "./dist-DiJnRA1C.js";
2
2
  import "./shared-CEyKoKAb.js";
3
3
  import { setRequireModule } from "./browser-BhJd-Orx.js";
4
4
  import { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setServerCallback } from "./browser-D8OPzpF5.js";
5
- import "./browser-DIa4fISB.js";
5
+ import "./browser-QU10IP0-.js";
6
6
 
7
7
  export { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setRequireModule, setServerCallback };
@@ -2,7 +2,7 @@ import "../dist-DiJnRA1C.js";
2
2
  import "../shared-CEyKoKAb.js";
3
3
  import "../browser-BhJd-Orx.js";
4
4
  import { createFromFetch, createFromReadableStream, createTemporaryReferenceSet, encodeReply, setServerCallback } from "../browser-D8OPzpF5.js";
5
- import "../browser-DIa4fISB.js";
5
+ import "../browser-QU10IP0-.js";
6
6
  import { rscStream } from "../client-C1J4FCf5.js";
7
7
  import React from "react";
8
8
  import ReactDomClient from "react-dom/client";
package/dist/extra/rsc.js CHANGED
@@ -4,7 +4,7 @@ import "../encryption-utils-BDwwcMVT.js";
4
4
  import { loadServerAction } from "../rsc-BfBPoIV8.js";
5
5
  import { createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, renderToReadableStream } from "../rsc-VjVw_i-M.js";
6
6
  import "../encryption-runtime-CJUalqt3.js";
7
- import "../rsc-CGUEQCnf.js";
7
+ import "../rsc-BwEwbLG4.js";
8
8
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
9
 
10
10
  //#region src/extra/rsc.tsx
package/dist/extra/ssr.js CHANGED
@@ -2,7 +2,7 @@ import "../dist-DiJnRA1C.js";
2
2
  import "../shared-CEyKoKAb.js";
3
3
  import "../ssr--rFiBtws.js";
4
4
  import { createFromReadableStream } from "../ssr-BEKKb_cw.js";
5
- import "../ssr-BuzPa0Go.js";
5
+ import "../ssr-BMTRhW5g.js";
6
6
  import { injectRSCPayload } from "../server-D0-DavPP.js";
7
7
  import React from "react";
8
8
  import { jsx } from "react/jsx-runtime";
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { RscPluginOptions, vitePluginRsc } from "./plugin-CYYsF3qY.js";
1
+ import { RscPluginOptions, vitePluginRsc } from "./plugin-BQszG7oj.js";
2
2
  import MagicString from "magic-string";
3
3
  import { Program } from "estree";
4
4
 
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import "./dist-DiJnRA1C.js";
2
2
  import "./plugin-CZbI4rhS.js";
3
- import { transformHoistInlineDirective, vitePluginRsc } from "./plugin-Cu7_zbmH.js";
3
+ import { transformHoistInlineDirective, vitePluginRsc } from "./plugin-DYOxE_xg.js";
4
4
  import "./encryption-utils-BDwwcMVT.js";
5
5
  import "./rpc-tGuLT8PD.js";
6
6
  import "./vite-utils-Vzd7cqfv.js";
@@ -28,6 +28,7 @@ type RscPluginOptions = {
28
28
  rscCssTransform?: false | {
29
29
  filter?: (id: string) => boolean;
30
30
  };
31
+ /** @deprecated use "DEBUG=vite-env:*" to see warnings. */
31
32
  ignoredPackageWarnings?: (string | RegExp)[];
32
33
  /**
33
34
  * This option allows customizing how client build copies assets from server build.
@@ -328,7 +328,8 @@ function parseIdQuery(id) {
328
328
  function transformCjsToEsm(code, ast) {
329
329
  const output = new MagicString(code);
330
330
  const analyzed = analyze(ast);
331
- let parentNodes = [];
331
+ const parentNodes = [];
332
+ const hoistedCodes = [];
332
333
  let hoistIndex = 0;
333
334
  walk(ast, {
334
335
  enter(node) {
@@ -346,7 +347,7 @@ function transformCjsToEsm(code, ast) {
346
347
  } else {
347
348
  const hoisted = `__cjs_to_esm_hoist_${hoistIndex}`;
348
349
  const importee = code.slice(node.arguments[0].start, node.arguments[0].end);
349
- output.prepend(`const ${hoisted} = await import(${importee});\n`);
350
+ hoistedCodes.push(`const ${hoisted} = await import(${importee});\n`);
350
351
  output.update(node.start, node.end, hoisted);
351
352
  hoistIndex++;
352
353
  }
@@ -356,6 +357,7 @@ function transformCjsToEsm(code, ast) {
356
357
  parentNodes.pop();
357
358
  }
358
359
  });
360
+ for (const hoisted of hoistedCodes.reverse()) output.prepend(hoisted);
359
361
  output.prepend(`const exports = {}; const module = { exports };\n`);
360
362
  return { output };
361
363
  }
@@ -971,6 +973,13 @@ function vitePluginUseClient(useClientPluginOptions) {
971
973
  const bareImportRE = /^(?![a-zA-Z]:)[\w@](?!.*:\/\/)/;
972
974
  const serverEnvironmentName = useClientPluginOptions.environment?.rsc ?? "rsc";
973
975
  const browserEnvironmentName = useClientPluginOptions.environment?.browser ?? "client";
976
+ function warnInoncistentClientOptimization(ctx, id) {
977
+ const { depsOptimizer } = server.environments.client;
978
+ if (depsOptimizer) {
979
+ for (const dep of Object.values(depsOptimizer.metadata.optimized)) if (dep.src === id) ctx.warn("client component dependency is inconsistently optimized. It's recommended to add the dependency to 'optimizeDeps.exclude'.");
980
+ }
981
+ }
982
+ const debug$1 = createDebug("vite-rsc:use-client");
974
983
  return [
975
984
  {
976
985
  name: "rsc:use-client",
@@ -983,9 +992,10 @@ function vitePluginUseClient(useClientPluginOptions) {
983
992
  let referenceKey;
984
993
  const packageSource = packageSources.get(id);
985
994
  if (!packageSource && this.environment.mode === "dev" && id.includes("/node_modules/")) {
986
- const ignored = useClientPluginOptions.ignoredPackageWarnings?.some((pattern) => pattern instanceof RegExp ? pattern.test(id) : id.includes(`/node_modules/${pattern}/`));
987
- if (!ignored) this.warn(`[vite-rsc] detected an internal client boundary created by a package imported on rsc environment`);
988
- importId = `/@id/__x00__virtual:vite-rsc/client-in-server-package-proxy/${encodeURIComponent(cleanUrl(id))}`;
995
+ debug$1(`internal client reference created through a package imported in '${this.environment.name}' environment: ${id}`);
996
+ id = cleanUrl(id);
997
+ warnInoncistentClientOptimization(this, id);
998
+ importId = `/@id/__x00__virtual:vite-rsc/client-in-server-package-proxy/${encodeURIComponent(id)}`;
989
999
  referenceKey = importId;
990
1000
  } else if (packageSource) if (this.environment.mode === "dev") {
991
1001
  importId = `/@id/__x00__virtual:vite-rsc/client-package-proxy/${packageSource}`;
@@ -1141,6 +1151,7 @@ function vitePluginDefineEncryptionKey(useServerPluginOptions) {
1141
1151
  function vitePluginUseServer(useServerPluginOptions) {
1142
1152
  const serverEnvironmentName = useServerPluginOptions.environment?.rsc ?? "rsc";
1143
1153
  const browserEnvironmentName = useServerPluginOptions.environment?.browser ?? "client";
1154
+ const debug$1 = createDebug("vite-rsc:use-server");
1144
1155
  return [{
1145
1156
  name: "rsc:use-server",
1146
1157
  async transform(code, id) {
@@ -1150,8 +1161,7 @@ function vitePluginUseServer(useServerPluginOptions) {
1150
1161
  const getNormalizedId = () => {
1151
1162
  if (!normalizedId_) {
1152
1163
  if (this.environment.mode === "dev" && id.includes("/node_modules/")) {
1153
- const ignored = useServerPluginOptions.ignoredPackageWarnings?.some((pattern) => pattern instanceof RegExp ? pattern.test(id) : id.includes(`/node_modules/${pattern}/`));
1154
- if (!ignored) this.warn(`[vite-rsc] detected an internal server function created by a package imported on ${this.environment.name} environment`);
1164
+ debug$1(`internal server reference created through a package imported in ${this.environment.name} environment: ${id}`);
1155
1165
  id = cleanUrl(id);
1156
1166
  }
1157
1167
  if (config.command === "build") normalizedId_ = hashString(path.relative(config.root, id));
@@ -1551,7 +1561,25 @@ function vitePluginRscCss(rscCssOptions) {
1551
1561
  }
1552
1562
  }
1553
1563
  }
1554
- }
1564
+ },
1565
+ createVirtualPlugin("vite-rsc/remove-duplicate-server-css", async function() {
1566
+ assert.equal(this.environment.mode, "dev");
1567
+ function removeFn() {
1568
+ document.querySelectorAll("link[rel='stylesheet']").forEach((node) => {
1569
+ if (node instanceof HTMLElement && node.dataset.precedence?.startsWith("vite-rsc/")) node.remove();
1570
+ });
1571
+ }
1572
+ return `\
1573
+ "use client"
1574
+ import React from "react";
1575
+ export default function RemoveDuplicateServerCss() {
1576
+ React.useEffect(() => {
1577
+ (${removeFn.toString()})();
1578
+ }, []);
1579
+ return null;
1580
+ }
1581
+ `;
1582
+ })
1555
1583
  ];
1556
1584
  }
1557
1585
  function invalidteModuleById(environment, id) {
@@ -1570,25 +1598,36 @@ function collectModuleDependents(mods) {
1570
1598
  return [...visited];
1571
1599
  }
1572
1600
  function generateResourcesCode(depsCode) {
1573
- const ResourcesFn = (React, deps) => {
1601
+ const ResourcesFn = (React, deps, RemoveDuplicateServerCss) => {
1574
1602
  return function Resources() {
1575
- return React.createElement(React.Fragment, null, [...deps.css.map((href) => React.createElement("link", {
1576
- key: "css:" + href,
1577
- rel: "stylesheet",
1578
- precedence: "vite-rsc/importer-resources",
1579
- href
1580
- })), ...deps.js.map((href) => React.createElement("script", {
1581
- key: "js:" + href,
1582
- type: "module",
1583
- async: true,
1584
- src: href
1585
- }))]);
1603
+ return React.createElement(React.Fragment, null, [
1604
+ ...deps.css.map((href) => React.createElement("link", {
1605
+ key: "css:" + href,
1606
+ rel: "stylesheet",
1607
+ precedence: "vite-rsc/importer-resources",
1608
+ href
1609
+ })),
1610
+ ...deps.js.map((href) => React.createElement("script", {
1611
+ key: "js:" + href,
1612
+ type: "module",
1613
+ async: true,
1614
+ src: href
1615
+ })),
1616
+ RemoveDuplicateServerCss && React.createElement(RemoveDuplicateServerCss, { key: "remove-duplicate-css" })
1617
+ ]);
1586
1618
  };
1587
1619
  };
1588
1620
  return `
1589
- import __vite_rsc_react__ from "react";
1590
- export const Resources = (${ResourcesFn.toString()})(__vite_rsc_react__, ${depsCode});
1591
- `;
1621
+ import __vite_rsc_react__ from "react";
1622
+
1623
+ ${config.command === "serve" ? `import RemoveDuplicateServerCss from "virtual:vite-rsc/remove-duplicate-server-css";` : `const RemoveDuplicateServerCss = undefined;`}
1624
+
1625
+ export const Resources = (${ResourcesFn.toString()})(
1626
+ __vite_rsc_react__,
1627
+ ${depsCode},
1628
+ RemoveDuplicateServerCss,
1629
+ );
1630
+ `;
1592
1631
  }
1593
1632
  async function transformRscCssExport(options) {
1594
1633
  if (hasDirective(options.ast.body, "use client")) return;
package/dist/plugin.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { AssetDeps, AssetsManifest, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginOptions, __fix_cloudflare, findSourceMapURL, transformRscCssExport, vitePluginFindSourceMapURL, vitePluginRsc, vitePluginRscCss, vitePluginRscMinimal } from "./plugin-CYYsF3qY.js";
1
+ import { AssetDeps, AssetsManifest, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginOptions, __fix_cloudflare, findSourceMapURL, transformRscCssExport, vitePluginFindSourceMapURL, vitePluginRsc, vitePluginRscCss, vitePluginRscMinimal } from "./plugin-BQszG7oj.js";
2
2
  export { AssetDeps, AssetsManifest, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginOptions, __fix_cloudflare, vitePluginRsc as default, findSourceMapURL, transformRscCssExport, vitePluginFindSourceMapURL, vitePluginRscCss, vitePluginRscMinimal };
package/dist/plugin.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import "./dist-DiJnRA1C.js";
2
2
  import "./plugin-CZbI4rhS.js";
3
- import { __fix_cloudflare, findSourceMapURL, transformRscCssExport, vitePluginFindSourceMapURL, vitePluginRsc, vitePluginRscCss, vitePluginRscMinimal } from "./plugin-Cu7_zbmH.js";
3
+ import { __fix_cloudflare, findSourceMapURL, transformRscCssExport, vitePluginFindSourceMapURL, vitePluginRsc, vitePluginRscCss, vitePluginRscMinimal } from "./plugin-DYOxE_xg.js";
4
4
  import "./encryption-utils-BDwwcMVT.js";
5
5
  import "./rpc-tGuLT8PD.js";
6
6
  import "./vite-utils-Vzd7cqfv.js";
@@ -17,4 +17,5 @@ function initialize() {
17
17
  } });
18
18
  }
19
19
 
20
- //#endregion
20
+ //#endregion
21
+ export { };
package/dist/rsc.js CHANGED
@@ -4,6 +4,6 @@ import "./encryption-utils-BDwwcMVT.js";
4
4
  import { createClientManifest, createServerManifest, loadServerAction, setRequireModule } from "./rsc-BfBPoIV8.js";
5
5
  import { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, registerClientReference, registerServerReference, renderToReadableStream } from "./rsc-VjVw_i-M.js";
6
6
  import { decryptActionBoundArgs, encryptActionBoundArgs } from "./encryption-runtime-CJUalqt3.js";
7
- import "./rsc-CGUEQCnf.js";
7
+ import "./rsc-BwEwbLG4.js";
8
8
 
9
9
  export { createClientManifest, createClientTemporaryReferenceSet, createFromReadableStream, createServerManifest, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, decryptActionBoundArgs, encodeReply, encryptActionBoundArgs, loadServerAction, registerClientReference, registerServerReference, renderToReadableStream, setRequireModule };
@@ -49,4 +49,5 @@ function preloadDeps(deps) {
49
49
  });
50
50
  }
51
51
 
52
- //#endregion
52
+ //#endregion
53
+ export { };
package/dist/ssr.js CHANGED
@@ -2,6 +2,6 @@ import "./dist-DiJnRA1C.js";
2
2
  import "./shared-CEyKoKAb.js";
3
3
  import { createServerConsumerManifest, setRequireModule } from "./ssr--rFiBtws.js";
4
4
  import { callServer, createFromReadableStream, createServerReference, findSourceMapURL } from "./ssr-BEKKb_cw.js";
5
- import "./ssr-BuzPa0Go.js";
5
+ import "./ssr-BMTRhW5g.js";
6
6
 
7
7
  export { callServer, createFromReadableStream, createServerConsumerManifest, createServerReference, findSourceMapURL, setRequireModule };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitejs/plugin-rsc",
3
- "version": "0.4.19",
3
+ "version": "0.4.20",
4
4
  "description": "React Server Components (RSC) support for Vite.",
5
5
  "keywords": [
6
6
  "vite",