keajs / kea

Batteries Included State Management for React
https://keajs.org/
MIT License
1.94k stars 51 forks source link

React native fast refresh support #119

Closed sanchezweezer closed 2 years ago

sanchezweezer commented 3 years ago

after edit file with logic (then it mounted) in expo it fails on fast refresh, because of fast refresh mechanism.

Screenshot 2020-12-19 at 20 46 19
mariusandra commented 3 years ago

Documenting that I'm seeing the same errors with fast refresh using create react app (using the Kea CRA template).

The solution for CRA for now is to add FAST_REFRESH=false to .env unfortunately.

I'd love to solve this though. Right now it seemed that React or something is just calling the cleanup function of useEffect inside useMountedLogic inside useValues, which then removes the values from redux. I'm not sure why as hooks shouldn't change with fast refresh.

mariusandra commented 3 years ago

I found a fix for the crashing. I'll release it with Kea 2.4 as soon as I track down one last issue. With the patch applied, if using React.StrictMode logics just won't refresh. Without strict mode, everything works. We won't hot-replace logic, but it'll be unloaded and loaded as needed. I think that's good enough for now :)

mariusandra commented 3 years ago

Kea 2.4 is out with support for this. In case logics don't reload after a change, just disable React.StrictMode for now. :|