Skip to content

null/undefined value does not remove xlink:/xml: attribute #3502

Open
@nolanlawson

Description

@nolanlawson

Description

Setting an attribute to a value of null or undefined will typically cause a removeAttribute call in LWC. However, this doesn't work for svg/xml namespace attributes (repro).

Template:

<template>
    <div title={prop}></div>
    <label xml:lang={prop}></label>
    <svg>
        <image xlink:title={prop}></image>
    </svg>
</template>

Result:

<div></div>
<label xml:lang="null"></label>
<svg>
  <image xlink:title="null"></image>
</svg>

Expected result:

<div></div>
<label></label>
<svg>
  <image></image>
</svg>

The root cause is these lines of code. Note that svg/xml namespace attributes will never result in a removeAttribute:

if (StringCharCodeAt.call(key, 3) === ColonCharCode) {
// Assume xml namespace
setAttribute(elm, key, cur as string, XML_NAMESPACE);
} else if (StringCharCodeAt.call(key, 5) === ColonCharCode) {
// Assume xlink namespace
setAttribute(elm, key, cur as string, XLINK_NAMESPACE);
} else if (isNull(cur) || isUndefined(cur)) {
removeAttribute(elm, key);
} else {
setAttribute(elm, key, cur as string);
}

Note that fixing this would be an observable change.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions