Description
Describe the bug
Hot reloading when the redux-state change stopped working when I use CRA to get the last React version. Noticed that it is due to React version and I made a test creating a new react project, as a result the package.json shows
"dependencies": {
"@testing-library/jest-dom": "^5.11.5",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-redux": "^7.2.1",
"react-scripts": "4.0.0",
"redux": "^4.0.5",
"web-vitals": "^0.2.4"
},
then change it to a previous version of react (copied from an old project)
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-redux": "^7.2.1",
"react-scripts": "3.4.3",
"redux": "^4.0.5"
},
And it continue to works as always.
Did you try recovering your dependencies?
yes
Environment
current version of create-react-app: 4.0.0
running from C:\Users\stewa\AppData\Roaming\npm\node_modules\create-react-app
System:
OS: Windows 10 10.0.19041
Binaries:
Node: 12.9.1 - C:\Program Files\nodejs\node.EXE
Yarn: Not Found
npm: 6.14.8 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 86.0.4240.111
Edge: Spartan (44.19041.423.0), Chromium (86.0.622.51)
Internet Explorer: 11.0.19041.1
npmPackages:
react: ^17.0.1 => 17.0.1
react-dom: ^17.0.1 => 17.0.1
react-scripts: 4.0.0 => 4.0.0
npmGlobalPackages:
create-react-app: Not Found
Steps to reproduce
(Write your steps here:)
- I have a file with a state with this value in my Redux reducer
const initialState = [
{
id: Date.now(),
task: "new todo ",
completed: false,
}
];
- Modify the object in the file to this
const initialState = [
{
id: 1,
task: "new todo ",
completed: false,
},
{
id:123,
task: "new todo ",
completed: false,
}
];
- As previous versions of React / CRA the page force a reload, displaying in the page the new object added, but it's not anymore
Expected behavior
Even if you change the text of one of the objects in the reducer it used to reload the page. I'm expecting to see the new state in the page as I save a file when the state change
Actual behavior
Here you can see I saved the file and the page is not showing the new state, and the new data.
Reproducible demo
https://github.com/StewartGF/todo-test
I created this clean project with CRA, it has react v17
You can change the version in the package.json to what I paste in the description and use npm install
in order to see the project working as it was working in previous versions.
Activity
FezVrasta commentedon Oct 25, 2020
CRA 4 uses Fast Refresh instead of Hot Reload, the page doesn't reload on file changes.
martinfrancois commentedon Oct 26, 2020
@FezVrasta Fast refresh is currently opt-in only and you must specify the environment variable
FAST_REFRESH
, I don't think @StewartGF set it, but it would be good to know whether he did to make sure it's not that.StewartGF commentedon Oct 26, 2020
I'm not using Fast refresh, this is a new project. But from what I read about Fast refresh the behaviour seems similar (I've never used it, so im not 100% sure).
Maybe now it's enabled by default and I have to disable it?
FezVrasta commentedon Oct 26, 2020
fast refresh is enabled by default.
RosenTomov commentedon Oct 26, 2020
So is hot reloading removed entirely?
I'm having trouble refreshing the app at all, adding or removing components does nothing, I have to manually refresh the page to get the updates.Only the styles update when changed.
I'm using is the config folder and start script from react-scripts, nothing else.
Edit:
Adding
in babel presets, solved the issue. Now the app reloads properly.
Sheparzo commentedon Oct 26, 2020
@RosenTomov hot reloading does not appear to be working from changes to the root index.js. At least that's what I'm seeing in my project and in the unaltered app created from create-react-app. But further down from index.js in a component, hot reloading does appear to be working.
martinfrancois commentedon Oct 26, 2020
@FezVrasta fast refresh is definitely NOT enabled by default, or I'm not able to read code anymore, have a look: https://github.com/facebook/create-react-app/pull/8582/files
For example, one comment explicitly mentions:
martinfrancois commentedon Oct 26, 2020
For me, hot reloading (without the
FAST_REFRESH
flag) also doesn't work, with theFAST_REFRESH
flag it works for me.FezVrasta commentedon Oct 27, 2020
The comment is outdated, fast refresh is enabled by default, in fact the checks is
FAST_REFRESH !== 'false'
because they assume any value different thanfalse
is going to betrue
lyqline commentedon Oct 28, 2020
npm run start -FAST_REFRESH=true
hot reload working
bstro commentedon Oct 28, 2020
Fast refresh also doesn't work for me. I have to manually refresh the page to see any updates.
"react-scripts": "4.0.0"
,"react-dom": "^17.0.1",
,"react": "^17.0.1",
miladebadi commentedon Nov 3, 2020
It is working in Safari but not working in Chrome and Brave.
116 remaining items
the-claw commentedon Feb 3, 2022
If you're using ASP.NET Core's "UseReactDevelopmentServer()" function, you will find that CRA5's webpack hot reloader cannot connect to the webpack-dev-server websocket because it determines the wrong port on start-up. You can fix this by setting WDS_SOCKET_PORT to the value of ASPNETCORE_HTTPS_PORT in the start script in package.json, e.g.:
This works on Windows, may require some tweaks to work on Linux.
The reason for this failure is that UseReactDevelopmentServer creates a proxy to the actual NodeJS instance that's hosting webpack-dev-server, and loads your app via this proxy. Webpack does not know about the proxy so it injects the wrong websocket port into the scripts for your app. Luckily ASP.NET Core puts its HTTPS port in a convenient environment variable that gets inherited by the child NodeJS process that runs "npm run start".
If you don't use HTTPS in development this won't work for you, but you could probably set your own environment variable to the current HTTP port in Startup.cs before calling UseReactDevelopmentServer.
niltonxp2 commentedon Feb 8, 2022
It worked for me but after uninstalling react-hot-reload :(
hoangle4 commentedon Feb 24, 2022
For anyone that have React sits on a remote dev server, I have a pull request here which you could modify the react-scripts package if you'd like to.
#12091
KayvT commentedon Feb 24, 2022
Using Windows 10, WSL 2, TypeScript, React 17.0.1.. nothing from the above worked for me.. anyone managed to make this work?
demedos commentedon Feb 24, 2022
@KayvT did you try the .env trick? I'm on a macOS but with cra and TS it did work
panpsonis commentedon Mar 3, 2022
To anyone working with Vagrant...
Just setup a new React app and this was the only way I managed to get webpack to capture changes and recompile.
"CHOKIDAR_USEPOLLING=true" did not work for me or any other suggestions.
I merged the changes submitted by @hoangle4 in #12091 and then created a .env file with the following option:
WDS_POLLING=true
My setup:
ubuntu/focal64 Vagrant box with VirtualBox under Windows 11
balamt commentedon Mar 17, 2022
Nothing mentioned above worked for me
I use WSL2 (Ubuntu) with Windows 10.
using Remote WSL extension to run VSCode.
I have created symlink to my project location to map it under $HOME path of WSL.
So that i can open the folder directly in VSCode as wsl path (Optional)
But I have a strange solution which is working, But not effective solution.
I have to make changes to my application code, then I need to simply comment some lines in package.json
and uncomment the change.
In browser we see error, when we comment.
when we uncomment the error goes, and when we refresh the page it reloads with the changes made in actual code.
Really strange solution!! 🙄
Dependency I use
When commented:

When Uncommented:

dquoctri commentedon Apr 21, 2022
balamt
how funny!
leonaburime commentedon Jun 14, 2022
How has this not been fixed? I wasted 3 days thinking this was an issue of another UI package that used this as a dependency?
sashiksu commentedon Oct 3, 2022
I face this issue with react app structured from scratch with webpack. So I have to mention below code snippest in the index.js file.
if (module.hot) { module.hot.accept(); }
Additional info about my setup,
webpack-dev-server
no additional arguments.hotOnly:true
in devServer block.icharge commentedon Oct 31, 2022
@sashiksu
module.hot.accept()
is work for me. But it seems like it reload all component on app. :(Hinaser commentedon Nov 29, 2022
I was troubled by this issue but after I disabled
why-did-you-render
, hot reload has begun to work again.My environment: React 18 & CRA5
If you have some npm dependencies which patches/modifies/replaces original React code, try to disable them and see the result.
bot281 commentedon May 1, 2023
still facing trouble even after adding .env with
FAST_REFRESH=false
in it.please update on a solution
zkchong commentedon Sep 8, 2024
I have the similar issue in node.js v18.
After some search, discovered it is because I am running node.js with docker in WSL. Hot reloading issues can arise due to how WSL handles file system events.
The issued is solved after I add the two environment variables:
The final docker script looks like below:
docker run -it \ -v "$(pwd)":/app \ -w /app \ --network=host \ -e WATCHPACK_POLLING=true \ -e CHOKIDAR_USEPOLLING=true \ node:18 /bin/bash