question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DOM nesting warning is confusing for whitespace (and text in general)

See original GitHub issue

When a user puts a textnode (whitespace) in an illegal location, our warning complains about a span element (because we wrap text - including whitespace - in a span). This is confusing for new users, since there is no span present in their code and the introduction of the span tag is an implementation detail of React. We should fix the warning to better align with the code the user is looking at.

var rows = <tr></tr>;
React.render(<table><tbody> {rows} </tbody></table>, document.getElementById('container'));

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:20 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
Ajaybhardwaj7commented, Aug 1, 2016

It took me nearly one hour until I came to this page to know about the actual cause of warning. There were one whitespace between my and like this and here it went everything confusing to understand this kind of bug. “#text cannot appear as a child of ”. Really hard to resolve by this message.

2reactions
jimfbcommented, Oct 8, 2015

@spicyj I think this might be a bit advanced to be a good-first-bug. Specifically, we need to handle three general cases:

  • The user actually specified a span: <table><span>foo</span></table>. In which case, we should indicate that there is a span.
  • The user did not specify a span, but did specify child text: <table>foo</table>
  • The user did not specify a span, but did specify only whitespace: <table> </table>. In which case, we should call out the whitespace, because if we just call it text, it’ll be easy to miss and be confused about what’s going on. Whitespace includes tabs, newlines, and spaces.
Read more comments on GitHub >

github_iconTop Results From Across the Web

React: Warning: validateDOMNesting(...): Whitespace text ...
I am trying to find an answer in stack but I don't actually have a or any table element in my project because...
Read more >
React DOM elements should be nested properly - DeepScan
This rule applies when React DOM elements are not nested properly according to the HTML specification. React requires using valid DOM elements ...
Read more >
HTML Standard
3.2.1 Semantics; 3.2.2 Elements in the DOM; 3.2.3 HTML element constructors ... 4.8.4.4 Requirements for providing text to act as an alternative for...
Read more >
3.2.5 Content models — HTML5 - W3C
Text is sometimes used as a content model on its own, but is also phrasing content, and can be inter-element whitespace (if the...
Read more >
JSHint Options Reference
Bitwise operators are very rare in JavaScript programs and quite often & is simply a mistyped && . camelcase. Warning This option has...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found