martpie / museeks

🎵 A simple, clean and cross-platform music player
https://museeks.io
MIT License
1.71k stars 200 forks source link

Fix loaders and react-query getting numb after HMR #787

Closed martpie closed 2 months ago

martpie commented 2 months ago

Because of HMR, some modules would be re-executed and singletons would be recreated. Typically, the whole router in vase a ViewXXX component would be updated, and the queryClient for react-query.

Weirdly, the invalidate() function would not work anymore (I tried a loooot of things).

This PR moves the routes data invalidation closer to the actual mutation, and move it out of the APIs. It's less clean and easier to miss when adding new code, but at the same time a bit more "correct" and it fixes the HMR issues.

If anyone has a better solution for this problem, feel free to share.