@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.
- package/dist/{browser-DIa4fISB.js → browser-QU10IP0-.js} +2 -1
- package/dist/browser.js +1 -1
- package/dist/extra/browser.js +1 -1
- package/dist/extra/rsc.js +1 -1
- package/dist/extra/ssr.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{plugin-CYYsF3qY.d.ts → plugin-BQszG7oj.d.ts} +1 -0
- package/dist/{plugin-Cu7_zbmH.js → plugin-DYOxE_xg.js} +62 -23
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.js +1 -1
- package/dist/{rsc-CGUEQCnf.js → rsc-BwEwbLG4.js} +2 -1
- package/dist/rsc.js +1 -1
- package/dist/{ssr-BuzPa0Go.js → ssr-BMTRhW5g.js} +2 -1
- package/dist/ssr.js +1 -1
- package/package.json +1 -1
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-
|
|
5
|
+
import "./browser-QU10IP0-.js";
|
|
6
6
|
|
|
7
7
|
export { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setRequireModule, setServerCallback };
|
package/dist/extra/browser.js
CHANGED
|
@@ -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-
|
|
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-
|
|
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-
|
|
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
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-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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
987
|
-
|
|
988
|
-
|
|
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
|
-
|
|
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, [
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
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
|
-
|
|
1590
|
-
|
|
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-
|
|
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-
|
|
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";
|
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-
|
|
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 };
|
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-
|
|
5
|
+
import "./ssr-BMTRhW5g.js";
|
|
6
6
|
|
|
7
7
|
export { callServer, createFromReadableStream, createServerConsumerManifest, createServerReference, findSourceMapURL, setRequireModule };
|