Open kettanaito opened 1 month ago
Seeing the same issue here. I'm trying to debounce calls but it doesn't work because state is not preserved between the two. At first, I thought each run was a different process but process.pid
and process.ppid
are the same, so not sure what's happening here. To illustrate the problem, I've put a variable in the root of my module like so:
let count = 0
And then just do a console.log(count)
followed by a count = count + 1
. I see the "0" twice, the "1" twice, and so on.
Seeing that pid and ppid are the same, the only idea that comes to my mind is that the two calls are using different Node.js module resolvers but honestly I have no idea of the internals of Remix or Vite 🤷
Hope that helps!
@fmvilas, I believe it may be a bit simpler. I think under the hood Remix may be using Vite CLI with the same Vite config twice. One for a dev server, the other for something else.
It would be really great for someone from the team to jump in on this. The issue makes it impossible to author Vite plugins for Remix apps (how other plugins work is also magic; perhaps they are broken too). cc @pcattori @brookslybrand
Yes we are using a "child compiler" (aka a manually instantiated Vite dev server within the main Vite dev server) in order to do some processing. Currently we special case a couple internal plugins to be omitted from the "child compiler".
For example, to support MDX routes we need to be able to detect server-only export in MDX before Vite transpiles it to JS. That way any error messages about server-only exports can reference the original source code rather than the transpiled JS. To be honest, I think the whole "MDX as routes" approach I explored is a dead end and a better approach would be to enforce that routes are JS-syntax parsable (i.e. not MDX) and have a "collections" feature similar to Astro for content like MDX. Then a "blog post" route (written in TS/JS) could show items in the "blog" collection (written in MDX).
That said, our current approach shouldn't cause issues for stateless plugins. However, for stateful plugins this can certainly be an issue. Even so, I do wish that Vite had an API for programmatically applying transformations without needing to spin up an additional dev server.
To be honest, I've been unsatisfied with the trade-offs of the "child compiler" approach and am actively looking for ways to get off of it. Its too magical and brittle at the moment.
Reproduction
This is reproducible on any latest Remix project (sorry for not providing an exact repo, there is literally nothing specific to the app).
vite.config.ts
.console.log(1)
in the root scope of the module.npm run dev
.1
being printed twice.System Info
Used Package Manager
pnpm
Expected Behavior
Vite, its configuration and plugins are executed once.
Actual Behavior
Remix executes everything Vite-related twice. This makes it impossible to write proper Vite plugins as every hook in a plugin will be called twice.
Here are the two calls traced to see their stack traces:
process.pid
is the same across the two calls..ts
config format as well as.mjs
.The look quite identical to me. A bug, perhaps?