Skip to content

<a href={null}> sets href="null" rather than omitting the attribute #2088

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

Closed
chris-morgan opened this issue Feb 17, 2019 · 1 comment
Closed

Comments

@chris-morgan
Copy link
Contributor

Trivial reproduction case:

<a href={null} something-else={null}>Alas!</a>

In the compiled JavaScript:

			a.href = null;
			setAttribute(a, "something-else", null);

Although a.href = null; is shorter than setAttribute(a, "href", null), it’s incorrect, because setting HTMLAnchorElement.prototype.href stringifies its argument, including null, and so you end up with <a href="null>.

It’s not the most common situation to craft an <a> which may or may not have an href, but I just hit this now.

@Conduitry
Copy link
Member

This is a duplicate of the (admittedly slightly meandering) #1434. This has been an issue since the very beginning of Svelte. Rich doesn't remember why he decided to use properties instead of attributes where possible (i.e., whether it was a performance thing or a code size thing). My comment on that issue from January 10 has a workaround. But this is still a known bug, just one not on the front burning right now amid v3 stuff.

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

2 participants