@vitejs/plugin-rsc 0.4.25 → 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);
|
|
@@ -845,6 +860,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
845
860
|
const resolved = await environment.pluginContainer.resolveId(source);
|
|
846
861
|
assert(resolved, `[vite-rsc] failed to resolve server handler '${source}'`);
|
|
847
862
|
const mod = await environment.runner.import(resolved.id);
|
|
863
|
+
req.url = req.originalUrl ?? req.url;
|
|
848
864
|
await createRequestListener(mod.default)(req, res);
|
|
849
865
|
} catch (e) {
|
|
850
866
|
next(e);
|
|
@@ -873,6 +889,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
873
889
|
return () => {
|
|
874
890
|
server.middlewares.use(async (req, res, next) => {
|
|
875
891
|
try {
|
|
892
|
+
req.url = req.originalUrl ?? req.url;
|
|
876
893
|
await handler(req, res);
|
|
877
894
|
} catch (e) {
|
|
878
895
|
next(e);
|
|
@@ -1164,34 +1181,22 @@ import.meta.hot.on("rsc:update", () => {
|
|
|
1164
1181
|
`;
|
|
1165
1182
|
return code;
|
|
1166
1183
|
}),
|
|
1167
|
-
{
|
|
1168
|
-
name: "rsc:inject-async-local-storage",
|
|
1169
|
-
transform: { handler(code) {
|
|
1170
|
-
if ((this.environment.name === "ssr" || this.environment.name === "rsc") && code.includes("typeof AsyncLocalStorage") && code.includes("new AsyncLocalStorage()") && !code.includes("__viteRscAyncHooks")) return (this.environment.mode === "build" && !isRolldownVite ? `const __viteRscAyncHooks = require("node:async_hooks");` : `import * as __viteRscAyncHooks from "node:async_hooks";`) + `globalThis.AsyncLocalStorage = __viteRscAyncHooks.AsyncLocalStorage;` + code;
|
|
1171
|
-
} }
|
|
1172
|
-
},
|
|
1173
1184
|
...vitePluginRscMinimal(rscPluginOptions, manager),
|
|
1174
1185
|
...vitePluginFindSourceMapURL(),
|
|
1175
1186
|
...vitePluginRscCss(rscPluginOptions, manager),
|
|
1176
1187
|
...rscPluginOptions.validateImports !== false ? [validateImportPlugin()] : [],
|
|
1177
1188
|
scanBuildStripPlugin({ manager }),
|
|
1178
|
-
...cjsModuleRunnerPlugin()
|
|
1189
|
+
...cjsModuleRunnerPlugin(),
|
|
1190
|
+
...globalAsyncLocalStoragePlugin()
|
|
1179
1191
|
];
|
|
1180
1192
|
}
|
|
1181
|
-
function
|
|
1182
|
-
return {
|
|
1183
|
-
name: "rsc:
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
const output = await transformScanBuildStrip(code);
|
|
1189
|
-
return {
|
|
1190
|
-
code: output,
|
|
1191
|
-
map: { mappings: "" }
|
|
1192
|
-
};
|
|
1193
|
-
}
|
|
1194
|
-
};
|
|
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
|
+
}];
|
|
1195
1200
|
}
|
|
1196
1201
|
function vitePluginUseClient(useClientPluginOptions, manager) {
|
|
1197
1202
|
const packageSources = /* @__PURE__ */ new Map();
|
|
@@ -1293,8 +1298,9 @@ function vitePluginUseClient(useClientPluginOptions, manager) {
|
|
|
1293
1298
|
for (const meta of Object.values(manager.clientReferenceMetaMap)) {
|
|
1294
1299
|
let name = useClientPluginOptions.clientChunks?.({
|
|
1295
1300
|
id: meta.importId,
|
|
1301
|
+
normalizedId: manager.toRelativeId(meta.importId),
|
|
1296
1302
|
serverChunk: meta.serverChunk
|
|
1297
|
-
}) ??
|
|
1303
|
+
}) ?? meta.serverChunk;
|
|
1298
1304
|
name = cleanUrl(name.replaceAll("..", "__"));
|
|
1299
1305
|
const group = manager.clientReferenceGroups[name] ??= [];
|
|
1300
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";
|