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

scryRenderedDOMComponents* does not return in DOM order #2978

Closed
brandonhorst opened this issue Jan 29, 2015 · 2 comments · Fixed by #3276
Closed

scryRenderedDOMComponents* does not return in DOM order #2978

brandonhorst opened this issue Jan 29, 2015 · 2 comments · Fixed by #3276

Comments

@brandonhorst
Copy link

In the code below, I am testing a component that is a simple list. I initialize with props that result in one node. Then, I setProps to add another node before it. Then, I get both of them using scryRenderedDOMComponentsWithClass. In the DOM, test1 comes before test2, but in the scry results, that is not true. It appears to be returning the node which was inserted first.

var CommentList = React.createClass({
  render: function() {
    var commentNodes = this.props.data.map(function (text) {
      return (
        <div className="comment" key={text}>{text}</div>
      );
    });
    return (
      <div className="commentList">
        {commentNodes}
      </div>
    );
  }
});

var data1 = ['test2'];
var data2 = ['test1', 'test2'];

var node = TestUtils.renderIntoDocument(<CommentList data={data1} />);
node.setProps({data: data2}, function () {
  var comments = TestUtils.scryRenderedDOMComponentsWithClass(node, 'comment');
  console.log(comments[0].getDOMNode().innerHTML); //prints test2
  console.log(comments[1].getDOMNode().innerHTML); //prints test1
});
@gja
Copy link

gja commented Feb 8, 2015

I seem to be seeing this bug as well

@sophiebits
Copy link
Collaborator

Looks like this is fixed in master already. I'll add a test so it doesn't regress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants