If you are reporting a bug or having an issue setting up React Hot Loader, please fill in below. For feature requests, feel free to remove this template entirely.
What you are reporting:
All react nodes are created by a proxy function in react-hot-loader now, and this affects all codes like node.type === Component. This assertion will always be false.
And this is very common in many codebases, like react bootstrap here.
What you think should happen:
See function location, it is from correct file location, and node.type === Component is true.

What actually happens:
react node's type has dynamic function location, which I believe is a dynamic generated, see screenshot:

[[FunctionLocation]]: VMxxx is a dynamically generated file in chrome, and node.type === Component is false now.
React Hot Loader version:
Run these commands in the project folder and fill in their results:
node -v: v6.9.5npm -v: 5.8.0Then, specify:
Please take the time to create a new project that reproduces the issue.
You can copy your project that experiences the problem and start removing things until you鈥檙e left with the minimal reproducible demo. This helps contributors, and you might get to the root of your problem during that process.
Push to GitHub and paste the link here.
hmr-function-location-bugnpm installnpm run start and open localhost:3000 in browserCorrect!npm run startWrong! in browserWe know this problem, but could not do anything to solve it. At least today.
The only proper way to write your code is to compare the _same things_:
node.type === <Component />.type
Thank you for taking the time @theKashey! I tested your workaround when running into the same problem and it works. It forces <Component /> to either be instantiated with all required props or not have any required props however (assuming PropTypes are used), otherwise a propType warning will be thrown. Instantiating components for equality checks also raises performance concerns.
Could it be enough to compare string representations of the functions in the particular case of React components? I am not sure whether this approach has drawbacks, it worked in a quick test.
node.type.toString() === Component.toString()
Either way, thank you for providing a working solution to the problem!
Nope. But we do have a special helper for it - areComponentsEqual, check out https://github.com/gaearon/react-hot-loader#checking-element-types.
PS: @gaearon, I know that we have to have this conversation a long time ago, but is it possible to move RHL a bit more "deeply" inside React? Make React more "hackable"?
Basically, only 1 things is required:
type from type before element creation.This will solve all endless "element comparison problems", and actually remove the last side-effect we have.
Most helpful comment
Nope. But we do have a special helper for it -
areComponentsEqual, check out https://github.com/gaearon/react-hot-loader#checking-element-types.PS: @gaearon, I know that we have to have this conversation a long time ago, but is it possible to move RHL a bit more "deeply" inside React? Make React more "hackable"?
Basically, only 1 things is required:
typefromtypebefore element creation.The same logic as we put into createElement, but in the proper place - below user space.
This will solve all endless "element comparison problems", and actually remove the last side-effect we have.