Skip to content

When Do You Actually Need SSR in Vite?

For the longest time, I felt like building applications as standard SPAs with Vite was more than enough.

3 min read
Vite
SSR
SPA
React
Rendering
Frontend

For the longest time, I felt like building applications as standard SPAs with Vite was more than enough. The workflow is great—it's fast, lightweight, and mostly drama-free. But there comes a point where that comfort starts to wear thin, specifically when you start caring about what a user actually sees the very first second they click a link.

If you're just building an internal dashboard that requires a login, don't overthink it. Just stick to standard CSR. But the moment you deal with public pages, SEO, or social media link previews, you run into a wall. Without SSR, search engines or bots often just see a blank page and a loading spinner.

That’s where Server-Side Rendering (SSR) comes in. Vite technically supports this through its API, but I don't think you should just force SSR onto everything. It isn't just a checkbox in your config; you're essentially managing two different runtimes.

Technically, using SSR in Vite means a dual build process. You end up with a bundle for the client side and a bundle for the server side. In development, Vite acts as middleware to transform modules on the fly, but in production, your Node.js server executes that code to generate HTML before it even hits the browser.

But let’s be honest: using SSR comes with a complexity "tax." It's a trade-off you have to accept with your eyes wide open.

One of the biggest headaches is hydration mismatch. This happens when the HTML generated by the server doesn't match what the JavaScript tries to render first in the browser. The cause is usually classic: trying to access browser-only objects like window or localStorage directly inside a render function. When that happens, the UI might flicker or just straight-up error out. You also have to be extra careful managing data to avoid "double-fetching" between the server and the client.

So, what's the difference between using a Vite SSR plugin and just jumping straight into a meta-framework like Next.js or Remix?

In my opinion, using a Vite plugin or template makes more sense if you want to maintain full control over your own server. This works well if your app is mostly an SPA but needs just a few specific routes to be server-rendered. You get total control, but you also have to be the one to fix things if the middleware or that dual-build process breaks.

On the other hand, if you don't want to deal with the headache of routing, data loading, and deployment, just use a meta-framework. They have the conventions already baked in so the team can just blast ahead coding without building the server infrastructure from scratch.

Ultimately, moving to SSR shouldn't be about following a trend, but about a real need. Does your app need strong SEO? Do you want to avoid annoying layout shifts during page loads? If yes, go for it—even if it has its downsides in terms of management effort.

Enough for this note.