Issue with hot reload
strangecamelcaselogin opened this issue · 4 comments
Version
2.13.0
Test Case
https://github.com/strangecamelcaselogin/react-contextmenu-with-hot-reload-issue
Steps to reproduce
Enable hot reload (react-hot-loader) in my case with react-app-rewired
and react-app-rewire-hot-loader
.
Expected Behavior
- Each
MenuItem
should have a hover effect - Selected item changes with arrow keys
Actual Behavior
- None of
MenuItem
have a hover effect - AbstractMenu.js throw error, nothing happened visually.
Stacktrace (open menu, press arrow down key):
AbstractMenu.js:157 Uncaught TypeError: Cannot read property 'children' of undefined
at childCollector (AbstractMenu.js:157)
at forEachSingleChild (react.development.js:1225)
at traverseAllChildrenImpl (react.development.js:1122)
at traverseAllChildren (react.development.js:1199)
at Object.forEachChildren [as forEach] (react.development.js:1247)
at childCollector (AbstractMenu.js:157)
at forEachSingleChild (react.development.js:1225)
at traverseAllChildrenImpl (react.development.js:1122)
at traverseAllChildrenImpl (react.development.js:1138)
at traverseAllChildren (react.development.js:1199)
at Object.forEachChildren [as forEach] (react.development.js:1247)
at ContextMenu.selectChildren (AbstractMenu.js:168)
at HTMLDocument.handleKeyNavigation (AbstractMenu.js:93)
As I understand this behavior caused by this line of code (link1, link2) - child.type (even if it is MenuItem
) not equal to imported MenuItem
.
Would you be able to submit a PR with a fix? I haven't used hot-reloading in a while.
As a workaround, you can make the component cold, so it will be ignored by hot-loader:
import { MenuItem } from "react-contextmenu";
import { cold } from "react-hot-loader";
cold(MenuItem);
Would you be able to submit a PR with a fix? I haven't used hot-reloading in a while.
I don't know. Problem is - AbstractMenu should be unaware of hot reload and be capable to check type of children's elements not by reference.
I will try to fix this over next weekend
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.