@vitejs/plugin-rsc 0.4.12 → 0.4.13
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 +6 -5
- package/dist/{browser-LizIyxet.js → browser-C1Q4O7AS.js} +5 -1
- package/dist/{browser-DjnGtEmB.d.ts → browser-CeSkQWD5.d.ts} +0 -2
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +1 -1
- package/dist/{client-edAdk2GF.js → client-CPc-spDn.js} +1 -1
- package/dist/extra/browser.d.ts +8 -1
- package/dist/extra/browser.js +8 -2
- package/dist/extra/rsc.d.ts +1 -1
- package/dist/extra/rsc.js +4 -1
- package/dist/extra/ssr.d.ts +4 -0
- package/dist/extra/ssr.js +5 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/{plugin-Dg2agPFN.d.ts → plugin-CCrsoChj.d.ts} +16 -16
- package/dist/{plugin-BvUB-eig.js → plugin-DgH7V82E.js} +53 -12
- package/dist/plugin.d.ts +2 -2
- package/dist/plugin.js +1 -1
- package/dist/react/browser.d.ts +1 -1
- package/dist/{rsc-DmPsJrxF.js → rsc-BIUd01vh.js} +3 -2
- package/dist/{rsc-Cmvt9txp.d.ts → rsc-DryRyKqc.d.ts} +3 -0
- package/dist/rsc-html-stream/browser.d.ts +1 -0
- package/dist/rsc-html-stream/browser.js +2 -1
- package/dist/rsc-html-stream/ssr.d.ts +1 -0
- package/dist/rsc-html-stream/ssr.js +2 -1
- package/dist/rsc.d.ts +0 -4
- package/dist/rsc.js +1 -1
- package/dist/{server-DS3S6m0g.js → server-C50j-DRF.js} +8 -2
- package/dist/{ssr-Do_Ok_bB.js → ssr-DNwSdZ9T.js} +6 -4
- package/dist/ssr.js +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ This package provides [React Server Components](https://react.dev/reference/rsc/
|
|
|
11
11
|
|
|
12
12
|
## Getting Started
|
|
13
13
|
|
|
14
|
-
You can
|
|
14
|
+
You can create a starter project by:
|
|
15
15
|
|
|
16
16
|
```sh
|
|
17
17
|
npx degit vitejs/vite-plugin-react/packages/plugin-rsc/examples/starter my-app
|
|
@@ -22,11 +22,9 @@ npx degit vitejs/vite-plugin-react/packages/plugin-rsc/examples/starter my-app
|
|
|
22
22
|
- [`./examples/starter`](./examples/starter)
|
|
23
23
|
- This example provides an in-depth overview of API with inline comments to explain how they function within RSC-powered React application.
|
|
24
24
|
- [`./examples/react-router`](./examples/react-router)
|
|
25
|
-
- This demonstrates how to integrate [experimental React Router RSC API](https://remix.run/blog/rsc-preview)
|
|
26
|
-
It also includes `@cloudflare/vite-plugin` integration.
|
|
25
|
+
- This demonstrates how to integrate [experimental React Router RSC API](https://remix.run/blog/rsc-preview). React Router now provides [official RSC support](https://reactrouter.com/how-to/react-server-components), so it's recommended to follow React Router's official documentation for the latest integration.
|
|
27
26
|
- [`./examples/basic`](./examples/basic)
|
|
28
27
|
- This is mainly used for e2e testing and include various advanced RSC usages (e.g. `"use cache"` example).
|
|
29
|
-
It also uses a high level `@vitejs/plugin-rsc/extra/{rsc,ssr,browser}` API for quick setup.
|
|
30
28
|
- [`./examples/ssg`](./examples/ssg)
|
|
31
29
|
- Static site generation (SSG) example with MDX and client components for interactivity.
|
|
32
30
|
|
|
@@ -419,7 +417,10 @@ export default defineConfig({
|
|
|
419
417
|
})
|
|
420
418
|
```
|
|
421
419
|
|
|
422
|
-
##
|
|
420
|
+
## High level API
|
|
421
|
+
|
|
422
|
+
> [!NOTE]
|
|
423
|
+
> High level API is deprecated. Please write on your own `@vitejs/plugin-rsc/{rsc,ssr,browser}` integration.
|
|
423
424
|
|
|
424
425
|
This is a wrapper of `react-server-dom` API and helper API to setup a minimal RSC app without writing own framework code like [`./examples/starter/src/framework`](./examples/starter/src/framework/). See [`./examples/basic`](./examples/basic/) for how this API is used.
|
|
425
426
|
|
|
@@ -5,7 +5,7 @@ import * as clientReferences from "virtual:vite-rsc/client-references";
|
|
|
5
5
|
initialize();
|
|
6
6
|
function initialize() {
|
|
7
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));
|
|
8
|
+
if (!import.meta.env.__vite_rsc_build__) return __vite_rsc_raw_import__(withTrailingSlash(import.meta.env.BASE_URL) + id.slice(1));
|
|
9
9
|
else {
|
|
10
10
|
const import_ = clientReferences.default[id];
|
|
11
11
|
if (!import_) throw new Error(`client reference not found '${id}'`);
|
|
@@ -13,5 +13,9 @@ function initialize() {
|
|
|
13
13
|
}
|
|
14
14
|
} });
|
|
15
15
|
}
|
|
16
|
+
function withTrailingSlash(path) {
|
|
17
|
+
if (path[path.length - 1] !== "/") return `${path}/`;
|
|
18
|
+
return path;
|
|
19
|
+
}
|
|
16
20
|
|
|
17
21
|
//#endregion
|
|
@@ -5,8 +5,6 @@ declare function createFromReadableStream<T>(stream: ReadableStream<Uint8Array>,
|
|
|
5
5
|
declare function createFromFetch<T>(promiseForResponse: Promise<Response>, options?: object): Promise<T>;
|
|
6
6
|
declare const encodeReply: (v: unknown[], options?: unknown) => Promise<string | FormData>;
|
|
7
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
8
|
declare function callServer(...args: any[]): any;
|
|
11
9
|
declare function setServerCallback(fn: CallServerCallback): void;
|
|
12
10
|
declare const createTemporaryReferenceSet: () => unknown;
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { CallServerCallback } from "./index-BHqtj9tT.js";
|
|
2
2
|
import { setRequireModule } from "./browser-Dw18EFgE.js";
|
|
3
|
-
import { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setServerCallback } from "./browser-
|
|
3
|
+
import { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setServerCallback } from "./browser-CeSkQWD5.js";
|
|
4
4
|
export { CallServerCallback, callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setRequireModule, setServerCallback };
|
package/dist/browser.js
CHANGED
|
@@ -2,6 +2,6 @@ import "./dist-DEF94lDJ.js";
|
|
|
2
2
|
import "./shared-CEyKoKAb.js";
|
|
3
3
|
import { setRequireModule } from "./browser-QWbIPyhO.js";
|
|
4
4
|
import { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setServerCallback } from "./browser-D8OPzpF5.js";
|
|
5
|
-
import "./browser-
|
|
5
|
+
import "./browser-C1Q4O7AS.js";
|
|
6
6
|
|
|
7
7
|
export { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setRequireModule, setServerCallback };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/rsc-html-stream@0.0.
|
|
1
|
+
//#region ../../node_modules/.pnpm/rsc-html-stream@0.0.7/node_modules/rsc-html-stream/client.js
|
|
2
2
|
let encoder = new TextEncoder();
|
|
3
3
|
let streamController;
|
|
4
4
|
let rscStream = new ReadableStream({ start(controller) {
|
package/dist/extra/browser.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import { RscPayload } from "../rsc-
|
|
1
|
+
import { RscPayload } from "../rsc-DryRyKqc.js";
|
|
2
2
|
|
|
3
3
|
//#region src/extra/browser.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Use `@vitejs/plugin-rsc/browser` API instead.
|
|
7
|
+
*/
|
|
4
8
|
declare function hydrate(): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Use `@vitejs/plugin-rsc/browser` API instead.
|
|
11
|
+
*/
|
|
5
12
|
declare function fetchRSC(request: string | URL | Request): Promise<RscPayload["root"]>;
|
|
6
13
|
//#endregion
|
|
7
14
|
export { fetchRSC, hydrate };
|
package/dist/extra/browser.js
CHANGED
|
@@ -2,13 +2,16 @@ import "../dist-DEF94lDJ.js";
|
|
|
2
2
|
import "../shared-CEyKoKAb.js";
|
|
3
3
|
import "../browser-QWbIPyhO.js";
|
|
4
4
|
import { createFromFetch, createFromReadableStream, createTemporaryReferenceSet, encodeReply, setServerCallback } from "../browser-D8OPzpF5.js";
|
|
5
|
-
import "../browser-
|
|
6
|
-
import { rscStream } from "../client-
|
|
5
|
+
import "../browser-C1Q4O7AS.js";
|
|
6
|
+
import { rscStream } from "../client-CPc-spDn.js";
|
|
7
7
|
import React from "react";
|
|
8
8
|
import ReactDomClient from "react-dom/client";
|
|
9
9
|
import { jsx } from "react/jsx-runtime";
|
|
10
10
|
|
|
11
11
|
//#region src/extra/browser.tsx
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Use `@vitejs/plugin-rsc/browser` API instead.
|
|
14
|
+
*/
|
|
12
15
|
async function hydrate() {
|
|
13
16
|
const callServer = async (id, args) => {
|
|
14
17
|
const url = new URL(window.location.href);
|
|
@@ -45,6 +48,9 @@ async function hydrate() {
|
|
|
45
48
|
window.history.replaceState({}, "", window.location.href);
|
|
46
49
|
});
|
|
47
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* @deprecated Use `@vitejs/plugin-rsc/browser` API instead.
|
|
53
|
+
*/
|
|
48
54
|
async function fetchRSC(request) {
|
|
49
55
|
const payload = await createFromFetch(fetch(request));
|
|
50
56
|
return payload.root;
|
package/dist/extra/rsc.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RscPayload, renderRequest } from "../rsc-
|
|
1
|
+
import { RscPayload, renderRequest } from "../rsc-DryRyKqc.js";
|
|
2
2
|
export { RscPayload, renderRequest };
|
package/dist/extra/rsc.js
CHANGED
|
@@ -3,10 +3,13 @@ import "../shared-CEyKoKAb.js";
|
|
|
3
3
|
import "../encryption-utils-BDwwcMVT.js";
|
|
4
4
|
import { loadServerAction } from "../rsc-DKA6wwTB.js";
|
|
5
5
|
import { createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, renderToReadableStream } from "../rsc-DHfL29FT.js";
|
|
6
|
-
import "../rsc-
|
|
6
|
+
import "../rsc-BIUd01vh.js";
|
|
7
7
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
|
|
9
9
|
//#region src/extra/rsc.tsx
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use `@vitejs/plugin-rsc/rsc` API instead.
|
|
12
|
+
*/
|
|
10
13
|
async function renderRequest(request, root, options) {
|
|
11
14
|
function RscRoot() {
|
|
12
15
|
const nonceMeta = options?.nonce && /* @__PURE__ */ jsx("meta", {
|
package/dist/extra/ssr.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { ReactFormState } from "react-dom/client";
|
|
2
2
|
|
|
3
3
|
//#region src/extra/ssr.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Use `@vitejs/plugin-rsc/ssr` API instead.
|
|
7
|
+
*/
|
|
4
8
|
declare function renderHtml(rscStream: ReadableStream<Uint8Array>, options?: {
|
|
5
9
|
formState?: ReactFormState;
|
|
6
10
|
nonce?: string;
|
package/dist/extra/ssr.js
CHANGED
|
@@ -2,13 +2,16 @@ import "../dist-DEF94lDJ.js";
|
|
|
2
2
|
import "../shared-CEyKoKAb.js";
|
|
3
3
|
import "../ssr-BOIYlvSn.js";
|
|
4
4
|
import { createFromReadableStream } from "../ssr-D5pxP29F.js";
|
|
5
|
-
import "../ssr-
|
|
6
|
-
import { injectRSCPayload } from "../server-
|
|
5
|
+
import "../ssr-DNwSdZ9T.js";
|
|
6
|
+
import { injectRSCPayload } from "../server-C50j-DRF.js";
|
|
7
7
|
import React from "react";
|
|
8
8
|
import { jsx } from "react/jsx-runtime";
|
|
9
9
|
import ReactDomServer from "react-dom/server.edge";
|
|
10
10
|
|
|
11
11
|
//#region src/extra/ssr.tsx
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Use `@vitejs/plugin-rsc/ssr` API instead.
|
|
14
|
+
*/
|
|
12
15
|
async function renderHtml(rscStream, options) {
|
|
13
16
|
const [rscStream1, rscStream2] = rscStream.tee();
|
|
14
17
|
let payload;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RscPluginOptions, vitePluginRsc } from "./plugin-
|
|
1
|
+
import { RscPluginOptions, vitePluginRsc } from "./plugin-CCrsoChj.js";
|
|
2
2
|
import MagicString from "magic-string";
|
|
3
3
|
import { Program } from "estree";
|
|
4
4
|
|
|
@@ -21,4 +21,4 @@ declare function transformHoistInlineDirective(input: string, ast: Program, {
|
|
|
21
21
|
names: string[];
|
|
22
22
|
};
|
|
23
23
|
//#endregion
|
|
24
|
-
export { RscPluginOptions, vitePluginRsc as default, transformHoistInlineDirective };
|
|
24
|
+
export { type RscPluginOptions, vitePluginRsc as default, transformHoistInlineDirective };
|
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-DgH7V82E.js";
|
|
4
4
|
import "./encryption-utils-BDwwcMVT.js";
|
|
5
5
|
import "./rpc-tGuLT8PD.js";
|
|
6
6
|
import "./vite-utils-CcqBE-C4.js";
|
|
@@ -45,30 +45,30 @@ type RscPluginOptions = {
|
|
|
45
45
|
keepUseCientProxy?: boolean;
|
|
46
46
|
};
|
|
47
47
|
declare function vitePluginRsc(rscPluginOptions?: RscPluginOptions): Plugin[];
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
declare class RuntimeAsset {
|
|
49
|
+
runtime: string;
|
|
50
|
+
constructor(value: string);
|
|
51
|
+
}
|
|
51
52
|
type AssetsManifest = {
|
|
52
|
-
bootstrapScriptContent: string;
|
|
53
|
+
bootstrapScriptContent: string | RuntimeAsset;
|
|
53
54
|
clientReferenceDeps: Record<string, AssetDeps>;
|
|
54
|
-
serverResources?: Record<string,
|
|
55
|
-
css: string[];
|
|
56
|
-
}>;
|
|
55
|
+
serverResources?: Record<string, Pick<AssetDeps, "css">>;
|
|
57
56
|
};
|
|
58
57
|
type AssetDeps = {
|
|
58
|
+
js: (string | RuntimeAsset)[];
|
|
59
|
+
css: (string | RuntimeAsset)[];
|
|
60
|
+
};
|
|
61
|
+
type ResolvedAssetsManifest = {
|
|
62
|
+
bootstrapScriptContent: string;
|
|
63
|
+
clientReferenceDeps: Record<string, ResolvedAssetDeps>;
|
|
64
|
+
serverResources?: Record<string, Pick<ResolvedAssetDeps, "css">>;
|
|
65
|
+
};
|
|
66
|
+
type ResolvedAssetDeps = {
|
|
59
67
|
js: string[];
|
|
60
68
|
css: string[];
|
|
61
69
|
};
|
|
62
|
-
//
|
|
63
|
-
// support findSourceMapURL
|
|
64
|
-
// https://github.com/facebook/react/pull/29708
|
|
65
|
-
// https://github.com/facebook/react/pull/30741
|
|
66
|
-
//
|
|
67
70
|
declare function vitePluginFindSourceMapURL(): Plugin[];
|
|
68
71
|
declare function findSourceMapURL(server: ViteDevServer, filename: string, environmentName: string): Promise<object | undefined>;
|
|
69
|
-
//
|
|
70
|
-
// css support
|
|
71
|
-
//
|
|
72
72
|
declare function vitePluginRscCss(rscCssOptions?: Pick<RscPluginOptions, "rscCssTransform">): Plugin[];
|
|
73
73
|
declare function transformRscCssExport(options: {
|
|
74
74
|
ast: Awaited<ReturnType<typeof parseAstAsync>>;
|
|
@@ -85,4 +85,4 @@ declare function transformRscCssExport(options: {
|
|
|
85
85
|
*/
|
|
86
86
|
declare function __fix_cloudflare(): Plugin;
|
|
87
87
|
//#endregion
|
|
88
|
-
export { AssetDeps, AssetsManifest, RscPluginOptions, __fix_cloudflare, findSourceMapURL, transformRscCssExport, vitePluginFindSourceMapURL, vitePluginRsc, vitePluginRscCss };
|
|
88
|
+
export { AssetDeps, AssetsManifest, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginOptions, __fix_cloudflare, findSourceMapURL, transformRscCssExport, vitePluginFindSourceMapURL, vitePluginRsc, vitePluginRscCss };
|
|
@@ -414,7 +414,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
414
414
|
clientReferenceMetaMap = sortObject(clientReferenceMetaMap);
|
|
415
415
|
serverResourcesMetaMap = sortObject(serverResourcesMetaMap);
|
|
416
416
|
await builder.build(builder.environments.client);
|
|
417
|
-
const assetsManifestCode = `export default ${
|
|
417
|
+
const assetsManifestCode = `export default ${serializeValueWithRuntime(buildAssetsManifest)}`;
|
|
418
418
|
const manifestPath = path.join(builder.environments.rsc.config.build.outDir, BUILD_ASSETS_MANIFEST_NAME);
|
|
419
419
|
fs.writeFileSync(manifestPath, assetsManifestCode);
|
|
420
420
|
return;
|
|
@@ -456,7 +456,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
456
456
|
const resolved = await environment.pluginContainer.resolveId(source);
|
|
457
457
|
assert(resolved, `[vite-rsc] failed to resolve server handler '${source}'`);
|
|
458
458
|
const mod = await environment.runner.import(resolved.id);
|
|
459
|
-
createRequestListener(mod.default)(req, res);
|
|
459
|
+
await createRequestListener(mod.default)(req, res);
|
|
460
460
|
} catch (e) {
|
|
461
461
|
next(e);
|
|
462
462
|
}
|
|
@@ -473,8 +473,9 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
473
473
|
const entryFile = path.join(config.environments[options.environmentName].build.outDir, `${options.entryName}.js`);
|
|
474
474
|
const entry = pathToFileURL(entryFile).href;
|
|
475
475
|
const mod = await import(
|
|
476
|
-
|
|
477
|
-
|
|
476
|
+
/* @vite-ignore */
|
|
477
|
+
entry
|
|
478
|
+
);
|
|
478
479
|
const handler = createRequestListener(mod.default);
|
|
479
480
|
server$1.middlewares.use((req, _res, next) => {
|
|
480
481
|
delete req.headers["accept-encoding"];
|
|
@@ -483,7 +484,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
483
484
|
return () => {
|
|
484
485
|
server$1.middlewares.use(async (req, res, next) => {
|
|
485
486
|
try {
|
|
486
|
-
handler(req, res);
|
|
487
|
+
await handler(req, res);
|
|
487
488
|
} catch (e) {
|
|
488
489
|
next(e);
|
|
489
490
|
}
|
|
@@ -642,7 +643,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
642
643
|
assert(this.environment.mode === "dev");
|
|
643
644
|
const entryUrl = assetsURL("@id/__x00__" + VIRTUAL_ENTRIES.browser);
|
|
644
645
|
const manifest = {
|
|
645
|
-
bootstrapScriptContent: `import(${
|
|
646
|
+
bootstrapScriptContent: `import(${serializeValueWithRuntime(entryUrl)})`,
|
|
646
647
|
clientReferenceDeps: {}
|
|
647
648
|
};
|
|
648
649
|
return `export default ${JSON.stringify(manifest, null, 2)}`;
|
|
@@ -680,8 +681,11 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
680
681
|
};
|
|
681
682
|
clientReferenceDeps[meta.referenceKey] = assetsURLOfDeps(mergeAssetDeps(deps, entry.deps));
|
|
682
683
|
}
|
|
684
|
+
let bootstrapScriptContent;
|
|
685
|
+
if (typeof entryUrl === "string") bootstrapScriptContent = `import(${JSON.stringify(entryUrl)})`;
|
|
686
|
+
else bootstrapScriptContent = new RuntimeAsset(`"import(" + JSON.stringify(${entryUrl.runtime}) + ")"`);
|
|
683
687
|
buildAssetsManifest = {
|
|
684
|
-
bootstrapScriptContent
|
|
688
|
+
bootstrapScriptContent,
|
|
685
689
|
clientReferenceDeps,
|
|
686
690
|
serverResources
|
|
687
691
|
};
|
|
@@ -698,7 +702,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
698
702
|
},
|
|
699
703
|
writeBundle() {
|
|
700
704
|
if (this.environment.name === "ssr") {
|
|
701
|
-
const assetsManifestCode = `export default ${
|
|
705
|
+
const assetsManifestCode = `export default ${serializeValueWithRuntime(buildAssetsManifest)}`;
|
|
702
706
|
for (const name of ["ssr", "rsc"]) {
|
|
703
707
|
const manifestPath = path.join(config.environments[name].build.outDir, BUILD_ASSETS_MANIFEST_NAME);
|
|
704
708
|
fs.writeFileSync(manifestPath, assetsManifestCode);
|
|
@@ -1084,13 +1088,50 @@ function generateDynamicImportCode(map) {
|
|
|
1084
1088
|
let code = Object.entries(map).map(([key, id]) => `${JSON.stringify(key)}: () => import(${JSON.stringify(id)}),`).join("\n");
|
|
1085
1089
|
return `export default {${code}};\n`;
|
|
1086
1090
|
}
|
|
1091
|
+
var RuntimeAsset = class {
|
|
1092
|
+
runtime;
|
|
1093
|
+
constructor(value) {
|
|
1094
|
+
this.runtime = value;
|
|
1095
|
+
}
|
|
1096
|
+
};
|
|
1097
|
+
function serializeValueWithRuntime(value) {
|
|
1098
|
+
const replacements = [];
|
|
1099
|
+
let result = JSON.stringify(value, (_key, value$1) => {
|
|
1100
|
+
if (value$1 instanceof RuntimeAsset) {
|
|
1101
|
+
const placeholder = `__runtime_placeholder_${replacements.length}__`;
|
|
1102
|
+
replacements.push([placeholder, value$1.runtime]);
|
|
1103
|
+
return placeholder;
|
|
1104
|
+
}
|
|
1105
|
+
return value$1;
|
|
1106
|
+
}, 2);
|
|
1107
|
+
for (const [placeholder, runtime] of replacements) result = result.replace(`"${placeholder}"`, runtime);
|
|
1108
|
+
return result;
|
|
1109
|
+
}
|
|
1087
1110
|
function assetsURL(url) {
|
|
1111
|
+
if (config.command === "build" && typeof config.experimental?.renderBuiltUrl === "function") {
|
|
1112
|
+
const result = config.experimental.renderBuiltUrl(url, {
|
|
1113
|
+
type: "asset",
|
|
1114
|
+
hostType: "js",
|
|
1115
|
+
ssr: true,
|
|
1116
|
+
hostId: ""
|
|
1117
|
+
});
|
|
1118
|
+
if (typeof result === "object") {
|
|
1119
|
+
if (result.runtime) return new RuntimeAsset(result.runtime);
|
|
1120
|
+
assert(!result.relative, "\"result.relative\" not supported on renderBuiltUrl() for RSC");
|
|
1121
|
+
} else if (result) return result;
|
|
1122
|
+
}
|
|
1088
1123
|
return config.base + url;
|
|
1089
1124
|
}
|
|
1090
1125
|
function assetsURLOfDeps(deps) {
|
|
1091
1126
|
return {
|
|
1092
|
-
js: deps.js.map((href) =>
|
|
1093
|
-
|
|
1127
|
+
js: deps.js.map((href) => {
|
|
1128
|
+
assert(typeof href === "string");
|
|
1129
|
+
return assetsURL(href);
|
|
1130
|
+
}),
|
|
1131
|
+
css: deps.css.map((href) => {
|
|
1132
|
+
assert(typeof href === "string");
|
|
1133
|
+
return assetsURL(href);
|
|
1134
|
+
})
|
|
1094
1135
|
};
|
|
1095
1136
|
}
|
|
1096
1137
|
function mergeAssetDeps(a, b) {
|
|
@@ -1262,7 +1303,7 @@ function vitePluginRscCss(rscCssOptions) {
|
|
|
1262
1303
|
const result = collectCss(server.environments.ssr, mod.id);
|
|
1263
1304
|
for (const file of [mod.file, ...result.visitedFiles]) this.addWatchFile(file);
|
|
1264
1305
|
const hrefs = result.hrefs.map((href) => assetsURL(href.slice(1)));
|
|
1265
|
-
return `export default ${
|
|
1306
|
+
return `export default ${serializeValueWithRuntime(hrefs)}`;
|
|
1266
1307
|
}
|
|
1267
1308
|
}
|
|
1268
1309
|
},
|
|
@@ -1324,7 +1365,7 @@ function vitePluginRscCss(rscCssOptions) {
|
|
|
1324
1365
|
css: cssHrefs,
|
|
1325
1366
|
js: jsHrefs
|
|
1326
1367
|
});
|
|
1327
|
-
return generateResourcesCode(
|
|
1368
|
+
return generateResourcesCode(serializeValueWithRuntime(deps));
|
|
1328
1369
|
} else {
|
|
1329
1370
|
const key = normalizePath(path.relative(config.root, importer));
|
|
1330
1371
|
serverResourcesMetaMap[importer] = { key };
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AssetDeps, AssetsManifest, RscPluginOptions, __fix_cloudflare, findSourceMapURL, transformRscCssExport, vitePluginFindSourceMapURL, vitePluginRsc, vitePluginRscCss } from "./plugin-
|
|
2
|
-
export { AssetDeps, AssetsManifest, RscPluginOptions, __fix_cloudflare, vitePluginRsc as default, findSourceMapURL, transformRscCssExport, vitePluginFindSourceMapURL, vitePluginRscCss };
|
|
1
|
+
import { AssetDeps, AssetsManifest, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginOptions, __fix_cloudflare, findSourceMapURL, transformRscCssExport, vitePluginFindSourceMapURL, vitePluginRsc, vitePluginRscCss } from "./plugin-CCrsoChj.js";
|
|
2
|
+
export { AssetDeps, AssetsManifest, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginOptions, __fix_cloudflare, vitePluginRsc as default, findSourceMapURL, transformRscCssExport, vitePluginFindSourceMapURL, vitePluginRscCss };
|
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-DgH7V82E.js";
|
|
4
4
|
import "./encryption-utils-BDwwcMVT.js";
|
|
5
5
|
import "./rpc-tGuLT8PD.js";
|
|
6
6
|
import "./vite-utils-CcqBE-C4.js";
|
package/dist/react/browser.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { CallServerCallback } from "../index-BHqtj9tT.js";
|
|
2
2
|
import { setRequireModule } from "../browser-Dw18EFgE.js";
|
|
3
|
-
import { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setServerCallback } from "../browser-
|
|
3
|
+
import { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setServerCallback } from "../browser-CeSkQWD5.js";
|
|
4
4
|
export { CallServerCallback, callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setRequireModule, setServerCallback };
|
|
@@ -28,8 +28,9 @@ initialize();
|
|
|
28
28
|
function initialize() {
|
|
29
29
|
setRequireModule({ load: async (id) => {
|
|
30
30
|
if (!import.meta.env.__vite_rsc_build__) return import(
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
/* @vite-ignore */
|
|
32
|
+
id
|
|
33
|
+
);
|
|
33
34
|
else {
|
|
34
35
|
const import_ = serverReferences[id];
|
|
35
36
|
if (!import_) throw new Error(`server reference not found '${id}'`);
|
|
@@ -6,6 +6,9 @@ type RscPayload = {
|
|
|
6
6
|
formState?: ReactFormState;
|
|
7
7
|
returnValue?: unknown;
|
|
8
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Use `@vitejs/plugin-rsc/rsc` API instead.
|
|
11
|
+
*/
|
|
9
12
|
declare function renderRequest(request: Request, root: React.ReactNode, options?: {
|
|
10
13
|
nonce?: string;
|
|
11
14
|
}): Promise<Response>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { rscStream } from "../client-
|
|
1
|
+
import { rscStream } from "../client-CPc-spDn.js";
|
|
2
2
|
|
|
3
3
|
//#region src/rsc-html-stream/browser.ts
|
|
4
|
+
/** @deprecated use `rsc-html-stream/client` instead */
|
|
4
5
|
const getRscStreamFromHtml = () => rscStream;
|
|
5
6
|
|
|
6
7
|
//#endregion
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { injectRSCPayload } from "../server-
|
|
1
|
+
import { injectRSCPayload } from "../server-C50j-DRF.js";
|
|
2
2
|
|
|
3
3
|
//#region src/rsc-html-stream/ssr.ts
|
|
4
|
+
/** @deprecated use `rsc-html-stream/server` instead */
|
|
4
5
|
const injectRscStreamToHtml = (stream, options) => injectRSCPayload(stream, options);
|
|
5
6
|
|
|
6
7
|
//#endregion
|
package/dist/rsc.d.ts
CHANGED
|
@@ -3,10 +3,6 @@ import { createClientManifest, createServerManifest, loadServerAction, setRequir
|
|
|
3
3
|
import { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, registerClientReference, registerServerReference, renderToReadableStream } from "./rsc-DgrejoNf.js";
|
|
4
4
|
|
|
5
5
|
//#region src/utils/encryption-runtime.d.ts
|
|
6
|
-
// based on
|
|
7
|
-
// https://github.com/parcel-bundler/parcel/blob/9855f558a69edde843b1464f39a6010f6b421efe/packages/transformers/js/src/rsc-utils.js
|
|
8
|
-
// https://github.com/vercel/next.js/blob/c10c10daf9e95346c31c24dc49d6b7cda48b5bc8/packages/next/src/server/app-render/encryption.ts
|
|
9
|
-
// https://github.com/vercel/next.js/pull/56377
|
|
10
6
|
declare function encryptActionBoundArgs(originalValue: unknown): Promise<string>;
|
|
11
7
|
declare function decryptActionBoundArgs(encrypted: ReturnType<typeof encryptActionBoundArgs>): Promise<unknown>;
|
|
12
8
|
//#endregion
|
package/dist/rsc.js
CHANGED
|
@@ -3,6 +3,6 @@ import "./shared-CEyKoKAb.js";
|
|
|
3
3
|
import "./encryption-utils-BDwwcMVT.js";
|
|
4
4
|
import { createClientManifest, createServerManifest, loadServerAction, setRequireModule } from "./rsc-DKA6wwTB.js";
|
|
5
5
|
import { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, registerClientReference, registerServerReference, renderToReadableStream } from "./rsc-DHfL29FT.js";
|
|
6
|
-
import { decryptActionBoundArgs, encryptActionBoundArgs } from "./rsc-
|
|
6
|
+
import { decryptActionBoundArgs, encryptActionBoundArgs } from "./rsc-BIUd01vh.js";
|
|
7
7
|
|
|
8
8
|
export { createClientManifest, createClientTemporaryReferenceSet, createFromReadableStream, createServerManifest, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, decryptActionBoundArgs, encodeReply, encryptActionBoundArgs, loadServerAction, registerClientReference, registerServerReference, renderToReadableStream, setRequireModule };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/rsc-html-stream@0.0.
|
|
1
|
+
//#region ../../node_modules/.pnpm/rsc-html-stream@0.0.7/node_modules/rsc-html-stream/server.js
|
|
2
2
|
const encoder = new TextEncoder();
|
|
3
3
|
const trailer = "</body></html>";
|
|
4
4
|
function injectRSCPayload(rscStream, options) {
|
|
@@ -28,7 +28,13 @@ function injectRSCPayload(rscStream, options) {
|
|
|
28
28
|
buffered.push(chunk);
|
|
29
29
|
if (timeout) return;
|
|
30
30
|
timeout = setTimeout(async () => {
|
|
31
|
-
|
|
31
|
+
try {
|
|
32
|
+
flushBufferedChunks(controller);
|
|
33
|
+
} catch (e) {
|
|
34
|
+
controller.error(e);
|
|
35
|
+
resolveFlightDataPromise();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
32
38
|
if (!startedRSC) {
|
|
33
39
|
startedRSC = true;
|
|
34
40
|
writeRSCStream(rscStream, controller, nonce).catch((err) => controller.error(err)).then(resolveFlightDataPromise);
|
|
@@ -9,11 +9,13 @@ function initialize() {
|
|
|
9
9
|
setRequireModule({ load: async (id) => {
|
|
10
10
|
if (!import.meta.env.__vite_rsc_build__) {
|
|
11
11
|
const mod = await import(
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
/* @vite-ignore */
|
|
13
|
+
id
|
|
14
|
+
);
|
|
14
15
|
const modCss = await import(
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
/* @vite-ignore */
|
|
17
|
+
"/@id/__x00__virtual:vite-rsc/css/dev-ssr/" + id
|
|
18
|
+
);
|
|
17
19
|
return wrapResourceProxy(mod, {
|
|
18
20
|
js: [],
|
|
19
21
|
css: modCss.default
|
package/dist/ssr.js
CHANGED
|
@@ -2,6 +2,6 @@ import "./dist-DEF94lDJ.js";
|
|
|
2
2
|
import "./shared-CEyKoKAb.js";
|
|
3
3
|
import { createServerConsumerManifest, setRequireModule } from "./ssr-BOIYlvSn.js";
|
|
4
4
|
import { callServer, createFromReadableStream, createServerReference, findSourceMapURL } from "./ssr-D5pxP29F.js";
|
|
5
|
-
import "./ssr-
|
|
5
|
+
import "./ssr-DNwSdZ9T.js";
|
|
6
6
|
|
|
7
7
|
export { callServer, createFromReadableStream, createServerConsumerManifest, createServerReference, findSourceMapURL, setRequireModule };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitejs/plugin-rsc",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.13",
|
|
4
4
|
"description": "React Server Components (RSC) support for Vite.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -48,19 +48,19 @@
|
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@hiogawa/utils": "^1.7.0",
|
|
51
|
-
"@playwright/test": "^1.
|
|
51
|
+
"@playwright/test": "^1.54.1",
|
|
52
52
|
"@tsconfig/strictest": "^2.0.5",
|
|
53
53
|
"@types/estree": "^1.0.8",
|
|
54
|
-
"@types/node": "^22.16.
|
|
54
|
+
"@types/node": "^22.16.5",
|
|
55
55
|
"@types/react": "^19.1.8",
|
|
56
56
|
"@types/react-dom": "^19.1.6",
|
|
57
57
|
"@vitejs/plugin-react": "workspace:*",
|
|
58
58
|
"react": "^19.1.0",
|
|
59
59
|
"react-dom": "^19.1.0",
|
|
60
60
|
"react-server-dom-webpack": "^19.1.0",
|
|
61
|
-
"rsc-html-stream": "^0.0.
|
|
61
|
+
"rsc-html-stream": "^0.0.7",
|
|
62
62
|
"tinyexec": "^1.0.1",
|
|
63
|
-
"tsdown": "^0.
|
|
63
|
+
"tsdown": "^0.13.0"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"react": "*",
|