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(vite): correctly parse --open from forwarded args #9550

Closed
wants to merge 1 commit into from

Conversation

jtoar
Copy link
Contributor

@jtoar jtoar commented Nov 19, 2023

Fixes an issue with our experimental Docker setup.

If browser.open is set to true (which it is by default) in a user's redwood.toml, docker compose -f docker-compose.dev.yml up (which is basically yarn rw dev) breaks:

image

Vite can't find a binary it needs to open the browser. The solution is telling Vite not to open the browser (it's running in a container). Since --fwd was never implemented for Vite, right now yarn rw exp setup-docker codemods the toml file:

image

This is overkill but more importantly it's not a great user experience. It'd be better to just pass --fwd="--open=false" in the Docker compose file.

At first I wanted to solve this by swapping rw-vite-dev for the Vite CLI, but since we handle env vars differently, we can't because the Vite CLI doesn't have an option for disabling env files. I.e. there's no Vite CLI option for this:

envFile: false, // env file is handled by plugins in the redwood-vite plugin

We could see about adding that to Vite. But for right now, let's at least parse --fwd="--open".

@jtoar jtoar added the release:fix This PR is a fix label Nov 19, 2023
@jtoar jtoar added this to the next-release-patch milestone Nov 19, 2023
@jtoar
Copy link
Contributor Author

jtoar commented Nov 19, 2023

Not working yet; seems like this line in the plugin is taking precedence over the config in rw-vite-dev:

open: rwConfig.browser.open,

@Tobbe
Copy link
Member

Tobbe commented Nov 19, 2023

We could see about adding that to Vite.

This got me interested 🙂

So it would probably not be too hard. Here's probably a good entry point: https://github.com/vitejs/vite/blob/b93dfe3e08f56cafe2e549efd80285a12a3dc2f0/packages/vite/src/node/cli.ts#L125

But looking around I found this [1]:

This feature is primarily for frameworks that use Vite under the hood:

  • Frameworks might need to load .env before starting Vite dev server, so they use the loadEnv function provided by Vite.
  • Vite loads .env again when it's unnecessary
  • Vite restarts when .env changes but this should be left to user in this case

That last bullet point caught my attention. They say that if you're using envFile: false (like we are) you're responsible for reloading when the env vars changes. Do we currently do that? And if we just used the Vite cli directly with --env-file=false, how would we handle the reloading?

[1] vitejs/vite#2475

@jtoar
Copy link
Contributor Author

jtoar commented Apr 4, 2024

I think the next the todo here is to make this an issue and add the help wanted label.

Update: see #9209.

@jtoar jtoar closed this Apr 10, 2024
@jtoar jtoar removed this from the next-release-patch milestone Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:fix This PR is a fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants