remix: [Bug]: Live Reload not working.
Which Remix packages are impacted?
remix(Remix core)@remix-run/react@remix-run/serve
What version of Remix are you using?
1.1.3
What version of Node are you using? Minimum supported version is 14.
14.17.4
Steps to Reproduce
- starting from the Quickstart template.
- create a posts route.
- navigate to route
- the route does not show up
Every step along the way I have to restart the dev server to see the changes in the web. For example I added
export default function Posts() {
const posts = useLoaderData();
console.log('test3');
return (
<div>
<h1>Posts</h1>
</div>
);
}
and the console still shows that it reloaded but still shows test2 (the value from when the dev server started)
Navigated to http://10.202.57.104:3000/posts index.tsx:18 test2 posts:23 šæ File changed: app\routes\posts\index.tsx posts:23 šæ Rebuilding⦠posts:23 šæ Rebuilt in 201ms posts:26 šæ Reloading window ⦠Navigated to http://10.202.57.104:3000/posts index.tsx:18 test2
Iām on Windows using Chrome(97.0.4692.71) and Edge(Version 97.0.1072.62), both failed
Expected Behavior
the hot reload should show the changes without having to restart
Actual Behavior
I have to stop the dev server and restart to see any changes
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 56
- Comments: 102 (17 by maintainers)
Iām also using Windows and I realized hot-reloads only work when I make changes inside the app directory of my Remix project. I donāt know if this is how it is supposed to work or itās a bug!
<LiveReload/>is a simple component. You can simply inline it in your root route.Had the same issue. Fixed by changing
remix.confix.jsfrom:to:
same problem here on Windows and
create-remix, Iām trying to follow the QuickStart tutorial but it doesnāt reload š¢I still have not found a solution other than it the hot-reloading it working on my Linux machine but refuses to work on Windows.
This is the most basic feature a frontend dev framework should have; itās not working in Nov/2023 so Iāll report to my team Remix is not worth considering yet š
The official remix tutorial runs straight into this problem. Not a good first experience with the framework
This is the only solution that worked for me
I donāt mean to +1, but Iām also getting the issue on mac, with a fresh vercel/ts boilerplate.
So the simple straightforward answer is:
In remix.config.js, add:
devServerPort: 8002,Just that should fix the Live Reload, with its default port.And when youād want to change that default port, also add this change to the LiveReload component in root.tsx:
<LiveReload port={8082}/>It is working, but we have to improve the documentation because itād work properly if you keep your code inside the
/appdirectory.In my case I have all my components inside the
./appfolder. But hot-reload is still not work. I am on MacOSInteresting observation. I was struggling with this and your point made me realize I currently have all my components in a
components/folder outside of myapp/directory. I just did a brief experiment and moving a component into theapp/directory seems to fix it ā i.e. causes changes to reflect on the hot reload live.As a possible feature, could we provide paths to whatever is watching the filesystem for hot reload?
There seem to be multiple different issues people are running into.
Named exports
Named exports are required for HMR. Note that this is a limitation of React Fast Refresh, not Remix. Thus the same limitation is present in Vite and Next.
Code outside of
app/dirExpecting changes outside of
app/to trigger hot updates. As already mentioned, you can add those paths towatchPaths, but weād recommend keeping all your app code withinapp/anyway.LiveReloadbeforeScripts(Vite)This limitation has been removed from unstable Vite support. The order of
LiveReloadandScriptsno longer matters.Quickstart/Tutorial not working
@BoilingSoup I couldnāt reproduce this error, but if you are still running into it could you file a separate issue?
This issue was already too broad when it was first created, so moving forward please file separate issues with your specific problem so that we can make sure we prioritize a fix.
I was having the same issue with the blues stack, I started with the template that had LiveReload after Scripts. I changed the order now where LiveReload comes first, and now it is fixed. This is important if you are using vitest. Source: https://remix.run/docs/en/main/future/vite#livereload-before-scripts
From root.tsx:
LiveReload is still not working in version 1.13. If you include the
<Scripts/>import from ā@remix-run/reactā, then it works.This worked for me! Thanks @nilobarp After a server restart that reload was hot hot hot š„
to clarify the workaround that some other people have suggested, the Remix project needs to be installed in the WSL only portion of the WSL filesystem. it may look like
/mnt/c/Users/[username]/projects/my-remix-appis in the WSL filesystem but since itās an abstraction of the Windows filesystem it will not work. however, it should work fine if you set up the project in/home/[username]/my-remix-appfor example. the reason this works is the WSL filesystem is able to detect file changes in its own virtualized environment but not in its abstraction of the Windows filesystemthis workaround requires setting up your code editor to point to the WSL files which isnāt an option for everyone, so I support an option for polling to be added as a short term solution while WSL itself gets the bug fixed
Same issue on MacOS. Nothing makes it work for me, even if i remove the
process.env.NODE_ENVcheck around<LiveReload/>I have reproduced the issue on
1.1.31.1.2and1.1.1so downgrading does not appear to help.I am using
arc sandbox- so this may be affecting it.Its dropped the Remix DX from a 10/10 down to a 1/10. Iāve had to put my project on hold until this is fixed. š¦
All my components are inside the app directory
https://github.com/remix-run/remix/issues/7466
It is here.
I fix this by adding the
componentsdirectory that I have outside of theappdirectory in thewatchPathsarray, myremix.conf.jsfile looks like this:Live reload does not seem to work for the socket.io example.
Setting
devServerPortdoesnāt appear to make a difference in this case.remix watchis seeing the file changes and rebuilding, and there is a websocket open on 8002. No errors in the browser console, and on initial page load we have successful connection to the websocket at 8002, but no network activity happens in response to the change, and reload requires manually refreshing the page.Netlify Starter is not hot/live reloading.
The OS doesnāt matter. I tried in both macOS and Windows10. It doesnāt show any errors on the terminal. The changes on files donāt make the browser reload.
Hot reload doesnāt work for me on
create-remix@1.3.3with the starter templates. Iām on Windows with WSL2.I dug a little deeper and found the root cause here: https://github.com/microsoft/WSL/issues/4739
This issue comes up across many tools, and the workaround is often to switch to polling.
chokidarprovides theusePollingflag: https://github.com/paulmillr/chokidar#performanceusePollingflag fromchokidarfor this exact reason: https://vitejs.dev/config/#server-watchesbuildwatch mode uses polling by default: https://esbuild.github.io/api/#watchMaybe remix should also offer a polling option?
https://twitter.com/markdalgleish/status/1736240852308251053
https://github.com/remix-run/remix/pull/8266
this helped!!! thanks so much š
Should be fixed by #5339
Apologies, yes 1.12. I had NextJS 13 in my head as Iām trying different SSR frameworks out!. Yes, 1.12, but the rest of what I stated still stands.
My apologies.
@Ali-Parandeh You already mentioned that, Iām not sure repeating it is helpful š
In case it helps others, I tried a bunch of the stuff above before realising that Remix does ālive reloadsā and not āhot module replacementā aka HMR.
So live reloads were actually working (e.g. page was reloaded on changes automatically), but I was assuming that it should be doing HMR (e.g. changes updated in place without reloading the entire page). This is not the case.
Thereās a good discussion here (https://github.com/remix-run/remix/discussions/2384) about HMR support, which will hopefully land eventually, although I appreciate the reasoning behind leaving it out currently.
What fixed the issue for me was setting an explicit
portprop onLiveReload:It will stop attempting to look up the default value from the
processthen.Managed to fix this: Because the live reload is just a WebSocket, it wasnāt by default published in Docker So I provided a fixed port in remix.config.js:
And published the port in my docker-compose.yml:
Hope this helps someone
I just updated to 1.5.1 and still am experiencing this issue. Am I the only one? I tried to play with the port (3000, 3001⦠instead of the deafault 8002), but nothing works.
EDIT: I just ran the jokes app and it works there. Iāll investigate what in the Blues Stack is messing with the LiveReload.
EDIT2: I just ran a fresh Blues Stack and it does indeed fails to connect to the websocket. I guess Iāll migrate my code to a simple create-remix template.
EDIT3: Moving my code to a fresh simple create-remix template (Remix App Server) did the work! Hot reload is back baby š
@LukeXF Are you on Mac or Windows?
Did you add/change
devServerPortin remix.config?Also check to see if
REMIX_DEV_SERVER_WS_PORTenvironment variable is defined.Worst case, just update your
devscript to:"cross-env NODE_ENV=development PORT=3000 REMIX_DEV_SERVER_WS_PORT=8002 remix dev"Also, try to connect to the web socket server using your browser: http://localhost:8002
You should see the message āUpgrade Requiredā
I believe there was a bug in the dev tool in that it wasnāt passing the
REMIX_DEV_SERVER_WS_PORTvariable to the compiler. Have you tried the latest version? Remix now gets a random unused port for the WS port.@nilobarp Thatās already in my
remix.config.js. Why would it matter either way? My best guess is these āsolutionsā are all part of an elaborate April fools prank. šThx.
FIY everybody, if you move to Remix Stack (Blues) there is no issue with hot reloading in WSL2. It is using pm2 server internally for that, AFAIK. Thatās what I did.
@Tymek the warning is unrelated, check #1077