-
Notifications
You must be signed in to change notification settings - Fork 48.5k
ReactMount: Two valid but unequal nodes with the same %s
: %s
#1400
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
Comments
Do you have a repro? I don't think invalid nesting should cause this error. |
@spicyj Had a debugging session with |
I don't believe browsers will do that for |
Here's a demo showing that data-reactid shouldn't end up duplicated in that case: http://jsbin.com/racecimo/1/edit Let me know if you see otherwise. |
Reproduced it with: http://jsfiddle.net/kb3gN/1874/ (i.e, yes you shouldn't do that, but it may still make sense to warn that it could be the cause) |
Curious, thank you. |
Same issue: |
Another possible cause of this error (just writing here for posterity): React receiving events on elements that have been removed from the DOM. This shouldn't happen unless there is a bug in React; it happens in 0.9 and 0.10 due to a React bug. The issue has been fixed in master (in c62c2c5 and 3e34739) and will be in the next release. |
See also #101. |
I just ran into this issue, it was indeed caused by invalid nesting, e.g. <a>
<div>
<a></a>
</div>
</a> |
Some love for #1987 perhaps :) |
Hi I have the same error message. I have mounted 2 React component on 2 different #div element with different ids. I was trying to have 2 different components doing different things. |
I believe I hit the same issue. I have two components in two different divs, they don't share common root. I create some components dynamically and end up with same ids. The set up is similar to this, but I cannot reproduce this outside my code. |
@macqm Are you pre-rendering and perhaps rendering the same static markup to two different places? |
@syranide: I wasn't prerendering. I now tried to create the same component in same place where I create the element and I had same React class in a different module, loaded by require(...) with Browserify. The class I created locally works just fine. When I load exact same module via Browserify, it does not work. Here's an illustration: // Require apps
var Loaded = require('../components/widget/widget');
var Widget = React.createClass({
//...
}); And now this works: // Create react component from class
var component = React.createElement(Widget);
React.render(Widget, _windows[title].$content.get(0)); But loading same React class via Browserify causes an issue: // Create react component from class
var component = React.createElement(Loaded);
React.render(component, _windows[title].$content.get(0)); I now get different error (I missed the moment it changed, but code looks almost identical): |
@macqm Find the reactID mentioned, it's most likely due to invalid nesting |
@syranide Ooops. I had a div nested in another div. I believe that caused the issue. So I am back to original react-id error. It looks like I was wrong about the browserify. It doesn't seem to matter now. This is the code I am using to create a widget class: var Widget = React.createClass({
getInitialState: function() {
return {
text: ""
}
},
render: function() {
return (
<div className="widget">
<h1>Widget</h1>
<input className="widget-input" value={this.state.text} onChange={this.handleChange} />
<p>{this.state.text}</p>
</div>
);
},
handleChange: function(e) {
this.setState({text: e.target.value });
}
}); And then I try to initialize the widget in a floating window (created using Ventus library): // Create react component from class
var component = React.createElement(Widget);
React.render(component, _windows[title].$content.get(0)); where
Indeed, the newly created element gets assigned react-id of 0.0. |
@macqm Do you have any repro I could look at? I'm assuming it's the external library that is mucking with the DOM. PS. Nesting divs is fine, p is not, same with div inside p, etc. |
@syranide: I was trying to reproduce the problem and than I noticed that I was loading |
@macqm That's a common issue on non-linux environments, case-insensitive filesystems and a bundler which doesn't warn. :) |
I encountered the same message with the same root problem - I included two independently webpack'ed bundles, and each one had a copy of react. The two bundles seemed to work (by some miracle), but I did get the error message about unequal nodes. Consolidating down to a single copy of React resolved the problem (thank you @macqm for the tip off). I wonder if there is any way to catch this scenario within React, and include a warning that multiple versions of React may be present - this would go nicely along with the other very useful and helpful error descriptors! |
Hit this one by rendering a component inside an anchor tag:
Seems like there should be a way to detect these. |
This problem repros in react-0.13.3.js see: http://jsfiddle.net/wnv190n8/5/ |
@petilon Seems to work if you move the event handler inside the component, see example |
@macqm moving the event handler to the .JSX file is not an option for me. The event handlers, controllers, models etc need to be in .TS (TypeScript) files, only the view can be in .JSX. This seems like a serious bug that Facebook hasn't completely fixed... for more than a year. |
@petilon: Aside from the fact that it still is an issue to fix and it seems like your code should work, from what you say, your view is in a JSX file. I would argue that handling a click event is definitely something that belongs to the view - you are reacting to a UI element action. Perhaps a good solution for you is to add another event to your component, something like |
@macqm Thank you for the suggestion. Some people would argue that handling events (and changing the view in response) is the controller's responsibility. This isn't just a philosophical issue. From a practical point of view it makes sense to move as much code as possible to .TS files because TypeScript can perform error checking. (Note that Flow isn't available on Windows.) Nevertheless, your idea is useful as a temporary workaround, so thank you for that. |
This error message can be caused by a number of things, which are mentioned in these comments. Many are due to invalid nesting which we now have a warning for in master. @petilon The specific issue you mention is the same as #3790, where we're tracking it. I'm going to close this issue; if anyone encounters this error with a new cause, please open more specific issues. |
I got the same issue as @eugene1g . I'm creating a widget system with React, and my solution was to check if window.React existed. Then use React.render and React.unmountComponentAtNode from window.React if it exists: const React = window.React || require('react'); |
I'm getting this error when using react-bootstrap ui components. I'll be as descriptive as I can as I'm not allowed to show much code: I added two ReactBootstrap.Buttons with a text that should dynamically change. So I have something that looks like this:
On the Modal, I have two select boxes. Each select box is supposed to be representing the button it will change. So the first select, when you change it, should update the first button's text, if you change the second select, it should update the second button's text. Notice, the modal is a child and the render function shown above is the wrapper that contains the modal and the table element. To make sure the state changes, the modal element makes a callback to the parent's function which does a setstate on Value1, Value2 (based on the select drop downs on the modal popup). What happens: if you click the first button, the popup that shows both dropdowns will be displayed, if you change the 1st dropdown, only the 1st button's text will change. If you change the 2nd dropdown, the 2nd button DOESNT change.. and when you click on it.. it gives: react-0.13.3.js:18472 Uncaught Error: Invariant Violation: ReactMount: Two valid but unequal nodes with the same If you refesh the page, and repeat the steps, the second button opens the modal, the second drop down will work.. but the first drop down doesnt.. and if you close the modal and try to open it again from the 1st button.. the same error occurs: Uncaught Error: Invariant Violation: ReactMount: Two valid but unequal nodes with the same I believe this ONLY happens when you involve states and dynamic ui interactivity. When something gets mounted with the state of the value you pass in, and you make a dynamic change to it, the mounted value will remain, as react doesn't believe this is the element that needs to be changed, and when you re-render it makes another copy on top of it (with the same id), but with a different value. So the garbage collection needs to be handled properly when you rerender. In my case this is a typical child-to-parent communication. |
Able to fix.. I changed
and just made it as a regular html:
So yes, it has something to do with children nodes and the depth 7C63 of a component. In my case, a react component that had children. |
https://github.com/facebook/react/blob/master/src/browser/ui/ReactMount.js#L81
It seems this is mainly the cause of invalid nesting of tags,
<a><div /></a>
,<table><tr></tr></table>
, etc. I know there are some issues/PRs regarding this already but AFAIK they're trying to solve/detect it, it seems reasonable to just improve this (very non-informative) error message in the meantime.PS. I've probably seen 2-3 people get bitten by it myself now that I think about it.
The text was updated successfully, but these errors were encountered: