News for hackers. Stuff that matters.
Re:Migrating from Create React App to Vite by lyxell on Thursday October 17, 2024 @04:29AM (#41867550)
With Vite you do not have to hack together Hot Module Reloading yourself.
Re:Migrating from Create React App to Vite by auggierose on Thursday October 17, 2024 @05:04AM (#41867726)
esbuild has live reloading, which works great. No hacking needed.

Edit: I don't know how Vite's HMR works, but it wouldn't surprise me if it is just piggybacking on esbuild's live reloading. Anyone here knows if there is a difference between the two?

Re:Migrating from Create React App to Vite by yurishimo on Thursday October 17, 2024 @06:40AM (#41868262)
When you say "live reloading", does that mean updating the component while maintaining state (HMR) or just triggering some sort of global page refresh?

My guess is that Vite relies on underlying tools as much as possible and only ejects when they need to. This is also why they are writing their own version of esbuild/rollup so that more of the dev pipeline can be controlled by Vite.

Re:Migrating from Create React App to Vite by auggierose on Thursday October 17, 2024 @06:56AM (#41868356)
What I mean by "live reloading" is that when you for example save a TypeScript file, esbuild does an incremental build and your webpage can check for that and reload. There is no state maintained. I think maintaining state would be a very difficult problem to solve correctly. Actually, I think that is impossible, and invites all sorts of heisenbugs, working only for simple cases.
Re:Migrating from Create React App to Vite by lyxell on Thursday October 17, 2024 @08:28AM (#41869019)
I’ve used both standalone esbuild as well as Vite for hundreds of hours and HMR works flawlessly in React using Vite, it’s the only reason I use Vite instead of just using esbuild directly. I suggest you to try it out.
Re:Migrating from Create React App to Vite by ativzzz on Thursday October 17, 2024 @10:17AM (#41869912)
I've been working with web apps for a long time and have always turned live reloading off whenever I can.

My code editor always auto saves changes so i just alt tab to browser and refresh to see changes

With live reload, often what happens, especially as projects get larger, is the watcher takes longer to trigger so the live reload is slower than just alt-tabbing, and it sometimes goes off on its own, probably due to multiple quick file changes, which is really annoying

I've never enjoyed this feature

Re:Migrating from Create React App to Vite by ddoolin on Thursday October 17, 2024 @04:53PM (#41873685)
It must not be that difficult as I use it every day in my Vite project. To be clear I am no Vite evangelist, but it does maintain existing state when it live reloads modules, it doesn't just refresh the page.
Re:Migrating from Create React App to Vite by Aldipower on Thursday October 17, 2024 @04:48AM (#41867641)
Thanks, so I won't use vite. Hot Module Realoading never worked reliable to me.
Re:Migrating from Create React App to Vite by homebrewer on Thursday October 17, 2024 @06:21AM (#41868159)
CRA's HMR is a mess that breaks more often than it works, but I haven't had any problems with Vite's HMR after using it for the past three (I think?) years.
Re:Migrating from Create React App to Vite by conradfr on Thursday October 17, 2024 @05:03AM (#41867722)
Because you did not use Vite.
Re:Migrating from Create React App to Vite by lyxell on Thursday October 17, 2024 @08:25AM (#41868994)
I can’t speak for how it works in other frameworks but HMR for React works flawlessly in Vite.