react-native-redux-groceries icon indicating copy to clipboard operation
react-native-redux-groceries copied to clipboard

Store and hot reloading

Open magalhini opened this issue 8 years ago • 3 comments

Hey there bruz,

Thanks for the great boilerplate here, so far the most interesting (and easiest) place to start digging into RR + Redux from scratch I've seen 👍

I was wondering if you had any ideas on how to fix the issue of hot-reloading the app, which currently crashes the Simulator every time with:

<Provider> does not support changing store on the fly. It is most likely that you see this error because you updated to Redux 2.x and React Redux 2.x which no longer hot reload reducers automatically. See https://github.com/reactjs/react-redux/releases/tag/v2.0.0 for the migration instructions.

I'm aware of the root cause of the error and I've seen the other reports showing how to fix it (see this issue ) but so far, no luck in getting this fixed... any clues how we'd change your boilerplate?

I've tried adding the following to the configureStore but to no avail:

if (module.hot) {
        module.hot.accept(() => {
            const nextRootReducer = require('../reducers').default;
            store.replaceReducer(nextRootReducer);
        });
    }

Still crashes on every file save, when Hot Reloading is enabled? Any tips? :)

magalhini avatar Dec 04 '16 20:12 magalhini

Interestingly, when I tried enabling hot reloading I got a different error when trying to make a change in Groceries.js:

Firebase App named '[DEFAULT]' already exists

Based on #15 I already had plans to break Firebase out of the React component, so I went ahead and did that to see if it'd help: https://github.com/bruz/react-native-redux-groceries/commit/55b145f7776c4528072e08aa623b028f1ea96598. It also adds essentially the same hot reload handler for the reducers that you show.

Now I get hot module reloading for the Groceries component and the reducer files, which is an improvement, but the actions, store files, App.js or index.(ios|android).js all still hit that Firebase error.

bruz avatar Dec 08 '16 06:12 bruz

@bruz thanks for sharing your good work with us. Are there some updates about this topic?

WoodyPhil avatar Sep 27 '17 15:09 WoodyPhil

@WoodyPhil I took another look at this but wasn't able to find a way around the issue with Firebase. Based on https://github.com/zeit/next.js/issues/1999#issuecomment-302244429 I tried to add a check so that initializeApp would only get called once and it would use an existing app instance if it was already defined, but couldn't get it working.

I suspect there may be a way to do it through the hot reloading API with module.hot.accept or something like that, but I don't know hot reloading very well so maybe someone else will know how to approach this better.

bruz avatar Oct 03 '17 05:10 bruz