nuxt/nuxt

ssr: false Routes Are Bundled in Server Output

Open

#30786 opened on Jan 27, 2025

View on GitHub
 (2 comments) (2 reactions) (0 assignees)TypeScript (60,221 stars) (5,607 forks)batch import
good first issue🍰 p2-nice-to-have

Description

Environment

  • Operating System: Linux
  • Node Version: v18.20.3
  • Nuxt Version: 3.15.3
  • CLI Version: 3.20.0
  • Nitro Version: 2.10.4
  • Package Manager: npm@10.2.3
  • Builder: -
  • User Config: compatibilityDate, routeRules, devtools, sourcemap
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-otbzpuzh

  1. Build the project using npm run build
  2. Inspect the .nuxt/dist/server/_nuxt/spa.js file which includes the <TextEditor> component

Describe the bug

When setting ssr: false for specific routes in routeRules, the expected behavior is for these routes to be excluded from the server bundle and executed entirely on the client side. However, the routes are still bundled into the server, defeating the purpose of ssr: false. This forces the use of <ClientOnly> or similar workarounds, which is not desirable.

Additional context

My use case involves an SSR Nuxt app that includes a large number of /admin SPA pages. These routes are intended to run entirely on the client. While setting ssr: false for /admin/** routes works as expected in terms of rendering, Nuxt still includes all their code in the server bundle. Currently, I am forced to wrap every SPA route's content in a <ClientOnly> component or use conditional checks like if (import.meta.client) for tree-shaking. Also making page components as .client.vue didn't work for me

Logs

Contributor guide