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.

React-Refresh not working for bound function which returns JSX.

See original GitHub issue

Describe 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:)

  1. Clone the repo athttps://github.com/cincyelite22/React-Refresh-Test
  2. Navigate into the examples/create-react-app folder
  3. Run ‘yarn install’
  4. Run ‘yarn start’
  5. 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.
  6. Uncomment one of the extra exports in Dummy.js
  7. 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.

React-RefreshBug

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:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
gaearoncommented, Jul 7, 2020

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.

When I lazy load my Components using above HOC full page reload takes places.

This sounds entirely unrelated to the issue on this thread and is a result of you using a class.

1reaction
pmmmwhcommented, Jul 7, 2020

When I lazy load my Components using above HOC full page reload takes places.

I just did some quick tests and I cannot reproduce this issue.

(Simply add your LazyLoader into examples/webpack-dev-server and wrap the LazyComponent with it)

@Rohitbels Please open a new issue with your particular usage in it to discuss this further.

Read more comments on GitHub >

github_iconTop 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 >
react-refresh | Yarn - Package Manager
Fast, reliable, and secure dependency management.
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