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

React.Fragment causes errors in the console #261

Closed
oddsund opened this issue Nov 5, 2018 · 3 comments
Closed

React.Fragment causes errors in the console #261

oddsund opened this issue Nov 5, 2018 · 3 comments

Comments

@oddsund
Copy link
Contributor

oddsund commented Nov 5, 2018

I'm submitting a ...

[X ] bug report
[ ] feature request
[ ] support request

If you're reporting a bug, please provide a minimal demonstration of the problem

https://codesandbox.io/s/ll886vz80l

What is the current behavior?

An error stating "TypeError: _this.content is undefined" is printed on each scroll event when returning React.Fragment from the render callback function.

What is the expected or desired behavior?

No error.

Why do you want this? What use case do you have?

A Sticky element containing several elements.

What is your environment?

  • Version: 6.0.3
  • Browser: Firefox 63
  • React: 16.6

Is there anything else I should know?

The error seems to come from src/Sticky.js#L125. findDOMNode seems to return undefined when called with the context of a react fragment, even though it should return the ref to the first child.

While it might not make sense to use Fragments as a child of a Sticky node, some documentation mentioning it would be greatly appreciated. :)

Also, as a heads up, findDOMNode is on its way to deprecation(according to facebook/react#13841, solution here: https://reactjs.org/docs/strict-mode.html#warning-about-deprecated-finddomnode-usage)

@vcarl
Copy link
Contributor

vcarl commented Nov 5, 2018

Thanks for the issue! Yeah, findDOMNode definitely isn't ideal. I'm not positive we can solve this, as we need to measure the DOM node and Fragments don't create one. If you want to open a PR to the docs for now, I'd be happy to merge it.

@Simek
Copy link

Simek commented Dec 31, 2018

React fragment is also responsible for getBoundingClientRect error in console:
Sticky.js:61 Uncaught TypeError: Cannot read property 'getBoundingClientRect' of undefined at Sticky._this.handleContainerEvent

Changing Fragment to HTML tag fixes this issue.

@vcarl
Copy link
Contributor

vcarl commented Dec 31, 2018

Yes, this is known behavior.

we need to measure the DOM node and Fragments don't create one.

Open to contributions to improve docs or behavior around this!

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

No branches or pull requests

3 participants