infinitered / ignite

Infinite Red's battle-tested React Native project boilerplate, along with a CLI, component/model generators, and more! 9 years of continuous development and counting.
MIT License
17.71k stars 1.4k forks source link

[Base] - Fix hot reloading #155

Closed GantMan closed 8 years ago

GantMan commented 8 years ago

Smart components have a provider error in some situations. @skellock says this is because of how we're replacing the reducers, instead of properly adding them in this situation.

simulator screen shot jun 8 2016 12 48 43 pm

bradennapier commented 8 years ago

+1 - running into this , hot reloading doesnt seem to work -- just tried to update the drawer

GantMan commented 8 years ago

if you update a component, it works. Any container it doesn't.

GantMan commented 8 years ago

We can fix this, though.

bradennapier commented 8 years ago

I was just updating the Root.js or w/e playing with it and changiing the text. I added this to the Store.js and it fixed it in some places but in others I still get the issue such as within the Themes etc.


if (module.hot) {
    // Enable Webpack hot module replacement for reducers
    module.hot.accept('../reducers', () => {
      const nextRootReducer = require('../Reducers/index');
      store.replaceReducer(nextRootReducer);
    });
  }
skellock commented 8 years ago

Fantastic!

phoenecke commented 8 years ago

The problem with changing things in the Themes folder, is that it is imported into the component that creates the store (Root.js). This is mentioned here:

https://github.com/reactjs/react-redux/issues/347

I played around with it a little, and changed Root.js to be:

import React from 'react'
import configureStore from './Store/Store'
import App from './App'

const store = configureStore()

export default class RNBase extends React.Component {
  render () {
    return <App {...this.props} store={store} />
  }
};

Then, App.js is the old Root.js, minus the configureStore call. I am not set up to test on Android right now, so I didn't try to make a PR.

hot

GantMan commented 8 years ago

@phoenecke - that's the best solution yet! I tested it on iOS and Android with perfect success! I changed the style just a little, but we're good! Thanks so much! This will be in master soon.

I'll be sure to give you credit in the release docs

GantMan commented 8 years ago

https://github.com/infinitered/ignite/pull/197

cinan commented 8 years ago

I can still reproduce the bug, shouldn't it be fixed? Ignite 1.8.0

GantMan commented 8 years ago

depends, what are you editing? The app.js? or the styles?

The app.js hot reloading will eventually be fixed by @skellock - He knows why it doesn't work. Though if you know the solution, feel free to PR :)

skellock commented 8 years ago

Are you editing a saga or reducer? If so, then it's still an issue because we haven't hotloaded redux just yet.

skellock commented 8 years ago

This fix was for visual things: basically everything in themes.

skellock commented 8 years ago

Here's an example of the way out:

https://github.com/erikras/react-redux-universal-hot-example/blob/master/src/redux/create.js#L28-L32

And

http://stackoverflow.com/questions/34243684/make-redux-reducers-and-other-non-components-hot-loadable

I really want to do this fix, but there's a thousand things on my plate and I'm failing at all them. Haha.

cinan commented 8 years ago

I see, I guessed it has been already fixed (because of Closed status), sorry :)

handycode commented 7 years ago

@phoenecke nice solution!

Fr33maan commented 7 years ago

I keep having this issue with new Apps when I try to update reducers/sagas.

I've made a PR for that -> https://github.com/infinitered/ignite-ir-boilerplate/pull/143

@skellock I guess you are under heavy loading so I made it for you <3