create-react-app: Hot Reload stopped working with React "^17.0.1"
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.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 97
- Comments: 116 (3 by maintainers)
Links to this issue
Commits related to this issue
- Updating boilerplate. Fixed hot reloading issue https://github.com/facebook/create-react-app/issues/9904 #966 — committed to DevUnltd/js-library-boilerplate by hodgef 3 years ago
- fix: react-script hot reloading https://github.com/facebook/create-react-app/issues/9904 — committed to policumbent/alice by gabelluardo 3 years ago
- Deactive fast refresh to workaround hot reload issue https://github.com/facebook/create-react-app/issues/9904#issuecomment-774497582 — committed to matedo1/pnc-web-ui-react by matedo1 3 years ago
- Deactive fast refresh to workaround hot reload issue https://github.com/facebook/create-react-app/issues/9904#issuecomment-774497582 — committed to project-ncl/pnc-web-ui-react by matedo1 3 years ago
- update to node 16 npm 7, fix react-scripts HMR see https://github.com/facebook/create-react-app/issues/9904 — committed to intergestalt/2038-app by retani 3 years ago
- Update react-scripts to enable fast refresh by default * https://github.com/facebook/create-react-app/issues/9904 — committed to okdonga/polygon-smart-contract-dapp by deleted user 2 years ago
- Update react-scripts to enable fast refresh by default * https://github.com/facebook/create-react-app/issues/9904 — committed to okdonga/polygon-smart-contract-dapp by okdonga 2 years ago
Worked! With React 17.0.1 and react-scripts 4.0.0 and with
FAST_REFRESH=true
(default) changes to components are reflected seemlessly, but changes to other dependencies are not reflected in the UI at all without manual refresh, despite obvious recompilation in the console. Setting the flag tofalse
in.env
didn’t change anything but when I updated toreact-scripts 4.0.1
settingFAST_REFRESH=false
in.env
brought back the hot reload.fast refresh is enabled by default.
I am not sure everyone is having the same problem.
For me, when i have nothing on .env or FAST_REFRESH=true, i will get the fast refreshes for components change, but other files changes will not reload the page, despite my console showing that it recompiled.
When i have FAST_FRESH=false, everything is hot-reloading and everything works.
npm run start -FAST_REFRESH=true
hot reload working
@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.
You just create your own
.env
file in the root of your project (where thepackage.json
is) and putFAST_REFRESH=false
in itThank you! Creating a .env file and adding
FAST_REFRESH=false
to my project root fixed my issue of hot-reloading not working on Windows 10Modify your react-scripts line (package.json) like so:
Advantage: .env is not checked into version control but package.json is.
CRA 4 uses Fast Refresh instead of Hot Reload, the page doesn’t reload on file changes.
Hi folks. I’ve solved this issue in my above comment, explained it in detail, and created a PR to fix it. That PR will go stale in 5 days. Not really sure what else to do from here if the maintainers aren’t interested in solving the problem. If the maintainers would be more interested in a PR from someone with a more masculine name I’d be happy to temporarily alter my profile to facilitate their comfort.
Why is this closed ?
Still not working with CRA5 ? w/ Ubuntu 20.04.3 LTS Tried everything above.
A summary of this very long and confusing thread for anyone coming in:
Fast refresh can update some components without reloading the whole page, unlike hot reload, which reloads the whole app every time you make any change. (With the exception of CSS, I think.) The downside of Fast Refresh is that, for some changes (I’m going to hazard a guess - changes that would actually require a reload to implement?), it won’t implement them, and won’t tell you it hasn’t, either. So you have to manually refresh or, I’ve found, manually restart the development server to see all changes. This can outweigh the convenience of Fast Refresh in many cases.
So, if you’d like to revert to Hot Reload behavior, create a
.env
file in the root folder of your project, and addFAST_REFRESH=false
to it. (You may also add this in your shell instead, if you’d like to adjust the behavior on a case-by-case basis). Make sure to close any running development server, and restart. If that doesn’t work, check to make sure you have the latest version of CRA, not
4.0.0
but4.0.1
; searchreact-scripts
in your project’spackage.json
file to see. If you need to upgrade,npm i --save react-scripts.
.I’m using WSL, you can create a
.env
file and just putCHOKIDAR_USEPOLLING=true
Or in your package.json
npm run start -FAST_REFRESH=true does NOT work for me on Chrome/MacOS Catalina.
As @Sheparzo mentioned though, the problem seems to be happening only with changes to the root index.js file. With .css & other .js files, hot reload is working fine for me.
Im getting the same problem. Just wanted to let the devs know that they can add one more person to list. Im using the following: “react”: “^17.0.2”, “react-dom”: “^17.0.2”, “react-scripts”: “4.0.3”,
I’m facing the same issue
"react-scripts": "4.0.0"
,"react-dom": "^17.0.1"
,"react": "^17.0.1"
,EDIT: I tried with chrome, firefox and chromium on Pop’Os 20.04 , with and without FAST_REFRESH=true, nothing make it works.
I had the same issue with WSL2. .env with the content of CHOKIDAR_USEPOLLING=true helped.
THANK you. You mentioning wsl made me try and it works. I had this problem for 2 days now.
"start": "CHOKIDAR_USEPOLLING=true react-scripts start",
When will be the next release?)))
Update: solved (for me, anyway)
Cause: Windows Update changed the WSL2 filesystem behavior. File changes can’t be detected when they are stored in the Windows file system. I was running my projects in
~/windows_dir_link/projects/
. (Equivalent to/mnt/c/Users/Dan/Documents/
.)Solution: I moved my projects to a directory that isn’t linked to a Windows folder. Using
~/projects/
avoids the filesystem translation layer and allows all changes to be detected. React is now working with the new FAST_REFRESH feature. As an added bonus, file access is an order of magnitude faster as well.Original post follows These fixes haven’t worked for me. Windows 10 version 20H2 (build 19042.746). WSL2 Ubuntu.
Linux Bigbox 4.19.128-microsoft-standard #1 SMP Tue Jun 23 12:58:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
I’ve tried setting FAST_REFRESH to both true and false in:
.env
file"start": "react-scripts start -FAST_REFRESH=false"
)npm run start -FAST_REFRESH=false
(also with yarn)The biggest clue is that the terminal output never shows a recompile whether I edit App.js or a component file. The browser console has a single line
[HMR] Waiting for update signal from WDS...
. Webpack reports that it disconnects when I kill the server.Edited to include the dependency versions:
It is working in Safari but not working in Chrome and Brave.
Works for me on windows 10, react: 17.0.1 - react-dom: 17.0.1 - react-scripts: 4.0.1 and chrome for my browser.
Using Windows 10, WSL 2, TypeScript, React 17.0.1… nothing from the above worked for me… anyone managed to make this work?
This still doesn’t work for me.
package.json
I don’t understand why is this issue closed. All the solutions on this thread are hacky and don’t actually work.
FAST_FRESH=false
in an.env
file works for javascript files but not for.css
files. When I change.css
files there’s an iframe covering the html and preventing any interaction with the page.It looks like the issue is in
react-hot-loader
. It relies on React internal API which is no longer available in React 17:instance._reactInternalFiber
.See here - when
react-hot-loader
detects changes and tries to figure out what to re-render (getReactStack
=>getInternalInstance
), it tries to readinstance._reactInternalFiber
, but it’s not available in React 17 anymore because of this PR. I’ve changedreact-hot-loader
locally and this resolves the issue. Soreact-hot-loader
has to be fixedJust duplicated an older project and updated the packages to c-r-a 4.0.1, react 17.0.1, typescript 4.1.2. Running in Firefox on Windows 8.1.
Browser was not updating when code was changed.
Added
FAST_REFRESH=true
to.env
, restarted the node process - browser now updates automatically when code is changed.FAST_REFRESH=false
is working on BigSure 11.2.2, React ^17.0.1@brense please ensure you do kill the “npm start” process between each .env change.
FAST_REFRESH=false should work
For me, hot reloading (without the
FAST_REFRESH
flag) also doesn’t work, with theFAST_REFRESH
flag it works for me.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. https://github.com/facebook/create-react-app/pull/12091
almost 1.5 years awaiting for issue fix to upgrade from stable cra3 =) seems like this issue should be reopened
This still doesn’t work… I’m using Docker Desktop for Windows, with WSL 2. I have to rebuild the docker container to get it to update… Refreshing the page doesn’t even do it…
The point is not that we’re lacking solutions, but that it should work out of the box.
For my system at least, this was down to a minor error of boolean logic in the CRA config.
This is what config/env.js looks like by default for v4 of CRA in Typescript:
This can never result in
FAST_REFRESH
being set tofalse
, for two reasons.Boolean logic
If
FAST_REFRESH
is undefined, as it will be for most people here, then config/env.js will set it to true, even though the intention here is to set it to false by default. It’s just a mistake of boolean logic.Strings are truthy
If that error were not present, we would still not have
FAST_REFRESH
disabled by default. The default value is not being set to the boolean value offalse
, it is being set to the string'false'
. So if evaluated as a boolean, it will be interpreted as truthy, and give a true value.This is why setting
FAST_REFRESH=false
in the dotfiles worked for so many people, wheras the disabled-by-default config didn’t. They were setting entirely different values. I don’t know why it didn’t work for everyone, possibly a difference of dependency versions or OS.Fix
The solution is to convert the environment variable to a boolean before trying to evaluate it as one, and then using a boolean for false instead of a string, and using an OR operator:
Just to add another voice to the ever growing list of people using Ubuntu 20.04. Fast refresh doesn’t work at all in a brand new CRA app installed two days ago. Adding
FAST_REFRESH=false
works but that seems to cause the whole page to reload (can’t tell, it’s rather quick).Greetings, a solution to the problem is given on the stackoverflow https://stackoverflow.com/questions/42189575/create-react-app-reload-not-working. Tested to Ubuntu 18.04.5 LTS, work
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.
Had a same problem after upgrading to CRA 5.0. Project uses .NET Core as backend and UseProxyToSpaDevelopmentServer as a poxy. Project have a homepage setting in package.json:
"homepage": "arm/"
and .env file withWDS_SOCKET_PATH=arm/sockjs-node
After upgrading to CRA 5.0 WebSocket used for hot reloading could not be established, and after comparing with fresh new React project created with CRA 5.0 it figured out that a URL changed from
/sockjs-node
to/ws
. Fixing .env withWDS_SOCKET_PATH=ws
fixed the issue with hot reloading.Same with me. Just migrated to Vite.js. Recommend the same.
As suggested in https://stackoverflow.com/a/68257526/621659:
FAST_REFRESH=false
?!Worked for me on Ubuntu 20.04.2 LTS and React 17.
Here’s how I fixed fast refresh for my VM, running in VirtualBox.
In your
.env
, add:I have not tried creating the .env folder with “FAST_REFRESH = false”, but leaving everything by default, with an “npx create-react-app my-app” and entering the project from VSC, starting the server with an “npm start”, removing all the files from “src” and creating new files, when I save the changes it does not refresh in Chrome. You can see from the inspector how it does try to refresh and change the colors of the elements of the inspector, on the other hand, if you do not press F5 or Ctrl + F5 it does not refresh the content in the browser. Tested as of yesterday.
This works on Chrome/Windows 10. Thanks @lyqline 👍🏽
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
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.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.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
@RenanZX At first it worked, but after some time stop working. I solve this problem with
FAST_REFRESH=false
in.env
temporary and looking for best solution.Still an issue to me. I am creating a blank cra application using the typescript template
but after removing all the boilerplate in App.tsx it doesn’t work anymore. I can see the terminal window re-compiling on save, but the browser just doesn’t refresh anymore.
The only way I can get around this is by creating the .env file with
FAST_REFRESH=false
in it, but it’s a sub-optimal solution.That is the correct answer!! Just put the logic code elsewhere, index.js is only responsible for quoting. Use
FAST_REFRESH=false
, hot reload will become fast refresh.I think hot reload is betterI can confirm hot-reloading still doesn’t work on Ubuntu 20 LTS, on VirtualBox.
Still forced to keep fast refresh disabled, in order to do any kind of development.
Can someone from the React team confirm if @phazel’s patch passes tests and solves the issue?
Creating the .env file with
FAST_REFRESH=false
is no use since the whole page is reloaded even clearing the current state. UsingFAST_REFRESH=true
in the .env is not working either. Only style changes are reloaded, not even texts reload. This “incompatibility issue” seems like a huge step backwards compared to the old approach using hot reload…It seems that the issue is in Chrome, closing and opening the browser fixes the issue.
For anyone else running into this issue who still hasn’t been able to solve it with everything above, if while updating to/installing React 17 you also updated to/installed Webpack 5 and are using webpack-dev-server, see the footnote of this troubleshooting guide for what finally solved the issue for me.
(Tldr; add
target: 'web'
to your development webpack config).https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/docs/TROUBLESHOOTING.md
It worked for me, even when I make changes on the index.js files, thank you
While I’m sure this is probably true for WSL 2 users shown here , an alternative I have found while still having my project in the
/mnt
(so windows file system instead of WSL2 system), follow this SO linkYou should never delete your package-lock unless there’s a merge conflict in it. If you change your react-scripts version to ^4.0.1, it will work as well and you will be on the latest version 😃 Executing
npm i --save react-scripts
should fix this for you. Stop and restart your app. If it still doesnt work, delete your node_modules and runnpm i
again.Thanks anybody who advised the .env file with FAST_REFRESH=false My tip: dont forget to create the .env file outside for your src folder
windows 10, react: 17.0.1 - react-dom: 17.0.1 - react-scripts: 4.0.1 chrome/firefox
This thread is totally confused. My conclusion,
I also experienced this issue but after creating a new project with
parcel
instead ofwebpack
everything works perfectly. Hope this helps.FYI you can use: CreateApp Frontend build config generator to quickly get things setup.
creating your own .env file and putting FAST_REFRESH=false in it works! I am on windows 10, “react”: “^17.0.1” and “react-scripts”: “4.0.1” and chrome for my browser. Thanks, @NicolasCharpentier, @brense, and everyone else.
Adding
FAST_REFRESH=false
to.env
or.env.development
works for me on OS X usingreact-scripts 4.0.1
, thank you @brense!console.dir(process.env);
placed at the root of the app will confirm right away whetherFAST_REFRESH
and other settings are set.PS: env setting is read from
.env
file located in the root of the project. To be sure the new settings are implemented, the app needs to be restarted. The app is not expected to re-read the .env file upon changes a la “fast-refresh”.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?