[WIP] Make UseElmish compatible with Fast Refresh #423
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Thanks for merging #414 @Zaid-Ajaj! I'm trying now to make the
useElmish
hook compatible with HMR, more specifically with the Fast Refresh plugin. I think I've made it work (I'm testing this with Vite and Vite's React plugin) but there are some notes:The only way I could make it work was to inline the function in Debug mode so the plugin could "see" the
useState
hook. FelizHook
Fable plugin (which changes the name of the import so it matches hook standards) didn't seem to have an effect. For the same reason, I had to use the hook bindings from Fable.React instead of the equivalents from Feliz. (If I'm not doing things wrong and Feliz hooks are indeed not compatible with Fast Refresh you may need to consider inlining them too).It seems the effects on connection/disconnection are run during HMR, so we need to be careful not to reset the state.
Again, I'm sending the WIP PR to start a discussion. If the approach looks good I can complete it 👍
cc @MangelMaxime