-
Notifications
You must be signed in to change notification settings - Fork 47.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Invariant Violation: ReactMount: Two valid but unequal nodes with the same data-reactid
"
#4120
Comments
Use
|
It looks like the error is happening when I'm using This works<div>
<PluginsList></PluginsList>
</div> This doesn't work
var DropdownItem = React.createClass({
onClick: function(e) {
e.preventDefault();
e.stopPropagation();
if (this.props.onClick) this.props.onClick();
},
isMenu: function(child) {
return child.type && child.type.displayName == 'DropdownMenu';
},
render: function() {
if (this.props.divider) return <li className="divider"></li>;
var inner = [], outer = [];
inner = React.Children.map(this.props.children, function(child) {
if (!this.isMenu(child)) return child;
return null;
}, this);
outer = React.Children.map(this.props.children, function(child) {
if (this.isMenu(child)) return child;
return null;
}, this);
return <li>
<a href="#" onClick={this.onClick}>{inner}</a>
{outer}
</li>
}
}); |
Looking at the HTML view, the data-reactid in question is used on 2 <a id="1">
<a id="2">foo</a>
</a> Will always get moved in the DOM to be <a id="1"></a>
<a id="2">foo</a> That's the likely culprit for your case. Chances are you have nested anchors across components. Though your problem might actually be manifesting slightly differently (could be the DOM structure playing different tricks) but you definitely have nested anchors. |
Thanks @zpao 🍻 It was a stupid mistake on my side: The filtering done in |
React will warn for invalid nesting like this in the next release. |
@spicyj I saw a comment about this on another issue, but when I tested using the latest master I didn't get any warning about invalid nesting. |
What if i need this kind of nesting?
How could I avoid this error? |
@mdcsfk That kind of nesting will not trigger this error. |
@jimfb Yes it will; you can't have two nested anchor tags in HTML. @mdcsfk You will need to restructure your markup. You can't have that kind of nesting in HTML, whether or not you're using React. Usually you'll want to change one of the links to not be an actual link and you can add a click handler to it. |
Oh, right, because the dom will rewrite the anchors. You're right. |
I'm trying to display a dropdown menu composed of
ul
,li
anda
(similar to the one from bootstrap).A
PluginList
element is used to generate a dropdown menu from a store.But the browser is not correctly parsing/outputting the HTML. Everytime I click on an item, I got the error:
Uncaught Error: Invariant Violation: ReactMount: Two valid but unequal nodes with the same
data-reactid: .0.0.0.0.7.1.$=15:0.0
.This bug is probably related to #1400, but I can't find any solution 😓
I'using react 0.13.3 and I also tested with the latest master.
HTML DOM View:
View of the same tree in the React plugin for Chrome:
Screenshot of the result
The blue element has nothing to do here
The text was updated successfully, but these errors were encountered: