-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Remix Dev Server #4838
Comments
One of the main complaints against Remix App Server is that you can't configure it to support SSL. Some devs want to use certificates on dev to match production. Will the new dev server allow you to set up a certificate? This also affects the web socket server. |
It will make building developer tooling so much easier. Awesome 👏 👏 👏 |
+1 ^ If you're self-hosting Remix ,the scenario of making your remix server an HTTPS server is more likely. Others might say wonder? Why not put NGINX or a proxy server in front of your Remix server? @kiliman had a proposal enabling Remix App Server to support HTTPs without needing to eject Maybe the HTTPS is out of scope, mostly bringing this up because I want every remix dev to have a smoother onboarding experience / integration with their infra 🤝 ⚛️ |
Building on this: TailwindUI works by running its own process to continually process
(This may already be solved with a debounce. If so, this just serves as a reminder to make sure that protection makes it through to the new implementation.) |
Perhaps the new Dev Server can include an option for one or more processes to launch (including tailwind watcher for example).
Currently, there is Maybe a So using the scenario above:
|
@pcattori has a couple more things to do and then after a thumbs up review we should be able to merge. Expecting to be done today. |
Will this solution address the issue #1555 where the dev server runs out of memory and crashes?. |
@sciutand yes the new dev server doesn't do any require cache purging, so if that was the cause of your issue, that will should be gone once you opt-in to the new dev server |
@scottcorgan Usually remix provide a feature flag for experimental feature that you can define in |
@scottcorgan like @izznatsir said, we're providing a future flag ( |
Discussed in #4664
Originally posted by ryanflorence November 21, 2022
PRs
Remix Dev Server
Instead of just a file watcher that writes files with
remix watch
, we should have a dev server receive requests, serve the asset, then proxy everything else to the real server. This should make building developer tooling better for us and our users better (live reload, HMR, faster incremental builds, forwarding build errors to a browser modal, etc.)Background
Two important concepts drove today’s Remix’s
npm run dev
design:How it works today: two processes
Two Processes need to run for remix development today:
remix watch
and a command to run a server likenode server.js
orwrangler dev
etc.remix.config.js
to know where to write the server and client build artifacts. It does not receive requests, it just spits out files where the web server is reading from.node server.js
, requires the server build thatremix watch
created (it’s just a module in the end) and uses it as the request handler. When the page is viewed in the browser, the assetsremix watch
created are requested from the actual server, as long as it’s correctly configured to server them of course!In other words: dev and production are identical when it comes to what happens when a request for a document or a static asset is made. The server (
node server.js
) serves everything.remix watch
simply created the modules for the server and client. In this way, Remix can be deployed anywhere.The exception: remix dev + remix-serve
For developers who don’t care to run their own server, the
remix-serve
package creates an express app configured just enough to run a Remix app. It has an integration with the remix CLI to run both the watcher (fromremix watch
) and the express server in the same process.Problems today
Requiring two processes is annoying. Many developers today are not used to owning so much of the stack (which is why we created
remix-serve
).Ports and Live Reload. It’s actually surprisingly difficult to develop two Remix apps at the same time. When you have two processes you can’t simply provide a
--port 3001
cli option. You may dowrangler dev --port 3000
for one app andnodemon server.js --port 3001
in another. That’s fine for the servers but the live reload web socket, that’s part ofremix watch
needs to specify a port too, and that port needs to be known for both SSR (server bundles) and in the browser (client bundles). In order to get the correct web socket port for bothremix watch
andwrangler dev
, we use an environment variable which is not only cumbersome but also super weird: it’s read at runtime for the server render (actual environment variable) but bundled as a static value into the client modules (not actually an environment variable!).Perhaps in the live reload case, we could figure out a better way to do it (like a cli option that gets bundled directly into both client/server bundles) but it illustrates the point well that having two processes in development adds some complexity. In fact, there have been a bunch of breakages around live reload in various commits because folks both outside and inside of Remix because they didn’t understand all the moving parts.
Proposal
I’m proposing we change the way Remix works in development by introducing a development server. Instead of requests always coming to the real server in development (
node server.js
), requests come to a Remix development server.API
remix.config.js
has a newdev
field that indicates how to spawn your development serverremix dev
boots a development server that also spawns the real serverWhen a requests comes in, the dev server matches it against the
remix.config
for assets, if it matches, it serves the file (with some bundling). If it doesn’t match, it proxies the request to the real server.Expected benefits
Having a persistent dev server should make all of the “DX” things we want to do easier to deal with because we get to receive the requests first.
concurrently
andpm2-dev
have race conditions where the browser reloaded when files changed but the builds aren't done!The core benefit is that we are in control of when to notify the browser of anything with a persistent server that owns both processes. By spawning a child process for the real server, we also don’t lose the “development and production are nearly identical” either. All assets are bundled the same, served from the same URLs controlled by remix.config.
The text was updated successfully, but these errors were encountered: