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.

Function component renders incorrectly after Fast Refresh

See original GitHub issue

I’ve encountered at least one scenario where a function component rendered after a Fast Refresh looks wrong and requires a hard refresh to fix. Changing it to a class component fixes this.

GIF: expo-fast-refresh-bug

React Native version:

System:
    OS: macOS 10.15.2
    CPU: (8) x64 Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
    Memory: 17.85 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 13.7.0 - /var/folders/7q/w_rts5kx5gzfk051cpw8vlzh0000gn/T/yarn--1579912407030-0.8849373494224462/node
    Yarn: 1.21.1 - /var/folders/7q/w_rts5kx5gzfk051cpw8vlzh0000gn/T/yarn--1579912407030-0.8849373494224462/yarn
    npm: 6.13.6 - ~/.nvm/versions/node/v13.7.0/bin/npm
  SDKs:
    iOS SDK:
      Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.6010548
    Xcode: 11.3.1/11C505 - /usr/bin/xcodebuild
  npmPackages:
    react: ~16.9.0 => 16.9.0
    react-native: https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz => 0.61.4

Steps To Reproduce

  1. Pull down this project: https://github.com/mxhold/rn-fast-refresh-bug
  2. Open app in iOS simulator with Fast Refresh turned on.
  3. Uncomment the commented line in App.tsx that sets flexGrow.
  4. Save the file, triggering a refresh. Note the border is unchanged, as expected.
  5. Comment out the same line (returning the file to its original contents).
  6. Save the file again, triggering a refresh again. Note the border has collapsed as if flex: 1 was not set (!).
  7. Press Cmd-R to refresh. Note the border goes back to the original position.

Describe what you expected to happen:

It is surprising that after step 6 the screen renders incorrectly and requires a hard refresh to render correctly.

I would have expected that after step 6, the border would have stayed in the same position but instead the view is rendered as if flex: 1 was not set at all.

Notes

  • This example doesn’t work if you change App to a class component. It has to be a function component.
  • This doesn’t seem to be reproducible in a Snack.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
gaearoncommented, Aug 18, 2020

@AndrewMorsillo This sounds quite bizarre! (I don’t think it has any relation to this issue btw so you should file a new one.)

1reaction
mxholdcommented, Feb 6, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

How and when to force a React component to re-render
React automatically re-renders components, but what happens when a component is not updating as expected? Find out what you can do here.
Read more >
React Functional Component Render twice after navigate to ...
When I refresh this page, console.log('Test===>>>') show only once. What is a mistake and how to fix the double render problem?
Read more >
Fix the slow render before you fix the re-render - Kent C. Dodds
Every time you click on the button, the Foo function is called, but the DOM that it represents is not re-rendered. Because of...
Read more >
When does React re-render components? - Felix Gerschau
As we already saw before, React re-renders a component when you call the setState function to change the state (or the provided function...
Read more >
React Components rendered twice — any way to fix this?
Many developer have implemented a similar functional component and have seen this behavior. Some have even opened a bug report in the official...
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