Skip to content
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

False-positive mutation warning #7424

Closed
just-boris opened this issue Aug 4, 2016 · 17 comments · Fixed by #7455
Closed

False-positive mutation warning #7424

just-boris opened this issue Aug 4, 2016 · 17 comments · Fixed by #7455

Comments

@just-boris
Copy link
Contributor

just-boris commented Aug 4, 2016

Given the following test case

function TestCmp() {
  return <span>{NaN}</span>;
}

ReactDOM.render(<TestCmp />, document.getElementById('app'));

Produces the following warning:

Warning: Component's children should not be mutated.
    in span (created by TestCmp)
    in TestCmp (created by Unknown)

This is probably caused by this mutation check, which was introduced in 15.3.0, but it doesn't work for NaN, because NaN != NaN

@zpao
Copy link
Member

zpao commented Aug 4, 2016

Yea, we should probably use Object.is (or an inlined polyfill for it).

@gbartlett9089
Copy link

gbartlett9089 commented Aug 5, 2016

Also having issues with this as well. I'm using Draft JS. Specifically with ordered and unordered list items. When I add either list block styles to a line, I receive a similar error:

 Component's children should not be mutated.
    in ul
    in div (created by DraftEditorContents)

It's being caused on line 32:

element._shadowChildren.length === element.props.children.length

It seems as if the shadowChildren array is empty but the element.props.children length is 1.

I followed the example here: https://github.com/facebook/draft-js/blob/master/examples/rich/rich.html although it is slightly modified using React.createClass({}) and is modularized into several separate files.

However, even when I copy and paste the example in, I'm still getting an error. Any ideas on why this may be occurring?

@vjeux
Copy link
Contributor

vjeux commented Aug 5, 2016

cc @keyanzhang as you were looking at shadow children

@vinayakpatil
Copy link

+1

@raghavio
Copy link

raghavio commented Aug 5, 2016

having this issue as well

@hackerwins
Copy link

+1

2 similar comments
@Pines-Cheng
Copy link

+1

@AndrejGajdos
Copy link

+1

@just-boris
Copy link
Contributor Author

Could you please stop +1-ing?

The issue is confirmed, the fix is here: #7455

@aweary
Copy link
Contributor

aweary commented Aug 16, 2016

(You can instead just add a reaction directly to the original post, which makes it easier for us to sort by popularity)

@michaelsoriano
Copy link

+1
react 15.3.1

I'm simply doing a sort before passing to .map:

` render : function(){
var children = this.props.children;
children.sort(function(a,b){
return a.Title.toLowerCase().localeCompare(b.Title.toLowerCase());
})
...

`

@jimfb
Copy link
Contributor

jimfb commented Aug 26, 2016

@michaelsoriano

The sort() method sorts the elements of an array in place

This is a mutation, and is NOT a false positive. If you need a new array that you are going to mutate, you should create a copy of the old one. Do not mutate React's data.

@Pines-Cheng
Copy link

Pines-Cheng commented Sep 18, 2016

I meet this problem too,It is the same reason. Thank for you sharing。

@suchipi
Copy link

suchipi commented Oct 26, 2016

This issue has been closed, but the original test case still produces the warning for me (using jsfiddle via https://jsfiddle.net/reactjs/69z2wepo/)

@gaearon
Copy link
Collaborator

gaearon commented Oct 27, 2016

The issue gets closed when the bug is fixed in master.

By looking at the issue history, you will see that it got closed by #7455. If you open that PR and look at it milestone, it says "15.4.0".

This means that when 15.4.0 is out as a stable version, the issue will be fixed. In the meantime you can already use 15.4.0-rc.4.

@suchipi
Copy link

suchipi commented Oct 27, 2016

Ah, I missed the "in #7455"; sorry. Thanks for the clarification.

@gaearon
Copy link
Collaborator

gaearon commented Oct 27, 2016

No worries! Hopefully we'll get it out within a week or two but RC should be perfectly usable.

islemaster added a commit to code-dot-org/code-dot-org that referenced this issue Dec 9, 2016
Discovered that this warning, `Component's children should not be mutated` is a [known false positive](facebook/react#7424) in React 15.3.0 when passing `NaN` into a DOM component.  It's fixed in 15.4 but I'm not happy about getting `NaN` here anyway.

Turns out we were computing an invalid transform matrix for the visualization when it's not visible.  All we have to do is early-out on that recomputation when we know we've got bad dimensions (meaning the svg isn't visible, or something is terribly wrong).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet