percyhanna / rquery

A testing utility that provides React tree traversal similar to jQuery
MIT License
56 stars 9 forks source link

"TypeError: Cannot read property 'getAttribute' of null" form component without dom node #37

Closed karudo closed 8 years ago

karudo commented 8 years ago

I have error in my test

TypeError: Cannot read property 'getAttribute' of null
    at rquery_getReactId (/Users/dperetyagin/work/pwdocker/Pushwoosh/Web/new/src/js/views/applications/application/__tests__/deeplinks-test.js:35083:41 <- webpack:///~/rquery/rquery.js?f17e:70:0)
    at componentDepth (/Users/dperetyagin/work/pwdocker/Pushwoosh/Web/new/src/js/views/applications/application/__tests__/deeplinks-test.js:35071:26 <- webpack:///~/rquery/rquery.js?f17e:58:0)

I did some research and came to the conclusion that the cause is component Collapse from react-bootstrap ReactDOM.findDOMNode() for this component returns null, because the component have not any dom node.

percyhanna commented 8 years ago

I've never seen findDOMNode return null unless there's an error in your rendering. The render function must ALWAYS return an element, so every component must had a DOM node.

My suspicion is that your DOM tree is being modified by the browser, which would normally cause an invariant violation as well. See here: http://stackoverflow.com/questions/25026399/uncaught-error-invariant-violation-findcomponentroot-110-unable-to

In any case, I need an easily reproducible example in order to be able to fix anything. findDOMNode always returns a value for valid React trees.

percyhanna commented 8 years ago

Not a bug in rquery, from what I can tell.

karudo commented 8 years ago

Why the render function must ALWAYS return an element? The documentation says that the render function may return null

You can also return null or false to indicate that you don't want anything rendered. Behind the scenes, React renders a <noscript> tag to work with our current diffing algorithm. When returning null or false, ReactDOM.findDOMNode(this) will return null.

percyhanna commented 8 years ago

Hmm, I had missed that change in the React spec. In previous versions render was definitely required to return something.

percyhanna commented 8 years ago

Fix released as version 4.3.0. Hopefully that works for you. Thanks for the bug report!

karudo commented 8 years ago

Yes, its works for me. Thank you!