@vitejs/plugin-rsc 0.4.10 → 0.4.11
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-D8OPzpF5.js +35 -0
- package/dist/browser-DjnGtEmB.d.ts +15 -0
- package/dist/browser-Dw18EFgE.d.ts +6 -0
- package/dist/browser-LizIyxet.js +17 -0
- package/dist/browser-QWbIPyhO.js +17 -0
- package/dist/browser.d.ts +4 -0
- package/dist/browser.js +7 -0
- package/dist/client-edAdk2GF.js +23 -0
- package/dist/core/browser.d.ts +2 -0
- package/dist/core/browser.js +5 -0
- package/dist/core/plugin.d.ts +6 -0
- package/dist/core/plugin.js +3 -0
- package/dist/core/rsc.d.ts +3 -0
- package/dist/core/rsc.js +5 -0
- package/dist/core/ssr.d.ts +3 -0
- package/dist/core/ssr.js +5 -0
- package/dist/dist-DEF94lDJ.js +41 -0
- package/dist/encryption-utils-BDwwcMVT.js +73 -0
- package/dist/extra/browser.d.ts +7 -0
- package/dist/extra/browser.js +83 -0
- package/dist/extra/rsc.d.ts +2 -0
- package/dist/extra/rsc.js +60 -0
- package/dist/extra/ssr.d.ts +10 -0
- package/dist/extra/ssr.js +35 -0
- package/dist/index-BHqtj9tT.d.ts +26 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +8 -0
- package/dist/plugin-BZEsXXjV.js +1442 -0
- package/dist/plugin-CZbI4rhS.js +24 -0
- package/dist/plugin-Dg2agPFN.d.ts +88 -0
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.js +8 -0
- package/dist/react/browser.d.ts +4 -0
- package/dist/react/browser.js +6 -0
- package/dist/react/rsc.d.ts +4 -0
- package/dist/react/rsc.js +6 -0
- package/dist/react/ssr.d.ts +4 -0
- package/dist/react/ssr.js +6 -0
- package/dist/rpc-tGuLT8PD.js +47 -0
- package/dist/rsc-BOV3yNSd.d.ts +12 -0
- package/dist/rsc-Cmvt9txp.d.ts +13 -0
- package/dist/rsc-DHfL29FT.js +36 -0
- package/dist/rsc-DKA6wwTB.js +78 -0
- package/dist/rsc-DgrejoNf.d.ts +15 -0
- package/dist/rsc-DmPsJrxF.js +42 -0
- package/dist/rsc-html-stream/browser.d.ts +4 -0
- package/dist/rsc-html-stream/browser.js +7 -0
- package/dist/rsc-html-stream/ssr.d.ts +6 -0
- package/dist/rsc-html-stream/ssr.js +7 -0
- package/dist/rsc.d.ts +13 -0
- package/dist/rsc.js +8 -0
- package/dist/server-DS3S6m0g.js +67 -0
- package/dist/shared-CEyKoKAb.js +22 -0
- package/dist/ssr-BOIYlvSn.js +23 -0
- package/dist/ssr-D5pxP29F.js +18 -0
- package/dist/ssr-D708H86k.d.ts +7 -0
- package/dist/ssr-DgSrGrln.d.ts +9 -0
- package/dist/ssr-Do_Ok_bB.js +47 -0
- package/dist/ssr.d.ts +4 -0
- package/dist/ssr.js +7 -0
- package/dist/utils/rpc.d.ts +7 -0
- package/dist/utils/rpc.js +3 -0
- package/dist/vendor/react-server-dom/LICENSE +21 -0
- package/dist/vendor/react-server-dom/README.md +5 -0
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.browser.development.js +2785 -0
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.browser.production.js +1664 -0
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.edge.development.js +2959 -0
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.edge.production.js +1845 -0
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.node.development.js +3002 -0
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.node.production.js +1894 -0
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2964 -0
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.node.unbundled.production.js +1859 -0
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-node-register.js +69 -0
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-plugin.js +400 -0
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.browser.development.js +4079 -0
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.browser.production.js +2806 -0
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.edge.development.js +4187 -0
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.edge.production.js +2845 -0
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.node.development.js +4195 -0
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.node.production.js +2902 -0
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.node.unbundled.development.js +4158 -0
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.node.unbundled.production.js +2868 -0
- package/dist/vendor/react-server-dom/client.browser.js +7 -0
- package/dist/vendor/react-server-dom/client.edge.js +7 -0
- package/dist/vendor/react-server-dom/client.js +3 -0
- package/dist/vendor/react-server-dom/client.node.js +7 -0
- package/dist/vendor/react-server-dom/client.node.unbundled.js +7 -0
- package/dist/vendor/react-server-dom/esm/package.json +3 -0
- package/dist/vendor/react-server-dom/esm/react-server-dom-webpack-node-loader.production.js +515 -0
- package/dist/vendor/react-server-dom/index.js +12 -0
- package/dist/vendor/react-server-dom/node-register.js +3 -0
- package/dist/vendor/react-server-dom/package.json +111 -0
- package/dist/vendor/react-server-dom/plugin.js +3 -0
- package/dist/vendor/react-server-dom/server.browser.js +17 -0
- package/dist/vendor/react-server-dom/server.edge.js +18 -0
- package/dist/vendor/react-server-dom/server.js +6 -0
- package/dist/vendor/react-server-dom/server.node.js +18 -0
- package/dist/vendor/react-server-dom/server.node.unbundled.js +18 -0
- package/dist/vendor/react-server-dom/static.browser.js +12 -0
- package/dist/vendor/react-server-dom/static.edge.js +12 -0
- package/dist/vendor/react-server-dom/static.js +6 -0
- package/dist/vendor/react-server-dom/static.node.js +12 -0
- package/dist/vendor/react-server-dom/static.node.unbundled.js +12 -0
- package/dist/vite-utils-CcqBE-C4.js +64 -0
- package/dist/vite-utils.d.ts +21 -0
- package/dist/vite-utils.js +3 -0
- package/package.json +3 -2
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as ReactClient from "@vitejs/plugin-rsc/vendor/react-server-dom/client.browser";
|
|
2
|
+
|
|
3
|
+
//#region src/react/browser.ts
|
|
4
|
+
function createFromReadableStream(stream, options = {}) {
|
|
5
|
+
return ReactClient.createFromReadableStream(stream, {
|
|
6
|
+
callServer,
|
|
7
|
+
findSourceMapURL,
|
|
8
|
+
...options
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
function createFromFetch(promiseForResponse, options = {}) {
|
|
12
|
+
return ReactClient.createFromFetch(promiseForResponse, {
|
|
13
|
+
callServer,
|
|
14
|
+
findSourceMapURL,
|
|
15
|
+
...options
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
const encodeReply = ReactClient.encodeReply;
|
|
19
|
+
const createServerReference = ReactClient.createServerReference;
|
|
20
|
+
function callServer(...args) {
|
|
21
|
+
return globalThis.__viteRscCallServer(...args);
|
|
22
|
+
}
|
|
23
|
+
function setServerCallback(fn) {
|
|
24
|
+
globalThis.__viteRscCallServer = fn;
|
|
25
|
+
}
|
|
26
|
+
const createTemporaryReferenceSet = ReactClient.createTemporaryReferenceSet;
|
|
27
|
+
function findSourceMapURL(filename, environmentName) {
|
|
28
|
+
const url = new URL("/__vite_rsc_findSourceMapURL", window.location.origin);
|
|
29
|
+
url.searchParams.set("filename", filename);
|
|
30
|
+
url.searchParams.set("environmentName", environmentName);
|
|
31
|
+
return url.toString();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setServerCallback };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CallServerCallback } from "./index-BHqtj9tT.js";
|
|
2
|
+
|
|
3
|
+
//#region src/react/browser.d.ts
|
|
4
|
+
declare function createFromReadableStream<T>(stream: ReadableStream<Uint8Array>, options?: object): Promise<T>;
|
|
5
|
+
declare function createFromFetch<T>(promiseForResponse: Promise<Response>, options?: object): Promise<T>;
|
|
6
|
+
declare const encodeReply: (v: unknown[], options?: unknown) => Promise<string | FormData>;
|
|
7
|
+
declare const createServerReference: (...args: any[]) => unknown;
|
|
8
|
+
// use global instead of local variable to tolerate duplicate modules
|
|
9
|
+
// e.g. when `setServerCallback` is pre-bundled but `createServerReference` is not
|
|
10
|
+
declare function callServer(...args: any[]): any;
|
|
11
|
+
declare function setServerCallback(fn: CallServerCallback): void;
|
|
12
|
+
declare const createTemporaryReferenceSet: () => unknown;
|
|
13
|
+
declare function findSourceMapURL(filename: string, environmentName: string): string | null;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setServerCallback };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { setRequireModule } from "./browser-QWbIPyhO.js";
|
|
2
|
+
import * as clientReferences from "virtual:vite-rsc/client-references";
|
|
3
|
+
|
|
4
|
+
//#region src/browser.ts
|
|
5
|
+
initialize();
|
|
6
|
+
function initialize() {
|
|
7
|
+
setRequireModule({ load: async (id) => {
|
|
8
|
+
if (!import.meta.env.__vite_rsc_build__) return __vite_rsc_raw_import__(import.meta.env.BASE_URL + id.slice(1));
|
|
9
|
+
else {
|
|
10
|
+
const import_ = clientReferences.default[id];
|
|
11
|
+
if (!import_) throw new Error(`client reference not found '${id}'`);
|
|
12
|
+
return import_();
|
|
13
|
+
}
|
|
14
|
+
} });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { memoize } from "./dist-DEF94lDJ.js";
|
|
2
|
+
import { removeReferenceCacheTag, setInternalRequire } from "./shared-CEyKoKAb.js";
|
|
3
|
+
|
|
4
|
+
//#region src/core/browser.ts
|
|
5
|
+
let init = false;
|
|
6
|
+
function setRequireModule(options) {
|
|
7
|
+
if (init) return;
|
|
8
|
+
init = true;
|
|
9
|
+
const requireModule = memoize((id) => {
|
|
10
|
+
return options.load(removeReferenceCacheTag(id));
|
|
11
|
+
});
|
|
12
|
+
globalThis.__vite_rsc_client_require__ = requireModule;
|
|
13
|
+
setInternalRequire();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { setRequireModule };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CallServerCallback } from "./index-BHqtj9tT.js";
|
|
2
|
+
import { setRequireModule } from "./browser-Dw18EFgE.js";
|
|
3
|
+
import { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setServerCallback } from "./browser-DjnGtEmB.js";
|
|
4
|
+
export { CallServerCallback, callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setRequireModule, setServerCallback };
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import "./dist-DEF94lDJ.js";
|
|
2
|
+
import "./shared-CEyKoKAb.js";
|
|
3
|
+
import { setRequireModule } from "./browser-QWbIPyhO.js";
|
|
4
|
+
import { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setServerCallback } from "./browser-D8OPzpF5.js";
|
|
5
|
+
import "./browser-LizIyxet.js";
|
|
6
|
+
|
|
7
|
+
export { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setRequireModule, setServerCallback };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/rsc-html-stream@0.0.6/node_modules/rsc-html-stream/client.js
|
|
2
|
+
let encoder = new TextEncoder();
|
|
3
|
+
let streamController;
|
|
4
|
+
let rscStream = new ReadableStream({ start(controller) {
|
|
5
|
+
if (typeof window === "undefined") return;
|
|
6
|
+
let handleChunk = (chunk) => {
|
|
7
|
+
if (typeof chunk === "string") controller.enqueue(encoder.encode(chunk));
|
|
8
|
+
else controller.enqueue(chunk);
|
|
9
|
+
};
|
|
10
|
+
window.__FLIGHT_DATA ||= [];
|
|
11
|
+
window.__FLIGHT_DATA.forEach(handleChunk);
|
|
12
|
+
window.__FLIGHT_DATA.push = (chunk) => {
|
|
13
|
+
handleChunk(chunk);
|
|
14
|
+
};
|
|
15
|
+
streamController = controller;
|
|
16
|
+
} });
|
|
17
|
+
if (typeof document !== "undefined" && document.readyState === "loading") document.addEventListener("DOMContentLoaded", () => {
|
|
18
|
+
streamController?.close();
|
|
19
|
+
});
|
|
20
|
+
else streamController?.close();
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { rscStream };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import "../index-BHqtj9tT.js";
|
|
2
|
+
import { createClientManifest, createServerDecodeClientManifest, createServerManifest, loadServerAction, setRequireModule } from "../rsc-BOV3yNSd.js";
|
|
3
|
+
export { createClientManifest, createServerDecodeClientManifest, createServerManifest, loadServerAction, setRequireModule };
|
package/dist/core/rsc.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import "../dist-DEF94lDJ.js";
|
|
2
|
+
import "../shared-CEyKoKAb.js";
|
|
3
|
+
import { createClientManifest, createServerDecodeClientManifest, createServerManifest, loadServerAction, setRequireModule } from "../rsc-DKA6wwTB.js";
|
|
4
|
+
|
|
5
|
+
export { createClientManifest, createServerDecodeClientManifest, createServerManifest, loadServerAction, setRequireModule };
|
package/dist/core/ssr.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/@hiogawa+utils@1.7.0/node_modules/@hiogawa/utils/dist/index.js
|
|
2
|
+
function tinyassert(value, message) {
|
|
3
|
+
if (value) return;
|
|
4
|
+
if (message instanceof Error) throw message;
|
|
5
|
+
throw new TinyAssertionError(message, tinyassert);
|
|
6
|
+
}
|
|
7
|
+
var TinyAssertionError = class extends Error {
|
|
8
|
+
constructor(message, stackStartFunction) {
|
|
9
|
+
super(message ?? "TinyAssertionError");
|
|
10
|
+
if (stackStartFunction && "captureStackTrace" in Error) Error.captureStackTrace(this, stackStartFunction);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
function safeFunctionCast(f) {
|
|
14
|
+
return f;
|
|
15
|
+
}
|
|
16
|
+
function once(f) {
|
|
17
|
+
let result;
|
|
18
|
+
let called = false;
|
|
19
|
+
return safeFunctionCast(function(...args) {
|
|
20
|
+
if (!called) {
|
|
21
|
+
result = f.apply(this, args);
|
|
22
|
+
called = true;
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function memoize(f, options) {
|
|
28
|
+
const keyFn = options?.keyFn ?? ((...args) => args[0]);
|
|
29
|
+
const cache = options?.cache ?? /* @__PURE__ */ new Map();
|
|
30
|
+
return safeFunctionCast(function(...args) {
|
|
31
|
+
const key = keyFn(...args);
|
|
32
|
+
const value = cache.get(key);
|
|
33
|
+
if (typeof value !== "undefined") return value;
|
|
34
|
+
const newValue = f.apply(this, args);
|
|
35
|
+
cache.set(key, newValue);
|
|
36
|
+
return newValue;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { memoize, once, tinyassert };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
//#region src/utils/encryption-utils.ts
|
|
2
|
+
function arrayBufferToString(buffer) {
|
|
3
|
+
const bytes = new Uint8Array(buffer);
|
|
4
|
+
const len = bytes.byteLength;
|
|
5
|
+
if (len < 65535) return String.fromCharCode.apply(null, bytes);
|
|
6
|
+
let binary = "";
|
|
7
|
+
for (let i = 0; i < len; i++) binary += String.fromCharCode(bytes[i]);
|
|
8
|
+
return binary;
|
|
9
|
+
}
|
|
10
|
+
function stringToUint8Array(binary) {
|
|
11
|
+
const len = binary.length;
|
|
12
|
+
const arr = new Uint8Array(len);
|
|
13
|
+
for (let i = 0; i < len; i++) arr[i] = binary.charCodeAt(i);
|
|
14
|
+
return arr;
|
|
15
|
+
}
|
|
16
|
+
function concatArray(chunks) {
|
|
17
|
+
let total = 0;
|
|
18
|
+
for (const chunk of chunks) total += chunk.length;
|
|
19
|
+
const result = new Uint8Array(total);
|
|
20
|
+
let offset = 0;
|
|
21
|
+
for (const chunk of chunks) {
|
|
22
|
+
result.set(chunk, offset);
|
|
23
|
+
offset += chunk.length;
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
async function concatArrayStream(stream) {
|
|
28
|
+
const chunks = [];
|
|
29
|
+
await stream.pipeTo(new WritableStream({ write(chunk) {
|
|
30
|
+
chunks.push(chunk);
|
|
31
|
+
} }));
|
|
32
|
+
return concatArray(chunks);
|
|
33
|
+
}
|
|
34
|
+
function arrayToStream(data) {
|
|
35
|
+
return new ReadableStream({ start(controller) {
|
|
36
|
+
controller.enqueue(data);
|
|
37
|
+
controller.close();
|
|
38
|
+
} });
|
|
39
|
+
}
|
|
40
|
+
function toBase64(buffer) {
|
|
41
|
+
return btoa(arrayBufferToString(buffer));
|
|
42
|
+
}
|
|
43
|
+
function fromBase64(data) {
|
|
44
|
+
return stringToUint8Array(atob(data));
|
|
45
|
+
}
|
|
46
|
+
async function generateEncryptionKey() {
|
|
47
|
+
const key = await crypto.subtle.generateKey({
|
|
48
|
+
name: "AES-GCM",
|
|
49
|
+
length: 256
|
|
50
|
+
}, true, ["encrypt", "decrypt"]);
|
|
51
|
+
const exported = await crypto.subtle.exportKey("raw", key);
|
|
52
|
+
return new Uint8Array(exported);
|
|
53
|
+
}
|
|
54
|
+
async function encryptBuffer(data, key) {
|
|
55
|
+
const iv = crypto.getRandomValues(new Uint8Array(16));
|
|
56
|
+
const encrypted = await crypto.subtle.encrypt({
|
|
57
|
+
name: "AES-GCM",
|
|
58
|
+
iv
|
|
59
|
+
}, key, data);
|
|
60
|
+
return toBase64(concatArray([iv, new Uint8Array(encrypted)]));
|
|
61
|
+
}
|
|
62
|
+
async function decryptBuffer(encryptedString, key) {
|
|
63
|
+
const concatenated = fromBase64(encryptedString);
|
|
64
|
+
const iv = concatenated.slice(0, 16);
|
|
65
|
+
const encrypted = concatenated.slice(16);
|
|
66
|
+
return crypto.subtle.decrypt({
|
|
67
|
+
name: "AES-GCM",
|
|
68
|
+
iv
|
|
69
|
+
}, key, encrypted);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
export { arrayToStream, concatArrayStream, decryptBuffer, encryptBuffer, fromBase64, generateEncryptionKey, toBase64 };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RscPayload } from "../rsc-Cmvt9txp.js";
|
|
2
|
+
|
|
3
|
+
//#region src/extra/browser.d.ts
|
|
4
|
+
declare function hydrate(): Promise<void>;
|
|
5
|
+
declare function fetchRSC(request: string | URL | Request): Promise<RscPayload["root"]>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { fetchRSC, hydrate };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import "../dist-DEF94lDJ.js";
|
|
2
|
+
import "../shared-CEyKoKAb.js";
|
|
3
|
+
import "../browser-QWbIPyhO.js";
|
|
4
|
+
import { createFromFetch, createFromReadableStream, createTemporaryReferenceSet, encodeReply, setServerCallback } from "../browser-D8OPzpF5.js";
|
|
5
|
+
import "../browser-LizIyxet.js";
|
|
6
|
+
import { rscStream } from "../client-edAdk2GF.js";
|
|
7
|
+
import React from "react";
|
|
8
|
+
import ReactDomClient from "react-dom/client";
|
|
9
|
+
import { jsx } from "react/jsx-runtime";
|
|
10
|
+
|
|
11
|
+
//#region src/extra/browser.tsx
|
|
12
|
+
async function hydrate() {
|
|
13
|
+
const callServer = async (id, args) => {
|
|
14
|
+
const url = new URL(window.location.href);
|
|
15
|
+
const temporaryReferences = createTemporaryReferenceSet();
|
|
16
|
+
const payload = await createFromFetch(fetch(url, {
|
|
17
|
+
method: "POST",
|
|
18
|
+
body: await encodeReply(args, { temporaryReferences }),
|
|
19
|
+
headers: { "x-rsc-action": id }
|
|
20
|
+
}), { temporaryReferences });
|
|
21
|
+
setPayload(payload);
|
|
22
|
+
return payload.returnValue;
|
|
23
|
+
};
|
|
24
|
+
setServerCallback(callServer);
|
|
25
|
+
async function onNavigation() {
|
|
26
|
+
const url = new URL(window.location.href);
|
|
27
|
+
const payload = await createFromFetch(fetch(url));
|
|
28
|
+
setPayload(payload);
|
|
29
|
+
}
|
|
30
|
+
const initialPayload = await createFromReadableStream(rscStream);
|
|
31
|
+
let setPayload;
|
|
32
|
+
function BrowserRoot() {
|
|
33
|
+
const [payload, setPayload_] = React.useState(initialPayload);
|
|
34
|
+
React.useEffect(() => {
|
|
35
|
+
setPayload = (v) => React.startTransition(() => setPayload_(v));
|
|
36
|
+
}, [setPayload_]);
|
|
37
|
+
React.useEffect(() => {
|
|
38
|
+
return listenNavigation(() => onNavigation());
|
|
39
|
+
}, []);
|
|
40
|
+
return payload.root;
|
|
41
|
+
}
|
|
42
|
+
const browserRoot = /* @__PURE__ */ jsx(React.StrictMode, { children: /* @__PURE__ */ jsx(BrowserRoot, {}) });
|
|
43
|
+
ReactDomClient.hydrateRoot(document, browserRoot, { formState: initialPayload.formState });
|
|
44
|
+
if (import.meta.hot) import.meta.hot.on("rsc:update", () => {
|
|
45
|
+
window.history.replaceState({}, "", window.location.href);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async function fetchRSC(request) {
|
|
49
|
+
const payload = await createFromFetch(fetch(request));
|
|
50
|
+
return payload.root;
|
|
51
|
+
}
|
|
52
|
+
function listenNavigation(onNavigation) {
|
|
53
|
+
window.addEventListener("popstate", onNavigation);
|
|
54
|
+
const oldPushState = window.history.pushState;
|
|
55
|
+
window.history.pushState = function(...args) {
|
|
56
|
+
const res = oldPushState.apply(this, args);
|
|
57
|
+
onNavigation();
|
|
58
|
+
return res;
|
|
59
|
+
};
|
|
60
|
+
const oldReplaceState = window.history.replaceState;
|
|
61
|
+
window.history.replaceState = function(...args) {
|
|
62
|
+
const res = oldReplaceState.apply(this, args);
|
|
63
|
+
onNavigation();
|
|
64
|
+
return res;
|
|
65
|
+
};
|
|
66
|
+
function onClick(e) {
|
|
67
|
+
let link = e.target.closest("a");
|
|
68
|
+
if (link && link instanceof HTMLAnchorElement && link.href && (!link.target || link.target === "_self") && link.origin === location.origin && !link.hasAttribute("download") && e.button === 0 && !e.metaKey && !e.ctrlKey && !e.altKey && !e.shiftKey && !e.defaultPrevented) {
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
history.pushState(null, "", link.href);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
document.addEventListener("click", onClick);
|
|
74
|
+
return () => {
|
|
75
|
+
document.removeEventListener("click", onClick);
|
|
76
|
+
window.removeEventListener("popstate", onNavigation);
|
|
77
|
+
window.history.pushState = oldPushState;
|
|
78
|
+
window.history.replaceState = oldReplaceState;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//#endregion
|
|
83
|
+
export { fetchRSC, hydrate };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import "../dist-DEF94lDJ.js";
|
|
2
|
+
import "../shared-CEyKoKAb.js";
|
|
3
|
+
import "../encryption-utils-BDwwcMVT.js";
|
|
4
|
+
import { loadServerAction } from "../rsc-DKA6wwTB.js";
|
|
5
|
+
import { createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, renderToReadableStream } from "../rsc-DHfL29FT.js";
|
|
6
|
+
import "../rsc-DmPsJrxF.js";
|
|
7
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
|
|
9
|
+
//#region src/extra/rsc.tsx
|
|
10
|
+
async function renderRequest(request, root, options) {
|
|
11
|
+
function RscRoot() {
|
|
12
|
+
const nonceMeta = options?.nonce && /* @__PURE__ */ jsx("meta", {
|
|
13
|
+
property: "csp-nonce",
|
|
14
|
+
nonce: options.nonce
|
|
15
|
+
});
|
|
16
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [nonceMeta, root] });
|
|
17
|
+
}
|
|
18
|
+
const url = new URL(request.url);
|
|
19
|
+
const isAction = request.method === "POST";
|
|
20
|
+
const isRscRequest = !request.headers.get("accept")?.includes("text/html") && !url.searchParams.has("__html") || url.searchParams.has("__rsc");
|
|
21
|
+
let returnValue;
|
|
22
|
+
let formState;
|
|
23
|
+
let temporaryReferences;
|
|
24
|
+
if (isAction) {
|
|
25
|
+
const actionId = request.headers.get("x-rsc-action");
|
|
26
|
+
if (actionId) {
|
|
27
|
+
const contentType = request.headers.get("content-type");
|
|
28
|
+
const body = contentType?.startsWith("multipart/form-data") ? await request.formData() : await request.text();
|
|
29
|
+
temporaryReferences = createTemporaryReferenceSet();
|
|
30
|
+
const args = await decodeReply(body, { temporaryReferences });
|
|
31
|
+
const action = await loadServerAction(actionId);
|
|
32
|
+
returnValue = await action.apply(null, args);
|
|
33
|
+
} else {
|
|
34
|
+
const formData = await request.formData();
|
|
35
|
+
const decodedAction = await decodeAction(formData);
|
|
36
|
+
const result = await decodedAction();
|
|
37
|
+
formState = await decodeFormState(result, formData);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const rscPayload = {
|
|
41
|
+
root: /* @__PURE__ */ jsx(RscRoot, {}),
|
|
42
|
+
formState,
|
|
43
|
+
returnValue
|
|
44
|
+
};
|
|
45
|
+
const rscOptions = { temporaryReferences };
|
|
46
|
+
const rscStream = renderToReadableStream(rscPayload, rscOptions);
|
|
47
|
+
if (isRscRequest) return new Response(rscStream, { headers: {
|
|
48
|
+
"content-type": "text/x-component;charset=utf-8",
|
|
49
|
+
vary: "accept"
|
|
50
|
+
} });
|
|
51
|
+
const ssrEntry = await import.meta.viteRsc.loadModule("ssr", "index");
|
|
52
|
+
return ssrEntry.renderHtml(rscStream, {
|
|
53
|
+
formState,
|
|
54
|
+
nonce: options?.nonce,
|
|
55
|
+
debugNoJs: url.searchParams.has("__nojs")
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
export { renderRequest };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReactFormState } from "react-dom/client";
|
|
2
|
+
|
|
3
|
+
//#region src/extra/ssr.d.ts
|
|
4
|
+
declare function renderHtml(rscStream: ReadableStream<Uint8Array>, options?: {
|
|
5
|
+
formState?: ReactFormState;
|
|
6
|
+
nonce?: string;
|
|
7
|
+
debugNoJs?: boolean;
|
|
8
|
+
}): Promise<Response>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { renderHtml };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import "../dist-DEF94lDJ.js";
|
|
2
|
+
import "../shared-CEyKoKAb.js";
|
|
3
|
+
import "../ssr-BOIYlvSn.js";
|
|
4
|
+
import { createFromReadableStream } from "../ssr-D5pxP29F.js";
|
|
5
|
+
import "../ssr-Do_Ok_bB.js";
|
|
6
|
+
import { injectRSCPayload } from "../server-DS3S6m0g.js";
|
|
7
|
+
import React from "react";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
import ReactDomServer from "react-dom/server.edge";
|
|
10
|
+
|
|
11
|
+
//#region src/extra/ssr.tsx
|
|
12
|
+
async function renderHtml(rscStream, options) {
|
|
13
|
+
const [rscStream1, rscStream2] = rscStream.tee();
|
|
14
|
+
let payload;
|
|
15
|
+
function SsrRoot() {
|
|
16
|
+
payload ??= createFromReadableStream(rscStream1, { nonce: options?.nonce });
|
|
17
|
+
const root = React.use(payload).root;
|
|
18
|
+
return root;
|
|
19
|
+
}
|
|
20
|
+
const bootstrapScriptContent = await import.meta.viteRsc.loadBootstrapScriptContent("index");
|
|
21
|
+
const htmlStream = await ReactDomServer.renderToReadableStream(/* @__PURE__ */ jsx(SsrRoot, {}), {
|
|
22
|
+
bootstrapScriptContent: options?.debugNoJs ? void 0 : bootstrapScriptContent,
|
|
23
|
+
nonce: options?.nonce,
|
|
24
|
+
formState: options?.formState
|
|
25
|
+
});
|
|
26
|
+
let responseStream = htmlStream;
|
|
27
|
+
if (!options?.debugNoJs) responseStream = responseStream.pipeThrough(injectRSCPayload(rscStream2, { nonce: options?.nonce }));
|
|
28
|
+
return new Response(responseStream, { headers: {
|
|
29
|
+
"content-type": "text/html;charset=utf-8",
|
|
30
|
+
vary: "accept"
|
|
31
|
+
} });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { renderHtml };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/types/index.d.ts
|
|
2
|
+
interface ImportManifestEntry {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
chunks: string[];
|
|
6
|
+
async?: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface BundlerConfig {
|
|
9
|
+
[bundlerId: string]: ImportManifestEntry;
|
|
10
|
+
}
|
|
11
|
+
type ModuleMap = {
|
|
12
|
+
[id: string]: {
|
|
13
|
+
[exportName: string]: ImportManifestEntry;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
interface ServerConsumerManifest {
|
|
17
|
+
moduleMap?: ModuleMap;
|
|
18
|
+
serverModuleMap?: BundlerConfig;
|
|
19
|
+
moduleLoading?: {
|
|
20
|
+
prefix: string;
|
|
21
|
+
crossOriign?: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
type CallServerCallback = (id: string, args: unknown[]) => unknown;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { BundlerConfig, CallServerCallback, ModuleMap, ServerConsumerManifest };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { RscPluginOptions, vitePluginRsc } from "./plugin-Dg2agPFN.js";
|
|
2
|
+
import MagicString from "magic-string";
|
|
3
|
+
import { Program } from "estree";
|
|
4
|
+
|
|
5
|
+
//#region src/transforms/hoist.d.ts
|
|
6
|
+
declare function transformHoistInlineDirective(input: string, ast: Program, {
|
|
7
|
+
runtime,
|
|
8
|
+
directive,
|
|
9
|
+
rejectNonAsyncFunction,
|
|
10
|
+
...options
|
|
11
|
+
}: {
|
|
12
|
+
runtime: (value: string, name: string) => string;
|
|
13
|
+
directive: string;
|
|
14
|
+
rejectNonAsyncFunction?: boolean;
|
|
15
|
+
encode?: (value: string) => string;
|
|
16
|
+
decode?: (value: string) => string;
|
|
17
|
+
noExport?: boolean;
|
|
18
|
+
}): {
|
|
19
|
+
output: MagicString;
|
|
20
|
+
names: string[];
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { RscPluginOptions, vitePluginRsc as default, transformHoistInlineDirective };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "./dist-DEF94lDJ.js";
|
|
2
|
+
import "./plugin-CZbI4rhS.js";
|
|
3
|
+
import { transformHoistInlineDirective, vitePluginRsc } from "./plugin-BZEsXXjV.js";
|
|
4
|
+
import "./encryption-utils-BDwwcMVT.js";
|
|
5
|
+
import "./rpc-tGuLT8PD.js";
|
|
6
|
+
import "./vite-utils-CcqBE-C4.js";
|
|
7
|
+
|
|
8
|
+
export { vitePluginRsc as default, transformHoistInlineDirective };
|