@vitejs/plugin-rsc 0.4.28 → 0.4.30

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.
Files changed (66) hide show
  1. package/README.md +2 -50
  2. package/dist/{browser-QU10IP0-.js → browser--ZREVnM9.js} +1 -1
  3. package/dist/{browser-BhJd-Orx.js → browser-7NhxQxuk.js} +1 -1
  4. package/dist/{browser-mbRygLxB.d.ts → browser-CQv7Z3J4.d.ts} +1 -1
  5. package/dist/browser.d.ts +3 -3
  6. package/dist/browser.js +3 -3
  7. package/dist/cjs-WQBk0zA_.js +104 -0
  8. package/dist/core/browser.d.ts +1 -1
  9. package/dist/core/browser.js +2 -2
  10. package/dist/core/rsc.d.ts +2 -2
  11. package/dist/core/rsc.js +2 -2
  12. package/dist/core/ssr.d.ts +2 -2
  13. package/dist/core/ssr.js +2 -2
  14. package/dist/{encryption-runtime-CJUalqt3.js → encryption-runtime-CugTJCLM.js} +2 -3
  15. package/dist/extra/browser.d.ts +1 -1
  16. package/dist/extra/browser.js +5 -6
  17. package/dist/extra/rsc.d.ts +1 -1
  18. package/dist/extra/rsc.js +11 -17
  19. package/dist/extra/ssr.js +8 -10
  20. package/dist/index-DWN3vCIQ.d.ts +89 -0
  21. package/dist/index.d.ts +3 -24
  22. package/dist/index.js +6 -4
  23. package/dist/{plugin-iKgvucKS.js → plugin-Bzocj-4a.js} +70 -496
  24. package/dist/{plugin-BFcMxUSS.d.ts → plugin-Cfy_9VpM.d.ts} +1 -9
  25. package/dist/plugin.d.ts +2 -1
  26. package/dist/plugin.js +5 -3
  27. package/dist/plugins/cjs.d.ts +6 -0
  28. package/dist/plugins/cjs.js +5 -0
  29. package/dist/react/browser.d.ts +3 -3
  30. package/dist/react/browser.js +2 -2
  31. package/dist/react/rsc.d.ts +3 -3
  32. package/dist/react/rsc.js +3 -3
  33. package/dist/react/ssr.d.ts +3 -3
  34. package/dist/react/ssr.js +3 -3
  35. package/dist/{rpc-tGuLT8PD.js → rpc-CUvSZurk.js} +2 -3
  36. package/dist/{rsc-CxDPDiLz.d.ts → rsc-3bkzqdsJ.d.ts} +1 -1
  37. package/dist/{rsc-VjVw_i-M.js → rsc-BdCB3621.js} +1 -1
  38. package/dist/{rsc-BwEwbLG4.js → rsc-CiAoLCx8.js} +1 -1
  39. package/dist/{rsc-BfBPoIV8.js → rsc-GFzFWyhT.js} +2 -3
  40. package/dist/rsc-html-stream/browser.js +1 -1
  41. package/dist/rsc-html-stream/ssr.js +1 -1
  42. package/dist/rsc.d.ts +4 -4
  43. package/dist/rsc.js +5 -5
  44. package/dist/{shared-CEyKoKAb.js → shared-CXg_u-4h.js} +1 -2
  45. package/dist/{ssr-CWjOQSe3.js → ssr-8BA2nj0-.js} +2 -2
  46. package/dist/{ssr-BoNKka-5.d.ts → ssr-CMjeQ9AS.d.ts} +1 -1
  47. package/dist/{ssr-BEKKb_cw.js → ssr-Cd4SbAaO.js} +1 -1
  48. package/dist/{ssr--rFiBtws.js → ssr-Cm2FP2zD.js} +1 -1
  49. package/dist/ssr.d.ts +3 -3
  50. package/dist/ssr.js +5 -5
  51. package/dist/transforms/index.d.ts +2 -0
  52. package/dist/transforms/index.js +4 -0
  53. package/dist/transforms-D1-2JfCh.js +330 -0
  54. package/dist/utils/encryption-runtime.d.ts +1 -1
  55. package/dist/utils/encryption-runtime.js +4 -4
  56. package/dist/utils/rpc.js +1 -1
  57. package/package.json +3 -2
  58. /package/dist/{browser-CuwQIlVY.d.ts → browser-DwWQeoll.d.ts} +0 -0
  59. /package/dist/{client-C1J4FCf5.js → client-C7Eok9hc.js} +0 -0
  60. /package/dist/{encryption-runtime-SgJRa9yj.d.ts → encryption-runtime-B8xcnJoN.d.ts} +0 -0
  61. /package/dist/{index-QWzVHuya.d.ts → index-CPkExgij.d.ts} +0 -0
  62. /package/dist/{rsc-CFtzqEG8.d.ts → rsc-JJjz3Z0i.d.ts} +0 -0
  63. /package/dist/{rsc-Cv3XEZqB.d.ts → rsc-c22DF1A7.d.ts} +0 -0
  64. /package/dist/{server-D0-DavPP.js → server-BTo03tXh.js} +0 -0
  65. /package/dist/{shared-BWHxNw3Q.js → shared-AvKUASD5.js} +0 -0
  66. /package/dist/{ssr-D6GTzOzx.d.ts → ssr-BrSGyrxe.d.ts} +0 -0
