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.

Multiple self-closing children causes nested children tree

See original GitHub issue

While writing some tests for #33 I found that when using multiple self closing children in a parent it nests them.

In other words this:

<div>
  <div />
  <div />
</div>

Results in a nested tree like this:

<div>
  <div>
    <div></div>
  </div>
</div>

Another find, which is also in the tests, was that the whitelisted self-closing tags (such as <br>) instead causes an exception when written as a open tag, like <br></br>. Which might be correct, but the exception message (Error: multiple root elements must be wrapped in an enclosing tag) was a bit confusing.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:2
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
slaskiscommented, Feb 2, 2017

Very interesting @rbiggs! I haven’t actually read the spec and was just going by intuition 😉

I do read that spec slightly different though. Regarding start tags it may have one or more space characters unless there are attributes.

And it does only mention self-closing tags for void elements, for which it’s optional and “has no effect”, and foreign elements (such as svg), for which it is required unless there is an end tag.

As for the normal tags my intuition says that html5 is pretty chill. But you’re absolutely right that the validator complains, and it gives me this message:

Self-closing syntax (/>) used on a non-void HTML element. Ignoring the slash and treating as a start tag.

However, the way I’ve seen this package is less stringified html and more like a “no need to preprocess jsx”. And since jsx treats self-closing tags the same as closed tag without children I expected this to work here as well.

1reaction
rbiggscommented, Feb 2, 2017

Just so you know, self-closing tags should always have at least one space character between the tag name and the U+002F (“/”) character. Not including a space should result in an error according to the specs from W3C. Same for <img />. See documentation on HTML 5 closing tags. Standard self-closing tags are:

  • br
  • hr
  • img
  • input
  • meta

These are never closed, you can use the forward slash / to close them or not.

By the way, <div /> is not a self-closing tag and should throw an error. Problem is jQuery does accept this, going against W3C docs. They have examples on their site of using this bad syntax, encouraging junior developers to using this broken HTML syntax: var div = $('<div/>')

Creates a correct div element, although it is incorrect HTML5.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chaining of Python generators to traverse a nested data ...
Suppose I have a nested data structure that I want to traverse. This data structure contains nodes which in turn may offer their...
Read more >
Closure Tree | closure_tree - GitHub Pages
As stated above, using multiple hierarchy gems (like ancestry or nested set ) on the same model will most likely result in pain,...
Read more >
(Not so) Simple ARIA Tree Views and Screen Readers | Articles
I started testing a number of screen readers with different ARIA tree views. It turns out there's a bit going on with screen...
Read more >
ViewGroup - Android Developers
android:animateLayoutChanges, Defines whether changes in layout (caused by adding ... Enable or disable the splitting of MotionEvents to multiple children ...
Read more >
Recursive function to add children to nested list - General
I am working on making nested lists for visualisation in a tree map. For this, I am looking for a recursive function that...
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