Skip to content

fix(plugin-rsc): skip build-only generateBundle in bundledDev#1296

Open
mellyeliu wants to merge 2 commits into
vitejs:mainfrom
mellyeliu:fix/rsc-bundled-dev-generatebundle
Open

fix(plugin-rsc): skip build-only generateBundle in bundledDev#1296
mellyeliu wants to merge 2 commits into
vitejs:mainfrom
mellyeliu:fix/rsc-bundled-dev-generatebundle

Conversation

@mellyeliu

Copy link
Copy Markdown

Context

experimental.bundledDev: true crashes the dev server on startup:

TypeError: Cannot convert undefined or null to object
    at generateBundle (virtual:vite-rsc/assets-manifest)

The assets-manifest manifest is served two ways: the load hook builds it in dev, and generateBundle builds it in production from manager.bundles['rsc']. In normal dev, generateBundle never runs. In bundledDev the client environment runs a Rollup build while mode === 'dev', so generateBundle fires, but there's no RSC build, so manager.bundles['rsc'] is undefined and Object.values(rscBundle) throws.

The fix is to return early from generateBundle in dev, since the load hook already provides the manifest there.

(Production builds and are unaffected)

Testing

  • plugin-rsc unit suite passes (448/448).
  • Ran a real RSC app (SSR + use client/use server + hydration) with bundledDev: true: crashed before, works after, dev server starts and serves a correct RSC response.
  • Production build of the same app still succeeds.
  • Added e2e/bundled-dev.test.ts (runs examples/starter with --experimental-bundle). I couldn't run the Playwright suite locally, so CI should confirm it

In bundledDev mode the client environment runs a Rollup build while
mode === 'dev', so the assets-manifest generateBundle hook fires even
though no RSC build output exists. It then reads manager.bundles['rsc']
(populated only by a production build) and crashes with
'TypeError: Cannot convert undefined or null to object'.

The dev manifest is already served by the load hook, so the build-only
asset copying and buildAssetsManifest construction are unnecessary in dev.
Return early when mode === 'dev'.
Reuses examples/basic with 'pnpm dev --experimental-bundle' and asserts the
dev server starts, renders, and hydrates without the generateBundle crash.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant