@vitejs/plugin-rsc 0.4.11 → 0.4.12
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 +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1 -1
- package/dist/{plugin-BZEsXXjV.js → plugin-BvUB-eig.js} +37 -9
- package/dist/plugin.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -130,7 +130,7 @@ export default defineConfig({
|
|
|
130
130
|
- [`entry.rsc.tsx`](./examples/starter/src/framework/entry.rsc.tsx)
|
|
131
131
|
|
|
132
132
|
```tsx
|
|
133
|
-
import * as ReactServer from '@vitejs/plugin-rsc/rsc' // re-export of react-server-dom/server.edge
|
|
133
|
+
import * as ReactServer from '@vitejs/plugin-rsc/rsc' // re-export of react-server-dom/server.edge and client.edge
|
|
134
134
|
|
|
135
135
|
// the plugin assumes `rsc` entry having default export of request handler
|
|
136
136
|
export default async function handler(request: Request): Promise<Response> {
|
|
@@ -214,11 +214,12 @@ main();
|
|
|
214
214
|
|
|
215
215
|
### `@vitejs/plugin-rsc/rsc`
|
|
216
216
|
|
|
217
|
-
This module re-exports RSC runtime API provided by `react-server-dom/server.edge`
|
|
217
|
+
This module re-exports RSC runtime API provided by `react-server-dom/server.edge` and `react-server-dom/client.edge` such as:
|
|
218
218
|
|
|
219
219
|
- `renderToReadableStream`: RSC serialization (React VDOM -> RSC stream)
|
|
220
220
|
- `createFromReadableStream`: RSC deserialization (RSC stream -> React VDOM). This is also available on rsc environment itself. For example, it allows saving serailized RSC and deserializing it for later use.
|
|
221
|
-
- `decodeAction/decodeReply/loadServerAction
|
|
221
|
+
- `decodeAction/decodeReply/decodeFormState/loadServerAction/createTemporaryReferenceSet`
|
|
222
|
+
- `encodeReply/createClientTemporaryReferenceSet`
|
|
222
223
|
|
|
223
224
|
### `@vitejs/plugin-rsc/ssr`
|
|
224
225
|
|
package/dist/index.d.ts
CHANGED
|
@@ -5,12 +5,13 @@ import { Program } from "estree";
|
|
|
5
5
|
//#region src/transforms/hoist.d.ts
|
|
6
6
|
declare function transformHoistInlineDirective(input: string, ast: Program, {
|
|
7
7
|
runtime,
|
|
8
|
-
directive,
|
|
9
8
|
rejectNonAsyncFunction,
|
|
10
9
|
...options
|
|
11
10
|
}: {
|
|
12
|
-
runtime: (value: string, name: string
|
|
13
|
-
|
|
11
|
+
runtime: (value: string, name: string, meta: {
|
|
12
|
+
directiveMatch: RegExpMatchArray;
|
|
13
|
+
}) => string;
|
|
14
|
+
directive: string | RegExp;
|
|
14
15
|
rejectNonAsyncFunction?: boolean;
|
|
15
16
|
encode?: (value: string) => string;
|
|
16
17
|
decode?: (value: string) => string;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./dist-DEF94lDJ.js";
|
|
2
2
|
import "./plugin-CZbI4rhS.js";
|
|
3
|
-
import { transformHoistInlineDirective, vitePluginRsc } from "./plugin-
|
|
3
|
+
import { transformHoistInlineDirective, vitePluginRsc } from "./plugin-BvUB-eig.js";
|
|
4
4
|
import "./encryption-utils-BDwwcMVT.js";
|
|
5
5
|
import "./rpc-tGuLT8PD.js";
|
|
6
6
|
import "./vite-utils-CcqBE-C4.js";
|
|
@@ -17,15 +17,10 @@ import { crawlFrameworkPkgs } from "vitefu";
|
|
|
17
17
|
import { walk } from "estree-walker";
|
|
18
18
|
import { analyze, extract_names } from "periscopic";
|
|
19
19
|
|
|
20
|
-
//#region src/transforms/utils.ts
|
|
21
|
-
function hasDirective(body, directive) {
|
|
22
|
-
return !!body.find((stmt) => stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && stmt.expression.value === directive);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
//#endregion
|
|
26
20
|
//#region src/transforms/hoist.ts
|
|
27
|
-
function transformHoistInlineDirective(input, ast, { runtime,
|
|
21
|
+
function transformHoistInlineDirective(input, ast, { runtime, rejectNonAsyncFunction,...options }) {
|
|
28
22
|
const output = new MagicString(input);
|
|
23
|
+
const directive = typeof options.directive === "string" ? exactRegex(options.directive) : options.directive;
|
|
29
24
|
walk(ast, { enter(node) {
|
|
30
25
|
if (node.type === "ExportAllDeclaration") this.remove();
|
|
31
26
|
if (node.type === "ExportNamedDeclaration" && !node.declaration) this.remove();
|
|
@@ -33,7 +28,9 @@ function transformHoistInlineDirective(input, ast, { runtime, directive, rejectN
|
|
|
33
28
|
const analyzed = analyze(ast);
|
|
34
29
|
const names = [];
|
|
35
30
|
walk(ast, { enter(node, parent) {
|
|
36
|
-
if ((node.type === "FunctionExpression" || node.type === "FunctionDeclaration" || node.type === "ArrowFunctionExpression") && node.body.type === "BlockStatement"
|
|
31
|
+
if ((node.type === "FunctionExpression" || node.type === "FunctionDeclaration" || node.type === "ArrowFunctionExpression") && node.body.type === "BlockStatement") {
|
|
32
|
+
const match = matchDirective(node.body.body, directive);
|
|
33
|
+
if (!match) return;
|
|
37
34
|
if (!node.async && rejectNonAsyncFunction) throw Object.assign(/* @__PURE__ */ new Error(`"${directive}" doesn't allow non async function`), { pos: node.start });
|
|
38
35
|
const scope = analyzed.map.get(node);
|
|
39
36
|
tinyassert(scope);
|
|
@@ -54,7 +51,7 @@ function transformHoistInlineDirective(input, ast, { runtime, directive, rejectN
|
|
|
54
51
|
output.update(node.start, node.body.start, `\n;${options.noExport ? "" : "export "}${node.async ? "async " : ""}function ${newName}(${newParams}) `);
|
|
55
52
|
output.appendLeft(node.end, `;\n/* #__PURE__ */ Object.defineProperty(${newName}, "name", { value: ${JSON.stringify(originalName)} });\n`);
|
|
56
53
|
output.move(node.start, node.end, input.length);
|
|
57
|
-
let newCode = `/* #__PURE__ */ ${runtime(newName, newName)}`;
|
|
54
|
+
let newCode = `/* #__PURE__ */ ${runtime(newName, newName, { directiveMatch: match })}`;
|
|
58
55
|
if (bindVars.length > 0) {
|
|
59
56
|
const bindArgs = options.encode ? options.encode("[" + bindVars.join(", ") + "]") : bindVars.join(", ");
|
|
60
57
|
newCode = `${newCode}.bind(null, ${bindArgs})`;
|
|
@@ -74,6 +71,13 @@ function transformHoistInlineDirective(input, ast, { runtime, directive, rejectN
|
|
|
74
71
|
names
|
|
75
72
|
};
|
|
76
73
|
}
|
|
74
|
+
const exactRegex = (s) => /* @__PURE__ */ new RegExp("^" + s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") + "$");
|
|
75
|
+
function matchDirective(body, directive) {
|
|
76
|
+
for (const stable of body) if (stable.type === "ExpressionStatement" && stable.expression.type === "Literal" && typeof stable.expression.value === "string") {
|
|
77
|
+
const match = stable.expression.value.match(directive);
|
|
78
|
+
if (match) return match;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
77
81
|
|
|
78
82
|
//#endregion
|
|
79
83
|
//#region src/transforms/wrap-export.ts
|
|
@@ -197,6 +201,12 @@ function transformWrapExport(input, ast, options) {
|
|
|
197
201
|
};
|
|
198
202
|
}
|
|
199
203
|
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/transforms/utils.ts
|
|
206
|
+
function hasDirective(body, directive) {
|
|
207
|
+
return !!body.find((stmt) => stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && stmt.expression.value === directive);
|
|
208
|
+
}
|
|
209
|
+
|
|
200
210
|
//#endregion
|
|
201
211
|
//#region src/transforms/proxy-export.ts
|
|
202
212
|
function transformDirectiveProxyExport(ast, options) {
|
|
@@ -391,6 +401,24 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
391
401
|
sharedPlugins: true,
|
|
392
402
|
sharedConfigBuild: true,
|
|
393
403
|
async buildApp(builder) {
|
|
404
|
+
if (!builder.environments.ssr?.config.build.rollupOptions.input) {
|
|
405
|
+
isScanBuild = true;
|
|
406
|
+
builder.environments.rsc.config.build.write = false;
|
|
407
|
+
builder.environments.client.config.build.write = false;
|
|
408
|
+
await builder.build(builder.environments.rsc);
|
|
409
|
+
await builder.build(builder.environments.client);
|
|
410
|
+
isScanBuild = false;
|
|
411
|
+
builder.environments.rsc.config.build.write = true;
|
|
412
|
+
builder.environments.client.config.build.write = true;
|
|
413
|
+
await builder.build(builder.environments.rsc);
|
|
414
|
+
clientReferenceMetaMap = sortObject(clientReferenceMetaMap);
|
|
415
|
+
serverResourcesMetaMap = sortObject(serverResourcesMetaMap);
|
|
416
|
+
await builder.build(builder.environments.client);
|
|
417
|
+
const assetsManifestCode = `export default ${JSON.stringify(buildAssetsManifest, null, 2)}`;
|
|
418
|
+
const manifestPath = path.join(builder.environments.rsc.config.build.outDir, BUILD_ASSETS_MANIFEST_NAME);
|
|
419
|
+
fs.writeFileSync(manifestPath, assetsManifestCode);
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
394
422
|
isScanBuild = true;
|
|
395
423
|
builder.environments.rsc.config.build.write = false;
|
|
396
424
|
builder.environments.ssr.config.build.write = false;
|
package/dist/plugin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./dist-DEF94lDJ.js";
|
|
2
2
|
import "./plugin-CZbI4rhS.js";
|
|
3
|
-
import { __fix_cloudflare, findSourceMapURL, transformRscCssExport, vitePluginFindSourceMapURL, vitePluginRsc, vitePluginRscCss } from "./plugin-
|
|
3
|
+
import { __fix_cloudflare, findSourceMapURL, transformRscCssExport, vitePluginFindSourceMapURL, vitePluginRsc, vitePluginRscCss } from "./plugin-BvUB-eig.js";
|
|
4
4
|
import "./encryption-utils-BDwwcMVT.js";
|
|
5
5
|
import "./rpc-tGuLT8PD.js";
|
|
6
6
|
import "./vite-utils-CcqBE-C4.js";
|