package/README.md CHANGED
@@ -14,12 +14,12 @@ This package provides [React Server Components](https://react.dev/reference/rsc/
14
14
  You can create a starter project by:
15
15
 
16
16
  ```sh
17
- npx degit vitejs/vite-plugin-react/packages/plugin-rsc/examples/starter my-app
17
+ npm create vite@latest -- --template rsc
18
18
  ```
19
19
 
20
20
  ## Examples
21
21
 
22
- **Start here:** [`./examples/starter`](./examples/starter) - Recommended for understanding the plugin
22
+ **Start here:** [`./examples/starter`](./examples/starter) - Recommended for understanding the package
23
23
 
24
24
  - Provides an in-depth overview of API with inline comments to explain how they function within RSC-powered React application.
25
25
 
@@ -295,35 +295,6 @@ export function UserApp() {
295
295
  }
296
296
  ```
297
297
 
298
- #### `<id>?vite-rsc-css-export=<name>`
299
-
300
- This special query convention provides automatic injection of `import.meta.viteRsc.loadCss`.
301
-
302
- For example,
303
-
304
- ```tsx
305
- // my-route.tsx
306
- export function Page(props) {
307
- return <div>...</div>
308
- }
309
-
310
- // my-route.tsx?vite-rsc-css-export=Page
311
- function Page(props) {
312
- return <div>...</div>
313
- }
314
-
315
- function __Page(props) {
316
- return (
317
- <>
318
- {import.meta.viteRsc.loadCss()}
319
- <Page {...props} />
320
- </>
321
- )
322
- }
323
-
324
- export { __Page as Page }
325
- ```
326
-
327
298
  ### Available on `ssr` environment
328
299
 
329
300
  #### `import.meta.viteRsc.loadBootstrapScriptContent("index")`
@@ -434,25 +405,6 @@ This module re-exports RSC runtime API provided by `react-server-dom/client.brow
434
405
  - `createFromFetch`: a robust way of `createFromReadableStream((await fetch("...")).body)`
435
406
  - `encodeReply/setServerCallback`: server function related...
436
407
 
437
- ## High level API
438
-
439
- > [!NOTE]
440
- > High level API is deprecated. Please write on your own `@vitejs/plugin-rsc/{rsc,ssr,browser}` integration.
441
-
442
- 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.
443
-
444
- ### `@vitejs/plugin-rsc/extra/rsc`
445
-
446
- - `renderRequest`
447
-
448
- ### `@vitejs/plugin-rsc/extra/ssr`
449
-
450
- - `renderHtml`
451
-
452
- ### `@vitejs/plugin-rsc/extra/browser`
453
-
454
- - `hydrate`
455
-
456
408
  ## CSS Support
457
409
 
458
410
  The plugin automatically handles CSS code-splitting and injection for server components. This eliminates the need to manually call [`import.meta.viteRsc.loadCss()`](#importmetaviterscloadcss) in most cases.
@@ -1,4 +1,4 @@
1
- import { setRequireModule } from "./browser-BhJd-Orx.js";
1
+ import { setRequireModule } from "./browser-7NhxQxuk.js";
2
2
  import * as clientReferences from "virtual:vite-rsc/client-references";
3
3
 
4
4
  //#region src/browser.ts
@@ -1,5 +1,5 @@
1
1
  import { memoize } from "./dist-DiJnRA1C.js";
2
- import { removeReferenceCacheTag, setInternalRequire } from "./shared-CEyKoKAb.js";
2
+ import { removeReferenceCacheTag, setInternalRequire } from "./shared-CXg_u-4h.js";
3
3
 
4
4
  //#region src/core/browser.ts
5
5
  let init = false;
@@ -1,4 +1,4 @@
1
- import { CallServerCallback } from "./index-QWzVHuya.js";
1
+ import { CallServerCallback } from "./index-CPkExgij.js";
2
2
 
3
3
  //#region src/react/browser.d.ts
4
4
  declare function createFromReadableStream<T>(stream: ReadableStream<Uint8Array>, options?: object): Promise<T>;
package/dist/browser.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CallServerCallback } from "./index-QWzVHuya.js";
2
- import { setRequireModule } from "./browser-CuwQIlVY.js";
3
- import { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setServerCallback } from "./browser-mbRygLxB.js";
1
+ import { CallServerCallback } from "./index-CPkExgij.js";
2
+ import { setRequireModule } from "./browser-DwWQeoll.js";
3
+ import { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setServerCallback } from "./browser-CQv7Z3J4.js";
4
4
  export { CallServerCallback, callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setRequireModule, setServerCallback };
package/dist/browser.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import "./dist-DiJnRA1C.js";
2
- import "./shared-CEyKoKAb.js";
3
- import { setRequireModule } from "./browser-BhJd-Orx.js";
2
+ import "./shared-CXg_u-4h.js";
3
+ import { setRequireModule } from "./browser-7NhxQxuk.js";
4
4
  import { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setServerCallback } from "./browser-D8OPzpF5.js";
5
- import "./browser-QU10IP0-.js";
5
+ import "./browser--ZREVnM9.js";
6
6
 
7
7
  export { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setRequireModule, setServerCallback };
@@ -0,0 +1,104 @@
1
+ import { createDebug } from "./dist-DiJnRA1C.js";
2
+ import { parseIdQuery } from "./shared-AvKUASD5.js";
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import * as esModuleLexer from "es-module-lexer";
6
+ import MagicString from "magic-string";
7
+ import { parseAstAsync } from "vite";
8
+ import { findClosestPkgJsonPath } from "vitefu";
9
+ import { walk } from "estree-walker";
10
+ import { analyze } from "periscopic";
11
+
12
+ //#region src/transforms/cjs.ts
13
+ function transformCjsToEsm(code, ast) {
14
+ const output = new MagicString(code);
15
+ const analyzed = analyze(ast);
16
+ const parentNodes = [];
17
+ const hoistedCodes = [];
18
+ let hoistIndex = 0;
19
+ walk(ast, {
20
+ enter(node) {
21
+ parentNodes.push(node);
22
+ if (node.type === "CallExpression" && node.callee.type === "Identifier" && node.callee.name === "require" && node.arguments.length === 1) {
23
+ let isTopLevel = true;
24
+ for (const parent of parentNodes) {
25
+ if (parent.type === "FunctionExpression" || parent.type === "FunctionDeclaration" || parent.type === "ArrowFunctionExpression") isTopLevel = false;
26
+ const scope = analyzed.map.get(parent);
27
+ if (scope && scope.declarations.has("require")) return;
28
+ }
29
+ if (isTopLevel) {
30
+ output.update(node.start, node.callee.end, "((await import");
31
+ output.appendRight(node.end, ").default)");
32
+ } else {
33
+ const hoisted = `__cjs_to_esm_hoist_${hoistIndex}`;
34
+ const importee = code.slice(node.arguments[0].start, node.arguments[0].end);
35
+ hoistedCodes.push(`const ${hoisted} = (await import(${importee})).default;\n`);
36
+ output.update(node.start, node.end, hoisted);
37
+ hoistIndex++;
38
+ }
39
+ }
40
+ },
41
+ leave() {
42
+ parentNodes.pop();
43
+ }
44
+ });
45
+ for (const hoisted of hoistedCodes.reverse()) output.prepend(hoisted);
46
+ output.prepend(`let exports = {}; const module = { exports };\n`);
47
+ return { output };
48
+ }
49
+
50
+ //#endregion
51
+ //#region src/plugins/cjs.ts
52
+ const debug = createDebug("vite-rsc:cjs");
53
+ function cjsModuleRunnerPlugin() {
54
+ const warnedPackages = /* @__PURE__ */ new Set();
55
+ return [{
56
+ name: "cjs-module-runner-transform",
57
+ apply: "serve",
58
+ applyToEnvironment: (env) => env.config.dev.moduleRunnerTransform,
59
+ async transform(code, id) {
60
+ if (id.includes("/node_modules/") && !id.startsWith(this.environment.config.cacheDir) && /\b(require|exports)\b/.test(code)) {
61
+ id = parseIdQuery(id).filename;
62
+ if (!/\.[cm]?js$/.test(id)) return;
63
+ if (id.endsWith(".mjs")) return;
64
+ if (id.endsWith(".js")) {
65
+ const pkgJsonPath = await findClosestPkgJsonPath(path.dirname(id));
66
+ if (pkgJsonPath) {
67
+ if (JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8")).type === "module") return;
68
+ }
69
+ }
70
+ const [, , , hasModuleSyntax] = esModuleLexer.parse(code);
71
+ if (hasModuleSyntax) return;
72
+ const packageKey = extractPackageKey(id);
73
+ if (!warnedPackages.has(packageKey)) {
74
+ debug(`non-optimized CJS dependency in '${this.environment.name}' environment: ${id}`);
75
+ warnedPackages.add(packageKey);
76
+ }
77
+ const ast = await parseAstAsync(code);
78
+ const output = transformCjsToEsm(code, ast).output;
79
+ output.append(`
80
+ ;__vite_ssr_exportAll__(module.exports);
81
+ export default module.exports;
82
+ `);
83
+ return {
84
+ code: output.toString(),
85
+ map: output.generateMap({ hires: "boundary" })
86
+ };
87
+ }
88
+ }
89
+ }];
90
+ }
91
+ function extractPackageKey(id) {
92
+ const yarnMatch = id.match(/\/.yarn\/cache\/([^/]+)/);
93
+ if (yarnMatch) return yarnMatch[1];
94
+ if (id.includes("/node_modules")) {
95
+ id = id.split("/node_modules/").at(-1);
96
+ let [x, y] = id.split("/");
97
+ if (x.startsWith("@")) return `${x}/${y}`;
98
+ return x;
99
+ }
100
+ return id;
101
+ }
102
+
103
+ //#endregion
104
+ export { cjsModuleRunnerPlugin };
@@ -1,2 +1,2 @@
1
- import { setRequireModule } from "../browser-CuwQIlVY.js";
1
+ import { setRequireModule } from "../browser-DwWQeoll.js";
2
2
  export { setRequireModule };
@@ -1,5 +1,5 @@
1
1
  import "../dist-DiJnRA1C.js";
2
- import "../shared-CEyKoKAb.js";
3
- import { setRequireModule } from "../browser-BhJd-Orx.js";
2
+ import "../shared-CXg_u-4h.js";
3
+ import { setRequireModule } from "../browser-7NhxQxuk.js";
4
4
 
5
5
  export { setRequireModule };
@@ -1,3 +1,3 @@
1
- import "../index-QWzVHuya.js";
2
- import { createClientManifest, createServerDecodeClientManifest, createServerManifest, loadServerAction, setRequireModule } from "../rsc-CxDPDiLz.js";
1
+ import "../index-CPkExgij.js";
2
+ import { createClientManifest, createServerDecodeClientManifest, createServerManifest, loadServerAction, setRequireModule } from "../rsc-3bkzqdsJ.js";
3
3
  export { createClientManifest, createServerDecodeClientManifest, createServerManifest, loadServerAction, setRequireModule };
package/dist/core/rsc.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "../dist-DiJnRA1C.js";
2
- import "../shared-CEyKoKAb.js";
3
- import { createClientManifest, createServerDecodeClientManifest, createServerManifest, loadServerAction, setRequireModule } from "../rsc-BfBPoIV8.js";
2
+ import "../shared-CXg_u-4h.js";
3
+ import { createClientManifest, createServerDecodeClientManifest, createServerManifest, loadServerAction, setRequireModule } from "../rsc-GFzFWyhT.js";
4
4
 
5
5
  export { createClientManifest, createServerDecodeClientManifest, createServerManifest, loadServerAction, setRequireModule };
@@ -1,3 +1,3 @@
1
- import "../index-QWzVHuya.js";
2
- import { createServerConsumerManifest, setRequireModule } from "../ssr-BoNKka-5.js";
1
+ import "../index-CPkExgij.js";
2
+ import { createServerConsumerManifest, setRequireModule } from "../ssr-CMjeQ9AS.js";
3
3
  export { createServerConsumerManifest, setRequireModule };
package/dist/core/ssr.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "../dist-DiJnRA1C.js";
2
- import "../shared-CEyKoKAb.js";
3
- import { createServerConsumerManifest, setRequireModule } from "../ssr--rFiBtws.js";
2
+ import "../shared-CXg_u-4h.js";
3
+ import { createServerConsumerManifest, setRequireModule } from "../ssr-Cm2FP2zD.js";
4
4
 
5
5
  export { createServerConsumerManifest, setRequireModule };
@@ -1,6 +1,6 @@
1
1
  import { once } from "./dist-DiJnRA1C.js";
2
2
  import { arrayToStream, concatArrayStream, decryptBuffer, encryptBuffer, fromBase64 } from "./encryption-utils-BDwwcMVT.js";
3
- import { createFromReadableStream, renderToReadableStream } from "./rsc-VjVw_i-M.js";
3
+ import { createFromReadableStream, renderToReadableStream } from "./rsc-BdCB3621.js";
4
4
  import encryptionKeySource from "virtual:vite-rsc/encryption-key";
5
5
 
6
6
  //#region src/utils/encryption-runtime.ts
@@ -16,8 +16,7 @@ async function decryptActionBoundArgs(encrypted) {
16
16
  }
17
17
  const getEncryptionKey = /* @__PURE__ */ once(async () => {
18
18
  const resolved = await encryptionKeySource();
19
- const key = await crypto.subtle.importKey("raw", fromBase64(resolved), { name: "AES-GCM" }, true, ["encrypt", "decrypt"]);
20
- return key;
19
+ return await crypto.subtle.importKey("raw", fromBase64(resolved), { name: "AES-GCM" }, true, ["encrypt", "decrypt"]);
21
20
  });
22
21
 
23
22
  //#endregion
@@ -1,4 +1,4 @@
1
- import { RscPayload } from "../rsc-Cv3XEZqB.js";
1
+ import { RscPayload } from "../rsc-c22DF1A7.js";
2
2
 
3
3
  //#region src/extra/browser.d.ts
4
4
 
@@ -1,9 +1,9 @@
1
1
  import "../dist-DiJnRA1C.js";
2
- import "../shared-CEyKoKAb.js";
3
- import "../browser-BhJd-Orx.js";
2
+ import "../shared-CXg_u-4h.js";
3
+ import "../browser-7NhxQxuk.js";
4
4
  import { createFromFetch, createFromReadableStream, createTemporaryReferenceSet, encodeReply, setServerCallback } from "../browser-D8OPzpF5.js";
5
- import "../browser-QU10IP0-.js";
6
- import { rscStream } from "../client-C1J4FCf5.js";
5
+ import "../browser--ZREVnM9.js";
6
+ import { rscStream } from "../client-C7Eok9hc.js";
7
7
  import React from "react";
8
8
  import ReactDomClient from "react-dom/client";
9
9
  import { jsx } from "react/jsx-runtime";
@@ -52,8 +52,7 @@ async function hydrate() {
52
52
  * @deprecated Use `@vitejs/plugin-rsc/browser` API instead.
53
53
  */
54
54
  async function fetchRSC(request) {
55
- const payload = await createFromFetch(fetch(request));
56
- return payload.root;
55
+ return (await createFromFetch(fetch(request))).root;
57
56
  }
58
57
  function listenNavigation(onNavigation) {
59
58
  window.addEventListener("popstate", onNavigation);
@@ -1,2 +1,2 @@
1
- import { RscPayload, renderRequest } from "../rsc-Cv3XEZqB.js";
1
+ import { RscPayload, renderRequest } from "../rsc-c22DF1A7.js";
2
2
  export { RscPayload, renderRequest };
package/dist/extra/rsc.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import "../dist-DiJnRA1C.js";
2
- import "../shared-CEyKoKAb.js";
2
+ import "../shared-CXg_u-4h.js";
3
3
  import "../encryption-utils-BDwwcMVT.js";
4
- import { loadServerAction } from "../rsc-BfBPoIV8.js";
5
- import { createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, renderToReadableStream } from "../rsc-VjVw_i-M.js";
6
- import "../encryption-runtime-CJUalqt3.js";
7
- import "../rsc-BwEwbLG4.js";
4
+ import { loadServerAction } from "../rsc-GFzFWyhT.js";
5
+ import { createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, renderToReadableStream } from "../rsc-BdCB3621.js";
6
+ import "../encryption-runtime-CugTJCLM.js";
7
+ import "../rsc-CiAoLCx8.js";
8
8
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
9
 
10
10
  //#region src/extra/rsc.tsx
@@ -28,32 +28,26 @@ async function renderRequest(request, root, options) {
28
28
  if (isAction) {
29
29
  const actionId = request.headers.get("x-rsc-action");
30
30
  if (actionId) {
31
- const contentType = request.headers.get("content-type");
32
- const body = contentType?.startsWith("multipart/form-data") ? await request.formData() : await request.text();
31
+ const body = request.headers.get("content-type")?.startsWith("multipart/form-data") ? await request.formData() : await request.text();
33
32
  temporaryReferences = createTemporaryReferenceSet();
34
33
  const args = await decodeReply(body, { temporaryReferences });
35
- const action = await loadServerAction(actionId);
36
- returnValue = await action.apply(null, args);
34
+ returnValue = await (await loadServerAction(actionId)).apply(null, args);
37
35
  } else {
38
36
  const formData = await request.formData();
39
- const decodedAction = await decodeAction(formData);
40
- const result = await decodedAction();
37
+ const result = await (await decodeAction(formData))();
41
38
  formState = await decodeFormState(result, formData);
42
39
  }
43
40
  }
44
- const rscPayload = {
41
+ const rscStream = renderToReadableStream({
45
42
  root: /* @__PURE__ */ jsx(RscRoot, {}),
46
43
  formState,
47
44
  returnValue
48
- };
49
- const rscOptions = { temporaryReferences };
50
- const rscStream = renderToReadableStream(rscPayload, rscOptions);
45
+ }, { temporaryReferences });
51
46
  if (isRscRequest) return new Response(rscStream, { headers: {
52
47
  "content-type": "text/x-component;charset=utf-8",
53
48
  vary: "accept"
54
49
  } });
55
- const ssrEntry = await import.meta.viteRsc.loadModule("ssr", "index");
56
- return ssrEntry.renderHtml(rscStream, {
50
+ return (await import.meta.viteRsc.loadModule("ssr", "index")).renderHtml(rscStream, {
57
51
  formState,
58
52
  nonce: options?.nonce,
59
53
  debugNoJs: url.searchParams.has("__nojs")
package/dist/extra/ssr.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import "../dist-DiJnRA1C.js";
2
- import "../shared-CEyKoKAb.js";
3
- import "../shared-BWHxNw3Q.js";
4
- import "../ssr--rFiBtws.js";
5
- import { createFromReadableStream } from "../ssr-BEKKb_cw.js";
6
- import "../ssr-CWjOQSe3.js";
7
- import { injectRSCPayload } from "../server-D0-DavPP.js";
2
+ import "../shared-CXg_u-4h.js";
3
+ import "../shared-AvKUASD5.js";
4
+ import "../ssr-Cm2FP2zD.js";
5
+ import { createFromReadableStream } from "../ssr-Cd4SbAaO.js";
6
+ import "../ssr-8BA2nj0-.js";
7
+ import { injectRSCPayload } from "../server-BTo03tXh.js";
8
8
  import React from "react";
9
9
  import { jsx } from "react/jsx-runtime";
10
10
  import ReactDomServer from "react-dom/server.edge";
@@ -18,16 +18,14 @@ async function renderHtml(rscStream, options) {
18
18
  let payload;
19
19
  function SsrRoot() {
20
20
  payload ??= createFromReadableStream(rscStream1, { nonce: options?.nonce });
21
- const root = React.use(payload).root;
22
- return root;
21
+ return React.use(payload).root;
23
22
  }
24
23
  const bootstrapScriptContent = await import.meta.viteRsc.loadBootstrapScriptContent("index");
25
- const htmlStream = await ReactDomServer.renderToReadableStream(/* @__PURE__ */ jsx(SsrRoot, {}), {
24
+ let responseStream = await ReactDomServer.renderToReadableStream(/* @__PURE__ */ jsx(SsrRoot, {}), {
26
25
  bootstrapScriptContent: options?.debugNoJs ? void 0 : bootstrapScriptContent,
27
26
  nonce: options?.nonce,
28
27
  formState: options?.formState
29
28
  });
30
- let responseStream = htmlStream;
31
29
  if (!options?.debugNoJs) responseStream = responseStream.pipeThrough(injectRSCPayload(rscStream2, { nonce: options?.nonce }));
32
30
  return new Response(responseStream, { headers: {
33
31
  "content-type": "text/html;charset=utf-8",
@@ -0,0 +1,89 @@
1
+ import MagicString from "magic-string";
2
+ import { Program } from "estree";
3
+
4
+ //#region src/transforms/hoist.d.ts
5
+ declare function transformHoistInlineDirective(input: string, ast: Program, {
6
+ runtime,
7
+ rejectNonAsyncFunction,
8
+ ...options
9
+ }: {
10
+ runtime: (value: string, name: string, meta: {
11
+ directiveMatch: RegExpMatchArray;
12
+ }) => string;
13
+ directive: string | RegExp;
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
+ //#region src/transforms/wrap-export.d.ts
24
+ type ExportMeta = {
25
+ declName?: string;
26
+ isFunction?: boolean;
27
+ defaultExportIdentifierName?: string;
28
+ };
29
+ type TransformWrapExportFilter = (name: string, meta: ExportMeta) => boolean;
30
+ type TransformWrapExportOptions = {
31
+ runtime: (value: string, name: string, meta: ExportMeta) => string;
32
+ ignoreExportAllDeclaration?: boolean;
33
+ rejectNonAsyncFunction?: boolean;
34
+ filter?: TransformWrapExportFilter;
35
+ };
36
+ declare function transformWrapExport(input: string, ast: Program, options: TransformWrapExportOptions): {
37
+ exportNames: string[];
38
+ output: MagicString;
39
+ };
40
+ //#endregion
41
+ //#region src/transforms/proxy-export.d.ts
42
+ type TransformProxyExportOptions = {
43
+ /** Required for source map and `keep` options */
44
+ code?: string;
45
+ runtime: (name: string, meta?: {
46
+ value: string;
47
+ }) => string;
48
+ ignoreExportAllDeclaration?: boolean;
49
+ rejectNonAsyncFunction?: boolean;
50
+ /**
51
+ * escape hatch for Waku's `allowServer`
52
+ * @default false
53
+ */
54
+ keep?: boolean;
55
+ };
56
+ declare function transformDirectiveProxyExport(ast: Program, options: {
57
+ directive: string;
58
+ } & TransformProxyExportOptions): {
59
+ exportNames: string[];
60
+ output: MagicString;
61
+ } | undefined;
62
+ declare function transformProxyExport(ast: Program, options: TransformProxyExportOptions): {
63
+ exportNames: string[];
64
+ output: MagicString;
65
+ };
66
+ //#endregion
67
+ //#region src/transforms/utils.d.ts
68
+ declare function hasDirective(body: Program["body"], directive: string): boolean;
69
+ declare function getExportNames(ast: Program, options: {
70
+ ignoreExportAllDeclaration?: boolean;
71
+ }): {
72
+ exportNames: string[];
73
+ };
74
+ //#endregion
75
+ //#region src/transforms/server-action.d.ts
76
+ declare function transformServerActionServer(input: string, ast: Program, options: {
77
+ runtime: (value: string, name: string) => string;
78
+ rejectNonAsyncFunction?: boolean;
79
+ encode?: (value: string) => string;
80
+ decode?: (value: string) => string;
81
+ }): {
82
+ exportNames: string[];
83
+ output: MagicString;
84
+ } | {
85
+ output: MagicString;
86
+ names: string[];
87
+ };
88
+ //#endregion
89
+ export { TransformProxyExportOptions, TransformWrapExportFilter, TransformWrapExportOptions, getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport };
package/dist/index.d.ts CHANGED
@@ -1,24 +1,3 @@
1
- import { PluginApi, RscPluginOptions, getPluginApi, vitePluginRsc } from "./plugin-BFcMxUSS.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
- rejectNonAsyncFunction,
9
- ...options
10
- }: {
11
- runtime: (value: string, name: string, meta: {
12
- directiveMatch: RegExpMatchArray;
13
- }) => string;
14
- directive: string | RegExp;
15
- rejectNonAsyncFunction?: boolean;
16
- encode?: (value: string) => string;
17
- decode?: (value: string) => string;
18
- noExport?: boolean;
19
- }): {
20
- output: MagicString;
21
- names: string[];
22
- };
23
- //#endregion
24
- export { type PluginApi, type RscPluginOptions, vitePluginRsc as default, getPluginApi, transformHoistInlineDirective };
1
+ import "./index-DWN3vCIQ.js";
2
+ import { PluginApi, RscPluginOptions, getPluginApi, vitePluginRsc } from "./plugin-Cfy_9VpM.js";
3
+ export { type PluginApi, type RscPluginOptions, vitePluginRsc as default, getPluginApi };
package/dist/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import "./dist-DiJnRA1C.js";
2
2
  import "./plugin-CZbI4rhS.js";
3
- import { getPluginApi, transformHoistInlineDirective, vitePluginRsc } from "./plugin-iKgvucKS.js";
3
+ import "./transforms-D1-2JfCh.js";
4
4
  import "./encryption-utils-BDwwcMVT.js";
5
- import "./rpc-tGuLT8PD.js";
6
- import "./shared-BWHxNw3Q.js";
5
+ import "./rpc-CUvSZurk.js";
6
+ import { getPluginApi, vitePluginRsc } from "./plugin-Bzocj-4a.js";
7
+ import "./cjs-WQBk0zA_.js";
8
+ import "./shared-AvKUASD5.js";
7
9
 
8
- export { vitePluginRsc as default, getPluginApi, transformHoistInlineDirective };
10
+ export { vitePluginRsc as default, getPluginApi };