question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hooks are not called when using webpack-dev-server and HMR

See original GitHub issue

Note: I wasn’t sure if it made sense to open this issue here or in the webpack repo… sorry if it doesn’t make sense!

Do you want to request a feature or report a bug? bug

What is the current behavior? Hooks are not being called when using webpack-dev-server with HotModuleReplacementPlugin

More specifically (see link to repo for source code): The callback given to useEffect is not run and typing into the input does no update

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn’t have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:

I have created a repository that reproduces the bug: https://github.com/terrencewwong/hooks-webpack-hmr-bug

What is the expected behavior?

  1. The callback given to useEffect should run and log “USING EFFECT WITH HMR”
  2. Typing into the input should update the text state: …

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

React:16.7.0-alpha.0 I’m using Mac OS 10.13.6 and Chrome 70.0.3538.77

Did this work in previous versions of React?

No

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
gaearoncommented, Nov 7, 2018

Please file this issue with react-hot-loader (ironically I started that project, but I’m not currently maintaining it). Due to lack of certain necessary features in React, this project currently uses some techniques which break Hooks. AFAIK there’s some way to work around them, although I’m not sure what those are exactly. You can probably search that repo’s issues for mentions of Hooks.

I plan to work on fixing this since Hooks should enable us to implement hot reloading in a much simpler way.

0reactions
andersblomcommented, Nov 9, 2018

There’s no reason why Hooks wouldn’t work in development mode 🙂

I think React Hot Loader just does the hacky stuff in dev mode only. Which is why disabling it fixes the issue.

But we don’t recommend disabling development mode in development.

Ah, right. I wasn’t implying it was a Hooks problem, although I can see it might have come across like that. My bad - and you’re totally right, if I use Hooks without HMR in development mode everything works!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hot Module Replacement - webpack
All we need to do is update our webpack-dev-server configuration, and use webpack's built-in HMR plugin. We'll also remove the entry point for...
Read more >
Hot reload not working with react and webpack - Stack Overflow
React hot loader currently doesn't work with hooks. See gaearon/react-hot-loader#1088 for details.
Read more >
Webpack's Hot Module Replacement Feature Explained
HMR allows you to exchange, add, or remove JavaScript modules while the application is running, all without having to reload the browser. This ......
Read more >
Webpack Dev Server (webpack-dev-server) Hot Module ...
... Webpack Dev Server (webpack-dev-server) Hot Module Replacement (HMR) Not Working-Reactjs. ... And I use following code in app.js in my react.js project....
Read more >
HMR and Hot Reloading with the webpack-dev-server
If you are not using server-side rendering (not using prerender: true ), then you can follow all the regular docs for using the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found