Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(remix-dev/vite): start SSR build within plugin #8206

Closed
wants to merge 3 commits into from

Conversation

markdalgleish
Copy link
Member

@markdalgleish markdalgleish commented Dec 4, 2023

tl;dr: You only need to run vite build now, not vite build && vite build --ssr 🎉

Since we're trying to stabilise the Vite API, I realised that consumers need to stop co-ordinating multiple Vite builds as they're doing today. This is because we're looking at adding support for server bundle shredding (i.e. multiple request handlers, not just one) and RSC, and both of these would mean that we won't know how many builds there will be ahead of time. To handle both of these scenarios, this PR adds a queue where we can push subsequent Vite build processes from within the initial vite build pass.

By the way, after this change I tried running vite build && vite build --ssr and it still works, it's just slower due to the double SSR build.

An alternative approach to this would be to wrap Vite in the Remix CLI (remix vite:build etc., or something similar), but that introduces its own set of complexity since we'd need to forward everything from our CLI to Vite, manage args parsing and validation, keep up to date with Vite CLI API changes etc. I initially went down this road and it started feeling too heavy, so I pivoted to the approach in this PR instead to see how we felt about it. It's nice that we get to continue being "just a Vite plugin", but it's a bit non-standard the way we're achieving it. I'm keen to get some feedback on it.

Todo:

  • Confirm that CLI args are passed to the child SSR build (e.g. vite build --assetsInlineLimit <number>)

UPDATE: While this solution is clever, it has some major drawbacks that I'm referring to as the "uncanny valley effect", one example of which is the question @mmachatschek raised below, but this is certainly not the only issue. I've opened another PR with a more traditional solution that addresses these tradeoffs: #8211.

Copy link

changeset-bot bot commented Dec 4, 2023

🦋 Changeset detected

Latest commit: c42b31f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
@remix-run/dev Patch
create-remix Patch
remix Patch
@remix-run/architect Patch
@remix-run/cloudflare Patch
@remix-run/cloudflare-pages Patch
@remix-run/cloudflare-workers Patch
@remix-run/css-bundle Patch
@remix-run/deno Patch
@remix-run/eslint-config Patch
@remix-run/express Patch
@remix-run/node Patch
@remix-run/react Patch
@remix-run/serve Patch
@remix-run/server-runtime Patch
@remix-run/testing Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@markdalgleish markdalgleish changed the title fix(remix-run/vite): start SSR build within plugin fix(remix-dev/vite): start SSR build within plugin Dec 4, 2023
@mmachatschek
Copy link

With the previous setup, one could select different cli args between client and SSR builds (e.g. --sourcemap). how can we achieve the same behaviour of this with a single vite build command?

vite build && vite build --ssr --sourcemap

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Dec 4, 2023

@mmachatschek I think users can still customize it using functional config, for example:

import { defineConfig } from "vite";

export default defineConfig((env) => ({
  build: {
    sourcemap: env.isSsrBuild,
  },
}));

I would prefer this form regardless of this PR's change since, in this way, vite.config.ts represents full information of the build instead of needing to check specific flags in scripts.

Copy link
Member Author

@markdalgleish markdalgleish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a fun experiment while it lasted, but we're closing this in favour of #8211 where you can find some more explanation for the shift in our approach.

@markdalgleish markdalgleish deleted the markdalgleish/single-vite-build branch December 5, 2023 03:33
@markdalgleish
Copy link
Member Author

@mmachatschek Thanks for raising that question by the way, it helped flesh out a big tradeoff with this approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants