Function component renders incorrectly after Fast Refresh
See original GitHub issueI’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:
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
- Pull down this project: https://github.com/mxhold/rn-fast-refresh-bug
- Open app in iOS simulator with Fast Refresh turned on.
- Uncomment the commented line in App.tsx that sets
flexGrow
. - Save the file, triggering a refresh. Note the border is unchanged, as expected.
- Comment out the same line (returning the file to its original contents).
- Save the file again, triggering a refresh again. Note the border has collapsed as if
flex: 1
was not set (!). - 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:
- Created 4 years ago
- Reactions:1
- Comments:12 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@AndrewMorsillo This sounds quite bizarre! (I don’t think it has any relation to this issue btw so you should file a new one.)
@gaearon