@vitejs/plugin-rsc 0.5.3 → 0.5.5
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 +1 -1
- package/dist/core/rsc.js +1 -1
- package/dist/{encryption-runtime-BeCv59UO.js → encryption-runtime-DlHpEnUc.js} +1 -1
- package/dist/index.js +2 -2
- package/dist/{plugin-yqduHnqG.js → plugin-BIGFumgz.js} +1 -1
- package/dist/plugin.js +2 -2
- package/dist/react/rsc.js +2 -2
- package/dist/{rpc-DgBxsMKW.js → rpc-CRpYrgKq.js} +48 -3
- package/dist/{rsc-DCIXw4uj.js → rsc-BIM0wUrP.js} +1 -1
- package/dist/{rsc-CvqvlKO2.js → rsc-BwsRzIFM.js} +7 -2
- package/dist/rsc.js +3 -3
- package/dist/utils/encryption-runtime.js +3 -3
- package/dist/utils/rpc.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -228,7 +228,7 @@ The plugin provides an additional helper for multi environment interaction.
|
|
|
228
228
|
|
|
229
229
|
This allows importing `ssr` environment module specified by `environments.ssr.build.rollupOptions.input[entryName]` inside `rsc` environment and vice versa.
|
|
230
230
|
|
|
231
|
-
During development, by default, this API assumes both `rsc` and `ssr` environments execute under the main Vite process. When enabling `rsc({ loadModuleDevProxy: true })` plugin option, the loaded module is implemented as a proxy with `fetch`-based RPC to call in node environment on the main Vite process, which for example, allows `rsc` environment inside cloudflare workers to access `ssr` environment on the main Vite process.
|
|
231
|
+
During development, by default, this API assumes both `rsc` and `ssr` environments execute under the main Vite process. When enabling `rsc({ loadModuleDevProxy: true })` plugin option, the loaded module is implemented as a proxy with `fetch`-based RPC to call in node environment on the main Vite process, which for example, allows `rsc` environment inside cloudflare workers to access `ssr` environment on the main Vite process. This proxy mechanism uses [turbo-stream](https://github.com/jacob-ebey/turbo-stream) for serializing data types beyond JSON, with custom encoders/decoders to additionally support `Request` and `Response` instances.
|
|
232
232
|
|
|
233
233
|
During production build, this API will be rewritten into a static import of the specified entry of other environment build and the modules are executed inside the same runtime.
|
|
234
234
|
|
package/dist/core/rsc.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../dist-BRSdGcl7.js";
|
|
2
2
|
import "../shared-DEpnONZf.js";
|
|
3
|
-
import { a as setRequireModule, i as loadServerAction, n as createServerDecodeClientManifest, r as createServerManifest, t as createClientManifest } from "../rsc-
|
|
3
|
+
import { a as setRequireModule, i as loadServerAction, n as createServerDecodeClientManifest, r as createServerManifest, t as createClientManifest } from "../rsc-BwsRzIFM.js";
|
|
4
4
|
|
|
5
5
|
export { createClientManifest, createServerDecodeClientManifest, createServerManifest, loadServerAction, setRequireModule };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { r as once } from "./dist-BRSdGcl7.js";
|
|
2
2
|
import { a as fromBase64, i as encryptBuffer, n as concatArrayStream, r as decryptBuffer, t as arrayToStream } from "./encryption-utils-6p8t4Xqm.js";
|
|
3
|
-
import { n as createFromReadableStream, u as renderToReadableStream } from "./rsc-
|
|
3
|
+
import { n as createFromReadableStream, u as renderToReadableStream } from "./rsc-BIM0wUrP.js";
|
|
4
4
|
import encryptionKeySource from "virtual:vite-rsc/encryption-key";
|
|
5
5
|
|
|
6
6
|
//#region src/utils/encryption-runtime.ts
|
package/dist/index.js
CHANGED
|
@@ -2,8 +2,8 @@ import "./plugin-D1MQNdps.js";
|
|
|
2
2
|
import "./dist-BRSdGcl7.js";
|
|
3
3
|
import "./transforms-BcLQCXiC.js";
|
|
4
4
|
import "./encryption-utils-6p8t4Xqm.js";
|
|
5
|
-
import "./rpc-
|
|
6
|
-
import { r as vitePluginRsc, t as getPluginApi } from "./plugin-
|
|
5
|
+
import "./rpc-CRpYrgKq.js";
|
|
6
|
+
import { r as vitePluginRsc, t as getPluginApi } from "./plugin-BIGFumgz.js";
|
|
7
7
|
import "./cjs-D5eQjp5l.js";
|
|
8
8
|
import "./shared-BbMae1Gg.js";
|
|
9
9
|
|
|
@@ -3,7 +3,7 @@ import { t as vitePluginRscCore } from "./plugin-D1MQNdps.js";
|
|
|
3
3
|
import { t as createDebug } from "./dist-BRSdGcl7.js";
|
|
4
4
|
import { a as hasDirective, n as transformDirectiveProxyExport, o as transformWrapExport, s as findDirectives, t as transformServerActionServer } from "./transforms-BcLQCXiC.js";
|
|
5
5
|
import { o as generateEncryptionKey, s as toBase64 } from "./encryption-utils-6p8t4Xqm.js";
|
|
6
|
-
import { n as createRpcServer } from "./rpc-
|
|
6
|
+
import { n as createRpcServer } from "./rpc-CRpYrgKq.js";
|
|
7
7
|
import { t as cjsModuleRunnerPlugin } from "./cjs-D5eQjp5l.js";
|
|
8
8
|
import { n as parseIdQuery, r as toCssVirtual, t as parseCssVirtual } from "./shared-BbMae1Gg.js";
|
|
9
9
|
import { createRequire } from "node:module";
|
package/dist/plugin.js
CHANGED
|
@@ -2,8 +2,8 @@ import "./plugin-D1MQNdps.js";
|
|
|
2
2
|
import "./dist-BRSdGcl7.js";
|
|
3
3
|
import "./transforms-BcLQCXiC.js";
|
|
4
4
|
import "./encryption-utils-6p8t4Xqm.js";
|
|
5
|
-
import "./rpc-
|
|
6
|
-
import { i as vitePluginRscMinimal, n as transformRscCssExport, r as vitePluginRsc, t as getPluginApi } from "./plugin-
|
|
5
|
+
import "./rpc-CRpYrgKq.js";
|
|
6
|
+
import { i as vitePluginRscMinimal, n as transformRscCssExport, r as vitePluginRsc, t as getPluginApi } from "./plugin-BIGFumgz.js";
|
|
7
7
|
import "./cjs-D5eQjp5l.js";
|
|
8
8
|
import "./shared-BbMae1Gg.js";
|
|
9
9
|
|
package/dist/react/rsc.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../dist-BRSdGcl7.js";
|
|
2
2
|
import "../shared-DEpnONZf.js";
|
|
3
|
-
import { a as setRequireModule, i as loadServerAction } from "../rsc-
|
|
4
|
-
import { a as decodeFormState, c as registerClientReference, i as decodeAction, l as registerServerReference, n as createFromReadableStream, o as decodeReply, r as createTemporaryReferenceSet, s as encodeReply, t as createClientTemporaryReferenceSet, u as renderToReadableStream } from "../rsc-
|
|
3
|
+
import { a as setRequireModule, i as loadServerAction } from "../rsc-BwsRzIFM.js";
|
|
4
|
+
import { a as decodeFormState, c as registerClientReference, i as decodeAction, l as registerServerReference, n as createFromReadableStream, o as decodeReply, r as createTemporaryReferenceSet, s as encodeReply, t as createClientTemporaryReferenceSet, u as renderToReadableStream } from "../rsc-BIM0wUrP.js";
|
|
5
5
|
|
|
6
6
|
export { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, loadServerAction, registerClientReference, registerServerReference, renderToReadableStream, setRequireModule };
|
|
@@ -1,10 +1,49 @@
|
|
|
1
1
|
import { decode, encode } from "turbo-stream";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/rpc.ts
|
|
4
|
+
const decodePlugins = [(type, ...rest) => {
|
|
5
|
+
switch (type) {
|
|
6
|
+
case "Request": {
|
|
7
|
+
const [method, url, headers, body] = rest;
|
|
8
|
+
return { value: new Request(url, {
|
|
9
|
+
body,
|
|
10
|
+
headers,
|
|
11
|
+
method,
|
|
12
|
+
duplex: body ? "half" : void 0
|
|
13
|
+
}) };
|
|
14
|
+
}
|
|
15
|
+
case "Response": {
|
|
16
|
+
const [status, statusText, headers, body] = rest;
|
|
17
|
+
return { value: new Response(body, {
|
|
18
|
+
headers,
|
|
19
|
+
status,
|
|
20
|
+
statusText
|
|
21
|
+
}) };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}];
|
|
26
|
+
const encodePlugins = [(obj) => {
|
|
27
|
+
if (obj instanceof Request) return [
|
|
28
|
+
"Request",
|
|
29
|
+
obj.method,
|
|
30
|
+
obj.url,
|
|
31
|
+
Array.from(obj.headers),
|
|
32
|
+
obj.body
|
|
33
|
+
];
|
|
34
|
+
if (obj instanceof Response) return [
|
|
35
|
+
"Response",
|
|
36
|
+
obj.status,
|
|
37
|
+
obj.statusText,
|
|
38
|
+
Array.from(obj.headers),
|
|
39
|
+
obj.body
|
|
40
|
+
];
|
|
41
|
+
return false;
|
|
42
|
+
}];
|
|
4
43
|
function createRpcServer(handlers) {
|
|
5
44
|
return async (request) => {
|
|
6
45
|
if (!request.body) throw new Error(`loadModuleDevProxy error: missing request body`);
|
|
7
|
-
const reqPayload = await decode(request.body.pipeThrough(new TextDecoderStream()));
|
|
46
|
+
const reqPayload = await decode(request.body.pipeThrough(new TextDecoderStream()), { plugins: decodePlugins });
|
|
8
47
|
const handler = handlers[reqPayload.method];
|
|
9
48
|
if (!handler) throw new Error(`loadModuleDevProxy error: unknown method ${reqPayload.method}`);
|
|
10
49
|
const resPayload = {
|
|
@@ -17,7 +56,10 @@ function createRpcServer(handlers) {
|
|
|
17
56
|
resPayload.ok = false;
|
|
18
57
|
resPayload.data = e;
|
|
19
58
|
}
|
|
20
|
-
return new Response(encode(resPayload
|
|
59
|
+
return new Response(encode(resPayload, {
|
|
60
|
+
plugins: encodePlugins,
|
|
61
|
+
redactErrors: false
|
|
62
|
+
}));
|
|
21
63
|
};
|
|
22
64
|
}
|
|
23
65
|
function createRpcClient(options) {
|
|
@@ -25,6 +67,9 @@ function createRpcClient(options) {
|
|
|
25
67
|
const body = encode({
|
|
26
68
|
method,
|
|
27
69
|
args
|
|
70
|
+
}, {
|
|
71
|
+
plugins: encodePlugins,
|
|
72
|
+
redactErrors: false
|
|
28
73
|
}).pipeThrough(new TextEncoderStream());
|
|
29
74
|
const res = await fetch(options.endpoint, {
|
|
30
75
|
method: "POST",
|
|
@@ -32,7 +77,7 @@ function createRpcClient(options) {
|
|
|
32
77
|
duplex: "half"
|
|
33
78
|
});
|
|
34
79
|
if (!res.ok || !res.body) throw new Error(`loadModuleDevProxy error: ${res.status} ${res.statusText}`);
|
|
35
|
-
const resPayload = await decode(res.body.pipeThrough(new TextDecoderStream()));
|
|
80
|
+
const resPayload = await decode(res.body.pipeThrough(new TextDecoderStream()), { plugins: decodePlugins });
|
|
36
81
|
if (!resPayload.ok) throw resPayload.data;
|
|
37
82
|
return resPayload.data;
|
|
38
83
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as createServerDecodeClientManifest, r as createServerManifest, t as createClientManifest } from "./rsc-
|
|
1
|
+
import { n as createServerDecodeClientManifest, r as createServerManifest, t as createClientManifest } from "./rsc-BwsRzIFM.js";
|
|
2
2
|
import * as ReactClient from "@vitejs/plugin-rsc/vendor/react-server-dom/client.edge";
|
|
3
3
|
import * as ReactServer from "@vitejs/plugin-rsc/vendor/react-server-dom/server.edge";
|
|
4
4
|
|
|
@@ -15,11 +15,16 @@ function setRequireModule(options) {
|
|
|
15
15
|
if (id.startsWith(SERVER_DECODE_CLIENT_PREFIX)) {
|
|
16
16
|
id = id.slice(SERVER_DECODE_CLIENT_PREFIX.length);
|
|
17
17
|
id = removeReferenceCacheTag(id);
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const target = {};
|
|
19
|
+
const getOrCreateClientReference = (name) => {
|
|
20
20
|
return target[name] ??= ReactServer.registerClientReference(() => {
|
|
21
21
|
throw new Error(`Unexpectedly client reference export '${name}' is called on server`);
|
|
22
22
|
}, id, name);
|
|
23
|
+
};
|
|
24
|
+
return new Proxy(target, { getOwnPropertyDescriptor(_target, name) {
|
|
25
|
+
if (typeof name !== "string" || name === "then") return Reflect.getOwnPropertyDescriptor(target, name);
|
|
26
|
+
getOrCreateClientReference(name);
|
|
27
|
+
return Reflect.getOwnPropertyDescriptor(target, name);
|
|
23
28
|
} });
|
|
24
29
|
}
|
|
25
30
|
return requireModule(id);
|
package/dist/rsc.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "./dist-BRSdGcl7.js";
|
|
2
2
|
import "./encryption-utils-6p8t4Xqm.js";
|
|
3
3
|
import "./shared-DEpnONZf.js";
|
|
4
|
-
import { a as setRequireModule, i as loadServerAction, r as createServerManifest, t as createClientManifest } from "./rsc-
|
|
5
|
-
import { a as decodeFormState, c as registerClientReference, i as decodeAction, l as registerServerReference, n as createFromReadableStream, o as decodeReply, r as createTemporaryReferenceSet, s as encodeReply, t as createClientTemporaryReferenceSet, u as renderToReadableStream } from "./rsc-
|
|
6
|
-
import { n as encryptActionBoundArgs, t as decryptActionBoundArgs } from "./encryption-runtime-
|
|
4
|
+
import { a as setRequireModule, i as loadServerAction, r as createServerManifest, t as createClientManifest } from "./rsc-BwsRzIFM.js";
|
|
5
|
+
import { a as decodeFormState, c as registerClientReference, i as decodeAction, l as registerServerReference, n as createFromReadableStream, o as decodeReply, r as createTemporaryReferenceSet, s as encodeReply, t as createClientTemporaryReferenceSet, u as renderToReadableStream } from "./rsc-BIM0wUrP.js";
|
|
6
|
+
import { n as encryptActionBoundArgs, t as decryptActionBoundArgs } from "./encryption-runtime-DlHpEnUc.js";
|
|
7
7
|
import serverReferences from "virtual:vite-rsc/server-references";
|
|
8
8
|
|
|
9
9
|
//#region src/rsc.tsx
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "../dist-BRSdGcl7.js";
|
|
2
2
|
import "../encryption-utils-6p8t4Xqm.js";
|
|
3
3
|
import "../shared-DEpnONZf.js";
|
|
4
|
-
import "../rsc-
|
|
5
|
-
import "../rsc-
|
|
6
|
-
import { n as encryptActionBoundArgs, t as decryptActionBoundArgs } from "../encryption-runtime-
|
|
4
|
+
import "../rsc-BwsRzIFM.js";
|
|
5
|
+
import "../rsc-BIM0wUrP.js";
|
|
6
|
+
import { n as encryptActionBoundArgs, t as decryptActionBoundArgs } from "../encryption-runtime-DlHpEnUc.js";
|
|
7
7
|
|
|
8
8
|
export { decryptActionBoundArgs, encryptActionBoundArgs };
|
package/dist/utils/rpc.js
CHANGED