Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Merge requests
  • !10970

Fix Issue 9904: Fast Refresh env var always set to true

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/phazel/master into main May 16, 2021
  • Overview 5
  • Commits 2
  • Pipelines 0
  • Changes 1

Created by: phazel

Hot reloading was not working with React "^17.0.1", in my case I had v17.0.2. See Issue #9904 (closed).

Copied from my comment on that issue:

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:

// Whether or not react-refresh is enabled.
// react-refresh is not 100% stable at this time,
// which is why it's disabled by default.
// It is defined here so it is available in the webpackHotDevClient.
FAST_REFRESH: process.env.FAST_REFRESH !== 'false',

This can never result in FAST_REFRESH being set to false, for two reasons.

Boolean logic

Screen Shot 2021-05-16 at 3 19 17 pm

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 of false, 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. Screen Shot 2021-05-16 at 3 22 39 pm

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:

FAST_REFRESH: (!!process.env.FAST_REFRESH) || false
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/phazel/master