Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redux examples has the Provider HMR Warning #369

Closed
howardya opened this issue Oct 6, 2017 · 5 comments
Closed

Redux examples has the Provider HMR Warning #369

howardya opened this issue Oct 6, 2017 · 5 comments

Comments

@howardya
Copy link
Contributor

howardya commented Oct 6, 2017

Reproduce, git clone.
cd examples/with-redux
yarn
yarn start

then change any file, for instance, common/components/Counter.js, HMR will work, but browser will sound the following warning

<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 have tried to google around this error, but does not find any food solution to it. Anyone manage to overcome this?

@howardya
Copy link
Contributor Author

howardya commented Oct 9, 2017

I added the following code to the file client.js and it removes the warning.

if (module.hot) {
  module.hot.accept();
  module.hot.accept('./App', () => {
    hydrate(
      <Provider store={store}>
        <BrowserRouter>
          <App />
        </BrowserRouter>
      </Provider>,
      document.getElementById('app')
    );
  });
}

Anyone has any view of this?

@jaredpalmer
Copy link
Owner

Can you submit a PR?

@Metnew
Copy link

Metnew commented Feb 8, 2018

Add key={Math.random()} prop to <Provider>. It should fix this warning.

@benhamlin
Copy link
Contributor

@howardya's solution is the better one here. Using a random key silences the warning but doesn't change the fact that the store is being recreated on every update, which is what's not supported. It can lead to some wonky behavior, especially if you're using redux dev-tools or similar.

By specifically handling the ./App module, that will catch virtually all updates except for reducers, which is already handled separately. That leaves changes to configureStore.js and client/index.js itself as unhandled. You can either leave the catch-all in, which would rerun everything and still cause the warning, or remove it, which triggers a page reload. I think the latter would be more correct here.

I'll take a look at making a PR for this.

@alleniver
Copy link

Add key={Math.random()} prop to <Provider>. It should fix this warning.

solve my problem! thanks man.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants