React-Refresh not working for bound function which returns JSX.
See original GitHub issueDescribe the bug
I have a view that is binding to a function which returns JSX:
<div>
{TestComponent()}
</div>
When the JSX that TestComponent returns changes, the view is not updated.
However; if the function is used in the below format, the changes to TestComponent are reflected to the view:
<div>
<TestComponent></TestComponent>
</div>
Steps to reproduce
(Write your steps here:)
- Clone the repo athttps://github.com/cincyelite22/React-Refresh-Test
- Navigate into the examples/create-react-app folder
- Run ‘yarn install’
- Run ‘yarn start’
- Change the value of “ReplaceMeToTest” in Dummy.js and observe that the view did not updated for the {Dummy( { val:'2. HMR Not Working ’ } )} usage.
- Uncomment one of the extra exports in Dummy.js
- Change the value of “ReplaceMeToTest” in Dummy.js again and observe that both usages are updated in the view.
Expected behavior
The view should update for both types of usages of “Dummy” regardless of whether the extra unused export is present.
Actual behavior
The view doesn’t update for both usages, but weirdly starts working if an extra unused export is added.
Reproducible demo
I have cloned https://github.com/pmmmwh/react-refresh-webpack-plugin and reproduced the issue in the create react app example. You can test these changes by pulling from the repo below: https://github.com/cincyelite22/React-Refresh-Test
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Hot Reload is not working in my React App - Stack Overflow
To solve the problem in hot reloading/fast_refresh I simply add CHOKIDAR_USEPOLLING=true in package.json:
Read more >React Performance with bound functions · Issue #5197 - GitHub
This always returns a new function even though incCount, this, ... Have you been running into performance problems due to bound functions?
Read more >How to use the react-refresh/runtime.isLikelyComponentType ...
function isReactRefreshBoundary(module) { var moduleExports = getModuleExports(module); if (Refresh.isLikelyComponentType(moduleExports)) { return true; } if ( ...
Read more >Refs and the DOM - React
Refs provide a way to access DOM nodes or React elements created in the render method. In the typical React dataflow, props are...
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
All of this sounds correct.
You shouldn’t be “calling” components directly because this breaks Hooks, too. So you should be using JSX or createElement for them. If you don’t intend that function to be treated as a component, don’t use Pascal Case for it.
This sounds entirely unrelated to the issue on this thread and is a result of you using a class.
I just did some quick tests and I cannot reproduce this issue.
(Simply add your LazyLoader into
examples/webpack-dev-server
and wrap theLazyComponent
with it)@Rohitbels Please open a new issue with your particular usage in it to discuss this further.