Skip to content

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

Closed
@chris-morgan

Description

@chris-morgan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions