Skip to content

Commit f91363f

Browse files
hi-ogawaOpenCode
andcommitted
refactor(app): use public plugin-rsc runtime entries
Co-authored-by: OpenCode <noreply@opencode.ai>
1 parent 22f106e commit f91363f

7 files changed

Lines changed: 66 additions & 58 deletions

File tree

packages/vinext/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@
194194
"peerDependencies": {
195195
"@mdx-js/rollup": "^3.0.0",
196196
"@vitejs/plugin-react": "^5.1.4 || ^6.0.0",
197-
"@vitejs/plugin-rsc": "^0.5.26",
197+
"@vitejs/plugin-rsc": "^0.5.29",
198198
"react": "^19.2.6",
199199
"react-dom": "^19.2.6",
200200
"react-server-dom-webpack": "^19.2.6",

packages/vinext/src/entries/app-rsc-entry.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -289,17 +289,12 @@ import {
289289
createTemporaryReferenceSet,`
290290
: ""
291291
}
292-
} from ${JSON.stringify(
293-
hasServerActions ? "@vitejs/plugin-rsc/rsc" : "@vitejs/plugin-rsc/react/rsc",
294-
)};
295-
import { createClientManifest as _createClientManifest } from "@vitejs/plugin-rsc/core/rsc";
296-
import { prerender as _prerender } from "@vitejs/plugin-rsc/vendor/react-server-dom/static.edge";
292+
} from "@vitejs/plugin-rsc/rsc/server";
293+
import { prerender as _prerender } from "@vitejs/plugin-rsc/rsc/static";
297294
import { createRscPrerenderer, createRscRenderer } from ${JSON.stringify(rscStreamHintsPath)};
298295
299296
const renderToReadableStream = createRscRenderer(_renderToReadableStream);
300-
const prerenderToReadableStream = createRscPrerenderer(async (model, options) =>
301-
_prerender(model, _createClientManifest(), options),
302-
);
297+
const prerenderToReadableStream = createRscPrerenderer(_prerender);
303298
import { createElement } from "react";
304299
import { getNavigationContext as _getNavigationContext } from "next/navigation";
305300
import { configureMemoryCacheHandler as __configureMemoryCacheHandler } from "vinext/shims/cache-handler";

packages/vinext/src/shims/cache-runtime.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export function getCacheContext(): CacheContext | null {
167167
// ---------------------------------------------------------------------------
168168

169169
/**
170-
* RSC serialization APIs from @vitejs/plugin-rsc/react/rsc.
170+
* RSC serialization APIs from @vitejs/plugin-rsc/rsc/server and /rsc/client.
171171
* Lazily loaded because these are only available in the Vite RSC environment
172172
* (they depend on virtual modules set up by @vitejs/plugin-rsc).
173173
* In test environments, the import fails and we fall back to JSON.
@@ -232,7 +232,11 @@ let _rscModule: RscModule | null | typeof NOT_LOADED = NOT_LOADED;
232232
async function getRscModule(): Promise<RscModule | null> {
233233
if (_rscModule !== NOT_LOADED) return _rscModule;
234234
try {
235-
_rscModule = (await import("@vitejs/plugin-rsc/react/rsc")) as RscModule;
235+
const [server, client] = await Promise.all([
236+
import("@vitejs/plugin-rsc/rsc/server"),
237+
import("@vitejs/plugin-rsc/rsc/client"),
238+
]);
239+
_rscModule = { ...server, ...client } as RscModule;
236240
} catch {
237241
_rscModule = null;
238242
}

pnpm-lock.yaml

Lines changed: 49 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ catalog:
4444
"@next/mdx": 16.2.7
4545
recma-codehike: 0.0.1
4646
remark-codehike: 0.0.1
47-
"@vitejs/plugin-rsc": ^0.5.27
47+
"@vitejs/plugin-rsc": ^0.5.29
4848
"@vitest/coverage-istanbul": 4.1.9
4949
better-auth: ^1.5.6
5050
better-sqlite3: ^12.0.0

tests/entry-templates.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,11 @@ describe("App Router entry templates", () => {
12441244
hasServerActions: false,
12451245
});
12461246

1247-
expect(code).toContain('from "@vitejs/plugin-rsc/react/rsc"');
1247+
expect(code).toContain('from "@vitejs/plugin-rsc/rsc/server"');
1248+
expect(code).toContain('from "@vitejs/plugin-rsc/rsc/static"');
1249+
expect(code).not.toContain("@vitejs/plugin-rsc/react/");
1250+
expect(code).not.toContain("@vitejs/plugin-rsc/core/");
1251+
expect(code).not.toContain("@vitejs/plugin-rsc/vendor/");
12481252
expect(code).not.toContain("app-server-action-execution.js");
12491253
expect(code).not.toContain("decodeAction,");
12501254
expect(code).not.toContain("decodeFormState,");

tests/shims.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6803,7 +6803,7 @@ describe('"use cache" runtime', () => {
68036803
});
68046804

68056805
it("falls back to JSON when RSC module is unavailable (test environment)", async () => {
6806-
// In vitest, @vitejs/plugin-rsc/react/rsc is not available (no Vite RSC
6806+
// In vitest, @vitejs/plugin-rsc/rsc entries are not available (no Vite RSC
68076807
// environment). The runtime should gracefully fall back to JSON.stringify
68086808
// for cache values and stableStringify for cache keys.
68096809
const { registerCachedFunction } =

0 commit comments

Comments
 (0)