Skip to content

Inconsistent Handling of null/undefined Attributes Between Component Properties and lwc:spread #5336

@Mr-VincentW

Description

@Mr-VincentW

Description

When binding attributes to an HTML element using component properties and the lwc:spread directive, null or undefined values are handled inconsistently.

  • When set via a standard component property, attributes with null or undefined values are removed from the element.

  • When set via lwc:spread, those same values are rendered as the string "null" or "undefined".

Steps to Reproduce

  1. Open the playground link

  2. Observe a element with the following attributes:

    • id: set via a normal component property

    • title and lang: set via lwc:spread

  3. Click the button to set both id and lang to null.

Expected Results

All attributes bound to null or undefined, regardless of binding method, should be removed from the DOM.
Specifically to the demo, both id and lang should be removed from the button element.

Actual Results

  • id is correctly removed.
  • lang remains on the element and is set to the string "null".

Browsers Affected

All.

Version

  • LWC: 8.16.3

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