@vitejs/plugin-rsc 0.4.24 → 0.4.26
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
|
@@ -477,6 +477,37 @@ export function Page() {
|
|
|
477
477
|
|
|
478
478
|
See https://github.com/vitejs/vite-plugin-react/pull/524 for how to install the package for React [canary](https://react.dev/community/versioning-policy#canary-channel) and [experimental](https://react.dev/community/versioning-policy#all-release-channels) usages.
|
|
479
479
|
|
|
480
|
+
## Using `@vitejs/plugin-rsc` as a framework package's `dependencies`
|
|
481
|
+
|
|
482
|
+
By default, `@vitejs/plugin-rsc` is expected to be used as `peerDependencies` similar to `react` and `react-dom`. When `@vitejs/plugin-rsc` is not available at the project root (e.g., in `node_modules/@vitejs/plugin-rsc`), you will see warnings like:
|
|
483
|
+
|
|
484
|
+
```sh
|
|
485
|
+
Failed to resolve dependency: @vitejs/plugin-rsc/vendor/react-server-dom/client.browser, present in client 'optimizeDeps.include'
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
This can be fixed by updating `optimizeDeps.include` to reference `@vitejs/plugin-rsc` through your framework package. For example, you can add the following plugin:
|
|
489
|
+
|
|
490
|
+
```js
|
|
491
|
+
// package name is "my-rsc-framework"
|
|
492
|
+
export default function myRscFrameworkPlugin() {
|
|
493
|
+
return {
|
|
494
|
+
name: 'my-rsc-framework:config',
|
|
495
|
+
configEnvironment(_name, config) {
|
|
496
|
+
if (config.optimizeDeps?.include) {
|
|
497
|
+
config.optimizeDeps.include = config.optimizeDeps.include.map(
|
|
498
|
+
(entry) => {
|
|
499
|
+
if (entry.startsWith('@vitejs/plugin-rsc')) {
|
|
500
|
+
entry = `my-rsc-framework > ${entry}`
|
|
501
|
+
}
|
|
502
|
+
return entry
|
|
503
|
+
},
|
|
504
|
+
)
|
|
505
|
+
}
|
|
506
|
+
},
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
```
|
|
510
|
+
|
|
480
511
|
## Credits
|
|
481
512
|
|
|
482
513
|
This project builds on fundamental techniques and insights from pioneering Vite RSC implementations.
|
package/dist/index.d.ts
CHANGED
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-
|
|
3
|
+
import { transformHoistInlineDirective, vitePluginRsc } from "./plugin-uOrnsu6L.js";
|
|
4
4
|
import "./encryption-utils-BDwwcMVT.js";
|
|
5
5
|
import "./rpc-tGuLT8PD.js";
|
|
6
6
|
import "./shared-BWHxNw3Q.js";
|
|
@@ -106,10 +106,13 @@ type RscPluginOptions = {
|
|
|
106
106
|
*
|
|
107
107
|
* This function allows you to group multiple client components into
|
|
108
108
|
* custom chunks instead of having each module in its own chunk.
|
|
109
|
+
* By default, client chunks are grouped by `meta.serverChunk`.
|
|
109
110
|
*/
|
|
110
111
|
clientChunks?: (meta: {
|
|
111
112
|
/** client reference module id */
|
|
112
113
|
id: string;
|
|
114
|
+
/** normalized client reference module id */
|
|
115
|
+
normalizedId: string;
|
|
113
116
|
/** server chunk which includes a corresponding client reference proxy module */
|
|
114
117
|
serverChunk: string;
|
|
115
118
|
}) => string | undefined;
|
|
@@ -148,4 +151,4 @@ declare function transformRscCssExport(options: {
|
|
|
148
151
|
output: MagicString;
|
|
149
152
|
} | undefined>;
|
|
150
153
|
//#endregion
|
|
151
|
-
export { AssetDeps, AssetsManifest, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginOptions, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal };
|
|
154
|
+
export { AssetDeps, AssetsManifest, ResolvedAssetDeps, ResolvedAssetsManifest, type RscPluginManager, RscPluginOptions, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal };
|
|
@@ -519,6 +519,21 @@ function hashString(v) {
|
|
|
519
519
|
|
|
520
520
|
//#endregion
|
|
521
521
|
//#region src/plugins/scan.ts
|
|
522
|
+
function scanBuildStripPlugin({ manager }) {
|
|
523
|
+
return {
|
|
524
|
+
name: "rsc:scan-strip",
|
|
525
|
+
apply: "build",
|
|
526
|
+
enforce: "post",
|
|
527
|
+
async transform(code, _id, _options) {
|
|
528
|
+
if (!manager.isScanBuild) return;
|
|
529
|
+
const output = await transformScanBuildStrip(code);
|
|
530
|
+
return {
|
|
531
|
+
code: output,
|
|
532
|
+
map: { mappings: "" }
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
}
|
|
522
537
|
const importGlobRE = /\bimport\.meta\.glob(?:<\w+>)?\s*\(/g;
|
|
523
538
|
async function transformScanBuildStrip(code) {
|
|
524
539
|
const [imports] = esModuleLexer.parse(code);
|
|
@@ -632,6 +647,7 @@ async function findSourceMapURL(server, filename, environmentName) {
|
|
|
632
647
|
|
|
633
648
|
//#endregion
|
|
634
649
|
//#region src/plugin.ts
|
|
650
|
+
const isRolldownVite = "rolldownVersion" in vite;
|
|
635
651
|
const BUILD_ASSETS_MANIFEST_NAME = "__vite_rsc_assets_manifest.js";
|
|
636
652
|
const PKG_NAME = "@vitejs/plugin-rsc";
|
|
637
653
|
const REACT_SERVER_DOM_NAME = `${PKG_NAME}/vendor/react-server-dom`;
|
|
@@ -777,6 +793,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
777
793
|
"react/jsx-runtime",
|
|
778
794
|
"react/jsx-dev-runtime",
|
|
779
795
|
"react-dom/server.edge",
|
|
796
|
+
"react-dom/static.edge",
|
|
780
797
|
`${REACT_SERVER_DOM_NAME}/client.edge`
|
|
781
798
|
],
|
|
782
799
|
exclude: [PKG_NAME]
|
|
@@ -815,6 +832,20 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
815
832
|
buildApp: rscPluginOptions.useBuildAppHook ? buildApp : void 0,
|
|
816
833
|
configureServer(server) {
|
|
817
834
|
globalThis.__viteRscDevServer = server;
|
|
835
|
+
const oldSend = server.environments.client.hot.send;
|
|
836
|
+
server.environments.client.hot.send = async function(...args) {
|
|
837
|
+
const e = args[0];
|
|
838
|
+
if (e && typeof e === "object" && e.type === "update") {
|
|
839
|
+
for (const update of e.updates) if (update.type === "js-update") {
|
|
840
|
+
const mod = server.environments.client.moduleGraph.urlToModuleMap.get(update.path);
|
|
841
|
+
if (mod && mod.id && manager.clientReferenceMetaMap[mod.id]) {
|
|
842
|
+
const serverMod = server.environments.rsc.moduleGraph.getModuleById(mod.id);
|
|
843
|
+
if (serverMod) server.environments.rsc.moduleGraph.invalidateModule(serverMod);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
return oldSend.apply(this, args);
|
|
848
|
+
};
|
|
818
849
|
if (rscPluginOptions.disableServerHandler) return;
|
|
819
850
|
if (rscPluginOptions.serverHandler === false) return;
|
|
820
851
|
const options = rscPluginOptions.serverHandler ?? {
|
|
@@ -829,6 +860,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
829
860
|
const resolved = await environment.pluginContainer.resolveId(source);
|
|
830
861
|
assert(resolved, `[vite-rsc] failed to resolve server handler '${source}'`);
|
|
831
862
|
const mod = await environment.runner.import(resolved.id);
|
|
863
|
+
req.url = req.originalUrl ?? req.url;
|
|
832
864
|
await createRequestListener(mod.default)(req, res);
|
|
833
865
|
} catch (e) {
|
|
834
866
|
next(e);
|
|
@@ -857,6 +889,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
857
889
|
return () => {
|
|
858
890
|
server.middlewares.use(async (req, res, next) => {
|
|
859
891
|
try {
|
|
892
|
+
req.url = req.originalUrl ?? req.url;
|
|
860
893
|
await handler(req, res);
|
|
861
894
|
} catch (e) {
|
|
862
895
|
next(e);
|
|
@@ -1148,42 +1181,22 @@ import.meta.hot.on("rsc:update", () => {
|
|
|
1148
1181
|
`;
|
|
1149
1182
|
return code;
|
|
1150
1183
|
}),
|
|
1151
|
-
{
|
|
1152
|
-
name: "rsc:inject-async-local-storage",
|
|
1153
|
-
async configureServer() {
|
|
1154
|
-
const __viteRscAyncHooks = await import("node:async_hooks");
|
|
1155
|
-
globalThis.AsyncLocalStorage = __viteRscAyncHooks.AsyncLocalStorage;
|
|
1156
|
-
},
|
|
1157
|
-
banner(chunk) {
|
|
1158
|
-
if ((this.environment.name === "ssr" || this.environment.name === "rsc") && this.environment.mode === "build" && chunk.isEntry) return `\
|
|
1159
|
-
import * as __viteRscAyncHooks from "node:async_hooks";
|
|
1160
|
-
globalThis.AsyncLocalStorage = __viteRscAyncHooks.AsyncLocalStorage;
|
|
1161
|
-
`;
|
|
1162
|
-
return "";
|
|
1163
|
-
}
|
|
1164
|
-
},
|
|
1165
1184
|
...vitePluginRscMinimal(rscPluginOptions, manager),
|
|
1166
1185
|
...vitePluginFindSourceMapURL(),
|
|
1167
1186
|
...vitePluginRscCss(rscPluginOptions, manager),
|
|
1168
1187
|
...rscPluginOptions.validateImports !== false ? [validateImportPlugin()] : [],
|
|
1169
1188
|
scanBuildStripPlugin({ manager }),
|
|
1170
|
-
...cjsModuleRunnerPlugin()
|
|
1189
|
+
...cjsModuleRunnerPlugin(),
|
|
1190
|
+
...globalAsyncLocalStoragePlugin()
|
|
1171
1191
|
];
|
|
1172
1192
|
}
|
|
1173
|
-
function
|
|
1174
|
-
return {
|
|
1175
|
-
name: "rsc:
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
const output = await transformScanBuildStrip(code);
|
|
1181
|
-
return {
|
|
1182
|
-
code: output,
|
|
1183
|
-
map: { mappings: "" }
|
|
1184
|
-
};
|
|
1185
|
-
}
|
|
1186
|
-
};
|
|
1193
|
+
function globalAsyncLocalStoragePlugin() {
|
|
1194
|
+
return [{
|
|
1195
|
+
name: "rsc:inject-async-local-storage",
|
|
1196
|
+
transform: { handler(code) {
|
|
1197
|
+
if ((this.environment.name === "ssr" || this.environment.name === "rsc") && code.includes("typeof AsyncLocalStorage") && code.includes("new AsyncLocalStorage()") && !code.includes("__viteRscAsyncHooks")) return (this.environment.mode === "build" && !isRolldownVite ? `const __viteRscAsyncHooks = require("node:async_hooks");` : `import * as __viteRscAsyncHooks from "node:async_hooks";`) + `globalThis.AsyncLocalStorage = __viteRscAsyncHooks.AsyncLocalStorage;` + code;
|
|
1198
|
+
} }
|
|
1199
|
+
}];
|
|
1187
1200
|
}
|
|
1188
1201
|
function vitePluginUseClient(useClientPluginOptions, manager) {
|
|
1189
1202
|
const packageSources = /* @__PURE__ */ new Map();
|
|
@@ -1285,8 +1298,9 @@ function vitePluginUseClient(useClientPluginOptions, manager) {
|
|
|
1285
1298
|
for (const meta of Object.values(manager.clientReferenceMetaMap)) {
|
|
1286
1299
|
let name = useClientPluginOptions.clientChunks?.({
|
|
1287
1300
|
id: meta.importId,
|
|
1301
|
+
normalizedId: manager.toRelativeId(meta.importId),
|
|
1288
1302
|
serverChunk: meta.serverChunk
|
|
1289
|
-
}) ??
|
|
1303
|
+
}) ?? meta.serverChunk;
|
|
1290
1304
|
name = cleanUrl(name.replaceAll("..", "__"));
|
|
1291
1305
|
const group = manager.clientReferenceGroups[name] ??= [];
|
|
1292
1306
|
group.push(meta);
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AssetDeps, AssetsManifest, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginOptions, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal } from "./plugin-
|
|
2
|
-
export { AssetDeps, AssetsManifest, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginOptions, vitePluginRsc as default, transformRscCssExport, vitePluginRscMinimal };
|
|
1
|
+
import { AssetDeps, AssetsManifest, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginManager, RscPluginOptions, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal } from "./plugin-DmahacLo.js";
|
|
2
|
+
export { AssetDeps, AssetsManifest, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginManager, RscPluginOptions, vitePluginRsc as default, transformRscCssExport, vitePluginRscMinimal };
|
package/dist/plugin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./dist-DiJnRA1C.js";
|
|
2
2
|
import "./plugin-CZbI4rhS.js";
|
|
3
|
-
import { transformRscCssExport, vitePluginRsc, vitePluginRscMinimal } from "./plugin-
|
|
3
|
+
import { transformRscCssExport, vitePluginRsc, vitePluginRscMinimal } from "./plugin-uOrnsu6L.js";
|
|
4
4
|
import "./encryption-utils-BDwwcMVT.js";
|
|
5
5
|
import "./rpc-tGuLT8PD.js";
|
|
6
6
|
import "./shared-BWHxNw3Q.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitejs/plugin-rsc",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.26",
|
|
4
4
|
"description": "React Server Components (RSC) support for Vite.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@types/estree": "^1.0.8",
|
|
54
54
|
"@types/node": "^22.18.0",
|
|
55
55
|
"@types/react": "^19.1.11",
|
|
56
|
-
"@types/react-dom": "^19.1.
|
|
56
|
+
"@types/react-dom": "^19.1.8",
|
|
57
57
|
"@vitejs/plugin-react": "workspace:*",
|
|
58
58
|
"react": "^19.1.1",
|
|
59
59
|
"react-dom": "^19.1.1",
|