@vitejs/plugin-rsc 0.5.27 → 0.5.28
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 +34 -18
- package/dist/browser.d.ts +3 -3
- package/dist/{cjs-BspwazE6.js → cjs-Cxg_7upE.js} +3 -3
- package/dist/client-BrwlzXgg.d.ts +19 -0
- package/dist/core/browser.d.ts +1 -1
- package/dist/core/browser.js +2 -2
- package/dist/core/plugin.d.ts +0 -1
- package/dist/core/rsc.d.ts +1 -19
- package/dist/core/rsc.js +20 -4
- package/dist/core/ssr.d.ts +1 -2
- package/dist/core/ssr.js +2 -2
- package/dist/{encryption-utils-CRBgMeBq.js → encryption-utils-BNbYHtC4.js} +1 -1
- package/dist/{index-DViteJjw.d.ts → index-BjJe9jqG.d.ts} +35 -12
- package/dist/{index-BrXJaflA.d.ts → index-CqNlZcWp.d.ts} +12 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{picocolors-CEw5D0BV.js → picocolors-DFVOi1sR.js} +4 -2
- package/dist/{plugin-BK29Va7z.js → plugin-BOTpkess.js} +29 -15
- package/dist/{plugin-Bm-Fb4g7.d.ts → plugin-CaLiN8ED.d.ts} +71 -64
- package/dist/plugin.d.ts +2 -2
- package/dist/plugin.js +1 -1
- package/dist/plugins/cjs.d.ts +0 -1
- package/dist/plugins/cjs.js +1 -1
- package/dist/react/browser.d.ts +2 -3
- package/dist/react/rsc/client.d.ts +2 -0
- package/dist/react/rsc/client.js +16 -0
- package/dist/react/rsc/server.d.ts +3 -0
- package/dist/react/rsc/server.js +20 -0
- package/dist/react/rsc.d.ts +3 -24
- package/dist/react/rsc.js +3 -31
- package/dist/react/ssr.d.ts +4 -3
- package/dist/react/ssr.js +3 -1
- package/dist/rsc/client.d.ts +2 -0
- package/dist/rsc/client.js +3 -0
- package/dist/rsc/server.d.ts +16 -0
- package/dist/rsc/server.js +20 -0
- package/dist/rsc-CGkkhLG3.d.ts +21 -0
- package/dist/rsc.d.ts +4 -16
- package/dist/rsc.js +4 -41
- package/dist/{scope-Bwt9GVLP.js → scope-Do08R7C2.js} +1 -1
- package/dist/server-DTkvSyJT.d.ts +20 -0
- package/dist/shared-D42sHPD1.js +25 -0
- package/dist/{shared-BVLpj0Y8.js → shared-Y4B6DJ99.js} +2 -1
- package/dist/ssr.d.ts +12 -12
- package/dist/ssr.js +12 -7
- package/dist/transforms/index.d.ts +1 -1
- package/dist/transforms/index.js +39 -28
- package/dist/utils/encryption-runtime.js +5 -5
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.browser.development.js +2 -2
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.node.development.js +70 -33
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.node.production.js +69 -29
- package/dist/vendor/react-server-dom/package.json +3 -3
- package/package.json +11 -11
- /package/dist/{browser-C_qguV-a.d.ts → browser-DI_Wyg5Y.d.ts} +0 -0
- /package/dist/{dist-rz-Bnebz.js → dist-uqdtSkzK.js} +0 -0
- /package/dist/{shared-DeahDSXi.js → shared-B6H2TbnP.js} +0 -0
package/README.md
CHANGED
|
@@ -444,14 +444,31 @@ export default defineConfig({
|
|
|
444
444
|
|
|
445
445
|
## RSC runtime (react-server-dom) API
|
|
446
446
|
|
|
447
|
-
### `@vitejs/plugin-rsc/rsc`
|
|
447
|
+
### `@vitejs/plugin-rsc/rsc/server`
|
|
448
448
|
|
|
449
|
-
This module
|
|
449
|
+
This module provides Vite-integrated RSC runtime APIs based on
|
|
450
|
+
`react-server-dom/server.edge` for use in the RSC environment:
|
|
450
451
|
|
|
451
452
|
- `renderToReadableStream`: RSC serialization (React VDOM -> RSC stream)
|
|
452
|
-
- `
|
|
453
|
-
- `
|
|
454
|
-
- `
|
|
453
|
+
- `decodeAction/decodeReply/decodeFormState/loadServerAction`
|
|
454
|
+
- `registerClientReference/registerServerReference`
|
|
455
|
+
- `createTemporaryReferenceSet`
|
|
456
|
+
|
|
457
|
+
### `@vitejs/plugin-rsc/rsc/client`
|
|
458
|
+
|
|
459
|
+
This module provides Vite-integrated RSC runtime APIs based on
|
|
460
|
+
`react-server-dom/client.edge` for use in the RSC environment:
|
|
461
|
+
|
|
462
|
+
- `createFromReadableStream`: RSC deserialization (RSC stream -> React VDOM)
|
|
463
|
+
- `encodeReply`
|
|
464
|
+
- `createClientTemporaryReferenceSet`
|
|
465
|
+
|
|
466
|
+
Together, these APIs allow a React VDOM to be serialized, saved as an RSC stream, and later deserialized within the same `rsc` environment.
|
|
467
|
+
|
|
468
|
+
### `@vitejs/plugin-rsc/rsc`
|
|
469
|
+
|
|
470
|
+
This module re-exports `@vitejs/plugin-rsc/rsc/server` and
|
|
471
|
+
`@vitejs/plugin-rsc/rsc/client`.
|
|
455
472
|
|
|
456
473
|
#### Vite-specific extension: `renderToReadableStream` (experimental)
|
|
457
474
|
|
|
@@ -479,17 +496,23 @@ function renderToReadableStream<T>(
|
|
|
479
496
|
|
|
480
497
|
### `@vitejs/plugin-rsc/ssr`
|
|
481
498
|
|
|
482
|
-
This module
|
|
499
|
+
This module provides Vite-integrated RSC runtime APIs based on
|
|
500
|
+
`react-server-dom/client.edge` for use in the SSR environment:
|
|
483
501
|
|
|
484
|
-
- `createFromReadableStream`:
|
|
502
|
+
- `createFromReadableStream`: Deserializes an RSC stream into a React VDOM
|
|
503
|
+
- `encodeReply`: Serializes server function arguments
|
|
504
|
+
- `createTemporaryReferenceSet`: Creates a temporary reference set shared by deserialization and reply serialization
|
|
485
505
|
|
|
486
506
|
### `@vitejs/plugin-rsc/browser`
|
|
487
507
|
|
|
488
|
-
This module
|
|
508
|
+
This module provides Vite-integrated RSC runtime APIs based on
|
|
509
|
+
`react-server-dom/client.browser` for use in the browser environment:
|
|
489
510
|
|
|
490
|
-
- `createFromReadableStream`:
|
|
491
|
-
- `createFromFetch`:
|
|
492
|
-
- `encodeReply
|
|
511
|
+
- `createFromReadableStream`: Deserializes an RSC stream into a React VDOM
|
|
512
|
+
- `createFromFetch`: Deserializes an RSC response from a fetch promise
|
|
513
|
+
- `encodeReply`: Serializes server function arguments
|
|
514
|
+
- `createTemporaryReferenceSet`: Creates a temporary reference set shared by deserialization and reply serialization
|
|
515
|
+
- `setServerCallback`: Configures how server functions are called
|
|
493
516
|
|
|
494
517
|
## Tips
|
|
495
518
|
|
|
@@ -667,13 +690,6 @@ Note that while there are official npm packages [`server-only`](https://www.npmj
|
|
|
667
690
|
|
|
668
691
|
This build-time validation is enabled by default and can be disabled by setting `validateImports: false` in the plugin options.
|
|
669
692
|
|
|
670
|
-
## Architecture Documentation
|
|
671
|
-
|
|
672
|
-
For developers interested in the internal architecture:
|
|
673
|
-
|
|
674
|
-
- **[docs/architecture.md](docs/architecture.md)** - Build pipeline, data flow, and key components
|
|
675
|
-
- **[docs/bundler-comparison.md](docs/bundler-comparison.md)** - How different bundlers approach RSC
|
|
676
|
-
|
|
677
693
|
## Credits
|
|
678
694
|
|
|
679
695
|
This project builds on fundamental techniques and insights from pioneering Vite RSC implementations.
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as CallServerCallback } from "./index-
|
|
2
|
-
import { t as setRequireModule } from "./browser-
|
|
1
|
+
import { n as CallServerCallback } from "./index-CqNlZcWp.js";
|
|
2
|
+
import { t as setRequireModule } from "./browser-DI_Wyg5Y.js";
|
|
3
3
|
import { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setServerCallback } from "./react/browser.js";
|
|
4
|
-
export { CallServerCallback, callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setRequireModule, setServerCallback };
|
|
4
|
+
export { type CallServerCallback, callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setRequireModule, setServerCallback };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as createDebug } from "./dist-
|
|
2
|
-
import { t as buildScopeTree } from "./scope-
|
|
3
|
-
import { n as parseIdQuery } from "./shared-
|
|
1
|
+
import { t as createDebug } from "./dist-uqdtSkzK.js";
|
|
2
|
+
import { t as buildScopeTree } from "./scope-Do08R7C2.js";
|
|
3
|
+
import { n as parseIdQuery } from "./shared-B6H2TbnP.js";
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { a as CreateFromReadableStreamEdgeOptions, c as EncodeReplyFunction, r as ClientTemporaryReferenceSet } from "./index-CqNlZcWp.js";
|
|
2
|
+
//#region src/react/rsc/client.d.ts
|
|
3
|
+
declare function createFromReadableStream<T>(stream: ReadableStream<Uint8Array>, options?: CreateFromReadableStreamEdgeOptions, extraOptions?: {
|
|
4
|
+
/**
|
|
5
|
+
* Preserve server references for re-serialization without loading their modules.
|
|
6
|
+
* Preserved references cannot be invoked in the current RSC environment.
|
|
7
|
+
*
|
|
8
|
+
* Disabled by default because this API also decodes bound server action
|
|
9
|
+
* arguments, which must revive references as callable implementations.
|
|
10
|
+
*
|
|
11
|
+
* @experimental
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
preserveServerReferences?: boolean;
|
|
15
|
+
}): Promise<T>;
|
|
16
|
+
declare const encodeReply: EncodeReplyFunction;
|
|
17
|
+
declare const createClientTemporaryReferenceSet: () => ClientTemporaryReferenceSet;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { createFromReadableStream as n, encodeReply as r, createClientTemporaryReferenceSet as t };
|
package/dist/core/browser.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as setRequireModule } from "../browser-
|
|
1
|
+
import { t as setRequireModule } from "../browser-DI_Wyg5Y.js";
|
|
2
2
|
export { setRequireModule };
|
package/dist/core/browser.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as memoize } from "../dist-
|
|
2
|
-
import { a as
|
|
1
|
+
import { n as memoize } from "../dist-uqdtSkzK.js";
|
|
2
|
+
import { a as removeReferenceCacheTag, o as setInternalRequire } from "../shared-Y4B6DJ99.js";
|
|
3
3
|
//#region src/core/browser.ts
|
|
4
4
|
let init = false;
|
|
5
5
|
function setRequireModule(options) {
|
package/dist/core/plugin.d.ts
CHANGED
package/dist/core/rsc.d.ts
CHANGED
|
@@ -1,20 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/core/rsc.d.ts
|
|
4
|
-
declare function setRequireModule(options: {
|
|
5
|
-
load: (id: string) => unknown;
|
|
6
|
-
}): void;
|
|
7
|
-
declare function loadServerAction(id: string): Promise<Function>;
|
|
8
|
-
declare function createServerManifest(): BundlerConfig;
|
|
9
|
-
declare function createServerDecodeClientManifest(): ModuleMap;
|
|
10
|
-
declare function createClientManifest(options?: {
|
|
11
|
-
/**
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
onClientReference?: (metadata: {
|
|
15
|
-
id: string;
|
|
16
|
-
name: string;
|
|
17
|
-
}) => void;
|
|
18
|
-
}): BundlerConfig;
|
|
19
|
-
//#endregion
|
|
1
|
+
import { a as setRequireModule, i as loadServerAction, n as createServerDecodeClientManifest, r as createServerManifest, t as createClientManifest } from "../rsc-CGkkhLG3.js";
|
|
20
2
|
export { createClientManifest, createServerDecodeClientManifest, createServerManifest, loadServerAction, setRequireModule };
|
package/dist/core/rsc.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as tinyassert, n as memoize } from "../dist-
|
|
2
|
-
import { a as
|
|
1
|
+
import { i as tinyassert, n as memoize } from "../dist-uqdtSkzK.js";
|
|
2
|
+
import { a as removeReferenceCacheTag, i as createReferenceCacheTag, n as SERVER_REFERENCE_PREFIX, o as setInternalRequire, r as SERVER_REFERENCE_PRESERVE_PREFIX, t as SERVER_DECODE_CLIENT_PREFIX } from "../shared-Y4B6DJ99.js";
|
|
3
3
|
import * as ReactServer from "@vitejs/plugin-rsc/vendor/react-server-dom/server.edge";
|
|
4
4
|
//#region src/core/rsc.ts
|
|
5
5
|
let init = false;
|
|
@@ -11,6 +11,21 @@ function setRequireModule(options) {
|
|
|
11
11
|
return options.load(removeReferenceCacheTag(id));
|
|
12
12
|
};
|
|
13
13
|
globalThis.__vite_rsc_server_require__ = memoize(async (id) => {
|
|
14
|
+
if (id.startsWith("$$preserve:")) {
|
|
15
|
+
id = id.slice(SERVER_REFERENCE_PRESERVE_PREFIX.length);
|
|
16
|
+
id = removeReferenceCacheTag(id);
|
|
17
|
+
const target = {};
|
|
18
|
+
const getOrCreateServerReference = (name) => {
|
|
19
|
+
return target[name] ??= ReactServer.registerServerReference(() => {
|
|
20
|
+
throw new Error(`Unexpectedly decoded server reference '${id}#${name}' is called on server`);
|
|
21
|
+
}, id, name);
|
|
22
|
+
};
|
|
23
|
+
return new Proxy(target, { getOwnPropertyDescriptor(_target, name) {
|
|
24
|
+
if (typeof name !== "string" || name === "then") return Reflect.getOwnPropertyDescriptor(target, name);
|
|
25
|
+
getOrCreateServerReference(name);
|
|
26
|
+
return Reflect.getOwnPropertyDescriptor(target, name);
|
|
27
|
+
} });
|
|
28
|
+
}
|
|
14
29
|
if (id.startsWith("$$decode-client:")) {
|
|
15
30
|
id = id.slice(SERVER_DECODE_CLIENT_PREFIX.length);
|
|
16
31
|
id = removeReferenceCacheTag(id);
|
|
@@ -34,7 +49,8 @@ async function loadServerAction(id) {
|
|
|
34
49
|
const [file, name] = id.split("#");
|
|
35
50
|
return (await requireModule(file))[name];
|
|
36
51
|
}
|
|
37
|
-
function createServerManifest() {
|
|
52
|
+
function createServerManifest(options) {
|
|
53
|
+
const prefix = options?.preserveServerReferences ? SERVER_REFERENCE_PRESERVE_PREFIX : "";
|
|
38
54
|
const cacheTag = import.meta.env.DEV ? createReferenceCacheTag() : "";
|
|
39
55
|
return new Proxy({}, { get(_target, $$id, _receiver) {
|
|
40
56
|
tinyassert(typeof $$id === "string");
|
|
@@ -42,7 +58,7 @@ function createServerManifest() {
|
|
|
42
58
|
tinyassert(id);
|
|
43
59
|
tinyassert(name);
|
|
44
60
|
return {
|
|
45
|
-
id: SERVER_REFERENCE_PREFIX + id + cacheTag,
|
|
61
|
+
id: SERVER_REFERENCE_PREFIX + prefix + id + cacheTag,
|
|
46
62
|
name,
|
|
47
63
|
chunks: [],
|
|
48
64
|
async: true
|
package/dist/core/ssr.d.ts
CHANGED
package/dist/core/ssr.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as memoize } from "../dist-
|
|
2
|
-
import { a as
|
|
1
|
+
import { n as memoize } from "../dist-uqdtSkzK.js";
|
|
2
|
+
import { a as removeReferenceCacheTag, o as setInternalRequire } from "../shared-Y4B6DJ99.js";
|
|
3
3
|
//#region src/core/ssr.ts
|
|
4
4
|
let init = false;
|
|
5
5
|
function setRequireModule(options) {
|
|
@@ -52,7 +52,7 @@ async function generateEncryptionKey() {
|
|
|
52
52
|
return new Uint8Array(exported);
|
|
53
53
|
}
|
|
54
54
|
async function encryptBuffer(data, key) {
|
|
55
|
-
const iv = crypto.getRandomValues(new Uint8Array(16));
|
|
55
|
+
const iv = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16));
|
|
56
56
|
const encrypted = await crypto.subtle.encrypt({
|
|
57
57
|
name: "AES-GCM",
|
|
58
58
|
iv
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import MagicString from "magic-string";
|
|
2
|
-
|
|
3
2
|
//#region ../../node_modules/.pnpm/@types+estree@1.0.9/node_modules/@types/estree/index.d.ts
|
|
4
3
|
// This definition file follows a somewhat unusual format. ESTree allows
|
|
5
4
|
// runtime type checks based on the `type` parameter. In order to explain this
|
|
@@ -84,7 +83,8 @@ interface Directive extends BaseNode {
|
|
|
84
83
|
interface BaseFunction extends BaseNode {
|
|
85
84
|
params: Pattern[];
|
|
86
85
|
generator?: boolean | undefined;
|
|
87
|
-
async?: boolean | undefined;
|
|
86
|
+
async?: boolean | undefined;
|
|
87
|
+
// The body is either BlockStatement or Expression because arrow functions
|
|
88
88
|
// can have a body that's either. FunctionDeclarations and
|
|
89
89
|
// FunctionExpressions have only BlockStatement bodies.
|
|
90
90
|
body: BlockStatement | Expression;
|
|
@@ -405,7 +405,8 @@ interface TemplateElement extends BaseNode {
|
|
|
405
405
|
type: "TemplateElement";
|
|
406
406
|
tail: boolean;
|
|
407
407
|
value: {
|
|
408
|
-
/** It is null when the template literal is tagged and the text has an invalid escape (e.g. - tag`\unicode and \u{55}`) */
|
|
408
|
+
/** It is null when the template literal is tagged and the text has an invalid escape (e.g. - tag`\unicode and \u{55}`) */
|
|
409
|
+
cooked?: string | null | undefined;
|
|
409
410
|
raw: string;
|
|
410
411
|
};
|
|
411
412
|
}
|
|
@@ -525,11 +526,7 @@ interface AwaitExpression extends BaseExpression {
|
|
|
525
526
|
}
|
|
526
527
|
//#endregion
|
|
527
528
|
//#region src/transforms/hoist.d.ts
|
|
528
|
-
declare function transformHoistInlineDirective(input: string, ast: Program, {
|
|
529
|
-
runtime,
|
|
530
|
-
rejectNonAsyncFunction,
|
|
531
|
-
...options
|
|
532
|
-
}: {
|
|
529
|
+
declare function transformHoistInlineDirective(input: string, ast: Program, { runtime, rejectNonAsyncFunction, ...options }: {
|
|
533
530
|
runtime: (value: string, name: string, meta: {
|
|
534
531
|
directiveMatch: RegExpMatchArray;
|
|
535
532
|
}) => string;
|
|
@@ -546,8 +543,33 @@ declare function findDirectives(ast: Program, directive: string): Literal[];
|
|
|
546
543
|
//#endregion
|
|
547
544
|
//#region src/transforms/wrap-export.d.ts
|
|
548
545
|
type ExportMeta = {
|
|
546
|
+
/**
|
|
547
|
+
* The local declaration name when statically available.
|
|
548
|
+
*
|
|
549
|
+
* - `"Page"` for `export function Page() {}`
|
|
550
|
+
* - `"Page"` for `export const Page = () => {}`
|
|
551
|
+
* - `undefined` for `export default () => {}`
|
|
552
|
+
* - `undefined` for `export { Page }`
|
|
553
|
+
*/
|
|
549
554
|
declName?: string;
|
|
555
|
+
/**
|
|
556
|
+
* Whether the exported value is statically known to be a function.
|
|
557
|
+
*
|
|
558
|
+
* - `true` for `export const Page = () => {}`
|
|
559
|
+
* - `false` for `export const value = 1`
|
|
560
|
+
* - `undefined` for `export const value = getValue()`
|
|
561
|
+
* - `undefined` for `export default Page`
|
|
562
|
+
*/
|
|
550
563
|
isFunction?: boolean;
|
|
564
|
+
/**
|
|
565
|
+
* The local identifier referenced by a default export.
|
|
566
|
+
* The RSC CSS transform uses this to detect a component by its capitalized
|
|
567
|
+
* local name and preserve that name on the generated wrapper.
|
|
568
|
+
*
|
|
569
|
+
* - `"Page"` for `const Page = () => {}; export default Page`
|
|
570
|
+
* - `undefined` for `export default function Page() {}`
|
|
571
|
+
* - `undefined` for `export default () => {}`
|
|
572
|
+
*/
|
|
551
573
|
defaultExportIdentifierName?: string;
|
|
552
574
|
};
|
|
553
575
|
type TransformWrapExportFilter = (name: string, meta: ExportMeta) => boolean;
|
|
@@ -564,16 +586,17 @@ declare function transformWrapExport(input: string, ast: Program, options: Trans
|
|
|
564
586
|
//#endregion
|
|
565
587
|
//#region src/transforms/proxy-export.d.ts
|
|
566
588
|
type TransformProxyExportOptions = {
|
|
567
|
-
/** Required for source map and `keep` options */
|
|
589
|
+
/** Required for source map and `keep` options */
|
|
590
|
+
code?: string;
|
|
568
591
|
runtime: (name: string, meta?: {
|
|
569
592
|
value: string;
|
|
570
593
|
}) => string;
|
|
571
594
|
ignoreExportAllDeclaration?: boolean;
|
|
572
595
|
rejectNonAsyncFunction?: boolean;
|
|
573
596
|
/**
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
597
|
+
* escape hatch for Waku's `allowServer`
|
|
598
|
+
* @default false
|
|
599
|
+
*/
|
|
577
600
|
keep?: boolean;
|
|
578
601
|
};
|
|
579
602
|
declare function transformDirectiveProxyExport(ast: Program, options: {
|
|
@@ -35,6 +35,7 @@ interface RenderToReadableStreamOptions {
|
|
|
35
35
|
interface CreateFromReadableStreamBrowserOptions {
|
|
36
36
|
callServer?: CallServerCallback;
|
|
37
37
|
debugChannel?: DebugChannel;
|
|
38
|
+
encodeFormAction?: EncodeFormActionCallback;
|
|
38
39
|
endTime?: number;
|
|
39
40
|
environmentName?: string;
|
|
40
41
|
replayConsoleLogs?: boolean;
|
|
@@ -43,6 +44,7 @@ interface CreateFromReadableStreamBrowserOptions {
|
|
|
43
44
|
}
|
|
44
45
|
interface CreateFromReadableStreamEdgeOptions {
|
|
45
46
|
debugChannel?: DebugChannel;
|
|
47
|
+
encodeFormAction?: EncodeFormActionCallback;
|
|
46
48
|
endTime?: number;
|
|
47
49
|
environmentName?: string;
|
|
48
50
|
nonce?: string;
|
|
@@ -58,6 +60,15 @@ interface EncodeReplyOptions {
|
|
|
58
60
|
temporaryReferences?: ClientTemporaryReferenceSet;
|
|
59
61
|
signal?: AbortSignal;
|
|
60
62
|
}
|
|
63
|
+
type EncodeFormActionCallback = (id: string, args: Promise<unknown[]>) => ReactCustomFormAction;
|
|
64
|
+
type ReactCustomFormAction = {
|
|
65
|
+
name?: string;
|
|
66
|
+
action?: string;
|
|
67
|
+
encType?: string;
|
|
68
|
+
method?: string;
|
|
69
|
+
target?: string;
|
|
70
|
+
data?: FormData | null;
|
|
71
|
+
};
|
|
61
72
|
type EncodeReplyFunction = (value: unknown[], options?: EncodeReplyOptions) => Promise<string | FormData>;
|
|
62
73
|
type DecodeReplyFunction = (body: string | FormData, options?: DecodeReplyOptions) => Promise<unknown[]>;
|
|
63
74
|
type DebugChannel = {
|
|
@@ -67,4 +78,4 @@ type DebugChannel = {
|
|
|
67
78
|
type ServerTemporaryReferenceSet = unknown;
|
|
68
79
|
type ClientTemporaryReferenceSet = unknown;
|
|
69
80
|
//#endregion
|
|
70
|
-
export { CreateFromReadableStreamEdgeOptions as a,
|
|
81
|
+
export { CreateFromReadableStreamEdgeOptions as a, EncodeReplyFunction as c, ServerConsumerManifest as d, ServerTemporaryReferenceSet as f, CreateFromReadableStreamBrowserOptions as i, ModuleMap as l, CallServerCallback as n, DecodeReplyFunction as o, ClientTemporaryReferenceSet as r, EncodeFormActionCallback as s, BundlerConfig as t, RenderToReadableStreamOptions as u };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { c as getPluginApi, r as PluginApi, s as RscPluginOptions, u as vitePluginRsc } from "./plugin-
|
|
1
|
+
import { c as getPluginApi, r as PluginApi, s as RscPluginOptions, u as vitePluginRsc } from "./plugin-CaLiN8ED.js";
|
|
2
2
|
export { type PluginApi, type RscPluginOptions, vitePluginRsc as default, getPluginApi };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { r as vitePluginRsc, t as getPluginApi } from "./plugin-
|
|
1
|
+
import { r as vitePluginRsc, t as getPluginApi } from "./plugin-BOTpkess.js";
|
|
2
2
|
export { vitePluginRsc as default, getPluginApi };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { a as __commonJSMin } from "./plugin-
|
|
1
|
+
import { a as __commonJSMin } from "./plugin-BOTpkess.js";
|
|
2
2
|
//#region ../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js
|
|
3
3
|
var require_picocolors = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
4
|
-
let p = process || {}
|
|
4
|
+
let p = process || {};
|
|
5
|
+
let argv = p.argv || [];
|
|
6
|
+
let env = p.env || {};
|
|
5
7
|
let isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
6
8
|
let formatter = (open, close, replace = open) => (input) => {
|
|
7
9
|
let string = "" + input, index = string.indexOf(close, open.length);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { t as createDebug } from "./dist-
|
|
1
|
+
import { t as createDebug } from "./dist-uqdtSkzK.js";
|
|
2
2
|
import vitePluginRscCore from "./core/plugin.js";
|
|
3
|
-
import { i as hasDirective } from "./scope-
|
|
4
|
-
import { t as cjsModuleRunnerPlugin } from "./cjs-
|
|
5
|
-
import { i as toCssVirtual, n as parseIdQuery, r as parseReferenceValidationVirtual, t as parseCssVirtual } from "./shared-
|
|
3
|
+
import { i as hasDirective } from "./scope-Do08R7C2.js";
|
|
4
|
+
import { t as cjsModuleRunnerPlugin } from "./cjs-Cxg_7upE.js";
|
|
5
|
+
import { i as toCssVirtual, n as parseIdQuery, r as parseReferenceValidationVirtual, t as parseCssVirtual } from "./shared-B6H2TbnP.js";
|
|
6
6
|
import { findDirectives, transformDirectiveProxyExport, transformExpandExportAll, transformServerActionServer, transformWrapExport } from "./transforms/index.js";
|
|
7
|
-
import { o as generateEncryptionKey, s as toBase64 } from "./encryption-utils-
|
|
7
|
+
import { o as generateEncryptionKey, s as toBase64 } from "./encryption-utils-BNbYHtC4.js";
|
|
8
8
|
import { createRpcServer } from "./utils/rpc.js";
|
|
9
9
|
import { createRequire } from "node:module";
|
|
10
10
|
import assert from "node:assert";
|
|
@@ -605,15 +605,24 @@ function vitePluginRscMinimal(rscPluginOptions = {}, manager = new RscPluginMana
|
|
|
605
605
|
apply: "serve",
|
|
606
606
|
load: {
|
|
607
607
|
filter: { id: prefixRegex("\0virtual:vite-rsc/reference-validation?") },
|
|
608
|
-
handler(id, _options) {
|
|
608
|
+
async handler(id, _options) {
|
|
609
609
|
if (id.startsWith("\0virtual:vite-rsc/reference-validation?")) {
|
|
610
610
|
const parsed = parseReferenceValidationVirtual(id);
|
|
611
611
|
assert(parsed);
|
|
612
|
+
assert(this.environment.mode === "dev");
|
|
612
613
|
if (parsed.type === "client") {
|
|
613
614
|
if (Object.values(manager.clientReferenceMetaMap).find((meta) => meta.referenceKey === parsed.id)) return `export {}`;
|
|
614
615
|
}
|
|
615
616
|
if (parsed.type === "server") {
|
|
616
|
-
|
|
617
|
+
let meta = Object.values(manager.serverReferenceMetaMap).find((meta) => meta.referenceKey === parsed.id);
|
|
618
|
+
if (!meta) {
|
|
619
|
+
try {
|
|
620
|
+
const id = (await this.resolve(parsed.id))?.id ?? parsed.id;
|
|
621
|
+
if (isFileLoadingAllowed(manager.config, slash(cleanUrl(id)))) await this.environment.transformRequest(parsed.id);
|
|
622
|
+
} catch {}
|
|
623
|
+
meta = Object.values(manager.serverReferenceMetaMap).find((meta) => meta.referenceKey === parsed.id);
|
|
624
|
+
}
|
|
625
|
+
if (meta) return `export {}`;
|
|
617
626
|
}
|
|
618
627
|
this.error(`[vite-rsc] invalid ${parsed.type} reference '${parsed.id}'`);
|
|
619
628
|
}
|
|
@@ -627,7 +636,7 @@ function vitePluginRscMinimal(rscPluginOptions = {}, manager = new RscPluginMana
|
|
|
627
636
|
function vitePluginRsc(rscPluginOptions = {}) {
|
|
628
637
|
const manager = new RscPluginManager();
|
|
629
638
|
const buildApp = async (builder) => {
|
|
630
|
-
const colors = await import("./picocolors-
|
|
639
|
+
const colors = await import("./picocolors-DFVOi1sR.js").then((m) => /* @__PURE__ */ __toESM(m.default, 1));
|
|
631
640
|
const logStep = (msg) => {
|
|
632
641
|
builder.config.logger.info(colors.blue(msg));
|
|
633
642
|
};
|
|
@@ -1096,6 +1105,7 @@ export function createRpcClient(params) {
|
|
|
1096
1105
|
}, manager);
|
|
1097
1106
|
const assetDeps = collectAssetDeps(bundle);
|
|
1098
1107
|
let bootstrapScriptContent = "";
|
|
1108
|
+
let clientEntryDeps;
|
|
1099
1109
|
const clientReferenceDeps = {};
|
|
1100
1110
|
for (const meta of Object.values(manager.clientReferenceMetaMap)) {
|
|
1101
1111
|
const deps = assetDeps[meta.groupChunkId]?.deps ?? {
|
|
@@ -1107,14 +1117,15 @@ export function createRpcClient(params) {
|
|
|
1107
1117
|
if (!rscPluginOptions.customClientEntry) {
|
|
1108
1118
|
const entry = Object.values(assetDeps).find((v) => v.chunk.name === "index" && v.chunk.isEntry);
|
|
1109
1119
|
if (!entry) throw new Error(`[vite-rsc] Client build must have an entry chunk named "index". Use 'customClientEntry' option to disable this requirement.`);
|
|
1110
|
-
|
|
1111
|
-
for (const [key, deps] of Object.entries(clientReferenceDeps)) clientReferenceDeps[key] = mergeAssetDeps(deps,
|
|
1120
|
+
clientEntryDeps = assetsURLOfDeps(entry.deps, manager);
|
|
1121
|
+
for (const [key, deps] of Object.entries(clientReferenceDeps)) clientReferenceDeps[key] = mergeAssetDeps(deps, clientEntryDeps);
|
|
1112
1122
|
const entryUrl = assetsURL(entry.chunk.fileName, manager);
|
|
1113
1123
|
if (typeof entryUrl === "string") bootstrapScriptContent = `import(${JSON.stringify(entryUrl)})`;
|
|
1114
1124
|
else bootstrapScriptContent = new RuntimeAsset(`"import(" + JSON.stringify(${entryUrl.runtime}) + ")"`);
|
|
1115
1125
|
}
|
|
1116
1126
|
manager.buildAssetsManifest = {
|
|
1117
1127
|
bootstrapScriptContent,
|
|
1128
|
+
clientEntryDeps,
|
|
1118
1129
|
clientReferenceDeps,
|
|
1119
1130
|
serverResources,
|
|
1120
1131
|
cssLinkPrecedence: rscPluginOptions.cssLinkPrecedence
|
|
@@ -1316,7 +1327,7 @@ function vitePluginUseClient(useClientPluginOptions, manager) {
|
|
|
1316
1327
|
exportNames,
|
|
1317
1328
|
renderedExports: []
|
|
1318
1329
|
};
|
|
1319
|
-
const importSource = resolvePackage(`${PKG_NAME}/react/rsc`);
|
|
1330
|
+
const importSource = resolvePackage(`${PKG_NAME}/react/rsc/server`);
|
|
1320
1331
|
output.prepend(`import * as $$ReactServer from "${importSource}";\n`);
|
|
1321
1332
|
return {
|
|
1322
1333
|
code: output.toString(),
|
|
@@ -1423,6 +1434,8 @@ function vitePluginUseClient(useClientPluginOptions, manager) {
|
|
|
1423
1434
|
if (this.environment.name === serverEnvironmentName && bareImportRE.test(source) && !(source === "client-only" || source === "server-only")) {
|
|
1424
1435
|
const resolved = await this.resolve(source, importer, options);
|
|
1425
1436
|
if (resolved && resolved.id.includes("/node_modules/")) {
|
|
1437
|
+
const resolvedAtRoot = await this.resolve(source, void 0, options);
|
|
1438
|
+
if (!resolvedAtRoot || resolvedAtRoot.id !== resolved.id) return;
|
|
1426
1439
|
packageSources.set(resolved.id, source);
|
|
1427
1440
|
return resolved;
|
|
1428
1441
|
}
|
|
@@ -1608,7 +1621,7 @@ function vitePluginUseServer(useServerPluginOptions, manager) {
|
|
|
1608
1621
|
referenceKey: getNormalizedId(),
|
|
1609
1622
|
exportNames: "names" in result ? result.names : result.exportNames
|
|
1610
1623
|
};
|
|
1611
|
-
const importSource = resolvePackage(`${PKG_NAME}/react/rsc`);
|
|
1624
|
+
const importSource = resolvePackage(`${PKG_NAME}/react/rsc/server`);
|
|
1612
1625
|
output.prepend(`import * as $$ReactServer from "${importSource}";\n`);
|
|
1613
1626
|
if (enableEncryption) {
|
|
1614
1627
|
const importSource = resolvePackage(`${PKG_NAME}/utils/encryption-runtime`);
|
|
@@ -1637,7 +1650,8 @@ function vitePluginUseServer(useServerPluginOptions, manager) {
|
|
|
1637
1650
|
referenceKey: getNormalizedId(),
|
|
1638
1651
|
exportNames: result.exportNames
|
|
1639
1652
|
};
|
|
1640
|
-
const
|
|
1653
|
+
const name = this.environment.name === browserEnvironmentName ? "browser" : "ssr";
|
|
1654
|
+
const importSource = resolvePackage(`${PKG_NAME}/react/${name}`);
|
|
1641
1655
|
output.prepend(`import * as $$ReactClient from "${importSource}";\n`);
|
|
1642
1656
|
return {
|
|
1643
1657
|
code: output.toString(),
|
|
@@ -1718,8 +1732,8 @@ function assetsURLOfDeps(deps, manager) {
|
|
|
1718
1732
|
}
|
|
1719
1733
|
function mergeAssetDeps(a, b) {
|
|
1720
1734
|
return {
|
|
1721
|
-
js: [
|
|
1722
|
-
css: [
|
|
1735
|
+
js: [.../* @__PURE__ */ new Set([...a.js, ...b.js])],
|
|
1736
|
+
css: [.../* @__PURE__ */ new Set([...a.css, ...b.css])]
|
|
1723
1737
|
};
|
|
1724
1738
|
}
|
|
1725
1739
|
function collectAssetDeps(bundle) {
|