Is hot reloading with Parcel possible right now?

In a couple of PureScript projects, one Halogen and one Concur and both using Parcel, we don’t have any hot reloading besides CSS.

I see it should be pretty easy to setup simple hot reloading of the app. However, has anyone figured out how to configure hot reloading that preserves state (for either or both of these libraries)?

I’m just wondering if this is possible, and if anyone’s done it. If you have, a rough idea of where to start would be really helpful too (if you have time). Thanks for giving this post your time and consideration! :smiling_face:

It has been asked about a few times for Halogen, but no, there’s not really a general way it can be supported.

We’d have to impose a constraint that all component state is serializable through some means, and also I think it would probably not behave in an ideal way - it would probably have to throw out some or all of the state if the serialized version no longer matched the state schema for the components.

I definitely understand the appeal, I’ve essentially implemented it manually for a project, but that’s because it’s beneficial for the app to maintain state for UX reasons as much as development reasons, and it’s really nice to have the page hot reload and just reflect the changes you made without losing place!

It might be possible to do something with a higher order component to handle the serialization and restoration of state that works for a majority of cases, but it’s not something I’ve looked into. The app I mentioned handles it pretty explicitly in every component that supports it.

1 Like

Thanks for the thoughtful response, Gary! I have an idea of how to implement that sort of explicit state retention, so yeah, I know what you mean and how it’s different from having something that JustWorks™.

Hot reloading + state is a bit of a concern for me, as popular libraries like Vue and React have it out of the box, and it’s very widely used. So now this is another annoying point against PureScript + Halogen that I’ll have to deal with (I’m assuming HMR+retaining state probably works fine with PS + React bindings).

Also, hot reloading’s ubiquity is what allowed Tailwind CSS to become popular: if you can change component markup without having to reload, it’s then possible to iterate quickly through design changes. Personally I dislike Tailwind, but I have to admit it’s very popular, and a large number of developers will disregard Halogen because they won’t be able to use it or tools like it.

By the way, I’m just saying this to be informative, not demanding!

We’d have to impose a constraint that all component state is serializable through some means, and also I think it would probably not behave in an ideal way - it would probably have to throw out some or all of the state if the serialized version no longer matched the state schema for the components.

My feeling is not ideal is better than nothing. In Vue, for example, there are rules regarding state preservation. Those rules can be a bit finicky:

This also means you need to be careful about global side effects such as timers inside your components lifecycle hooks. Sometimes you may need to do a full-page reload if your component produces global side-effects.

I read this is as, ‘Lolle actually you’ll need to press F5 sometimes!’ And yet, the appeal you mentioned seems to outweigh the problems with it.

Without thinking about it too much, I also feel like PureScript — with its strict separation between pure and effectful functions, and its type system — might be capable of doing a better job at HMR+retaining state than React or Vue.