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

<a> tags cannot be self-closing #200

Closed
Rich-Harris opened this issue Dec 15, 2016 · 7 comments · Fixed by #201
Closed

<a> tags cannot be self-closing #200

Rich-Harris opened this issue Dec 15, 2016 · 7 comments · Fixed by #201
Labels

Comments

@Rich-Harris
Copy link
Member

Just encountered an interesting bug. The Svelte SSR compiler uses self-closing tags for elements without children:

<div/> <!-- equivalent to <div></div> -->

But that doesn't work with some elements:

<a href='https://whatever.com'/>
<p>this will be included in the link!</p>

It needs to be <a ...></a> instead. Empty anchor tags is a bit of an edge case, but it should still be handled. Am wondering which other elements can't use self-closing tags though. A quick Google doesn't yield anything interesting – does anyone out there know the answer? Or should we just always use closing tags for non-void elements?

@Ryuno-Ki
Copy link

According to http://stackoverflow.com/a/3558200 the answer is “it depends”.

Maybe you should take a look at the HTML5 spec ;-)

@Rich-Harris
Copy link
Member Author

The spec suggests that all elements except void elements and foreign elements (i.e. SVG) need a closing tag. But browsers definitely parse things like <div/> just fine, so [shruggie]

@Ryuno-Ki
Copy link

Switch to XHTML if you want crashed in the renderer hides

Jokes aside, would it be an option to omit the closing slash in a tag? AFAIK browser can deal with that better (have a look at <img> or <input> in your browser's Inspector).

@Rich-Harris
Copy link
Member Author

Closing slashes are omitted for void elements, this is about 'normal' elements

@Ryuno-Ki
Copy link

In HTML5, the meaning of depends on the type of element.
[…]
On other HTML elements, it is an error, but error recovery will cause browsers to treat it as a start tag. This will usually end up with a missing end tag putting subsequent elements as children of it.

(highlighting mine)

Can't you omit it on those normal elements as well?

@Rich-Harris
Copy link
Member Author

Where is that pasted from?

@Ryuno-Ki
Copy link

The StackOverflow question I've linked above.

Rich-Harris added a commit that referenced this issue Dec 15, 2016
Rich-Harris added a commit that referenced this issue Dec 15, 2016
don't self-close elements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants