Skip to content

[LiveComponent] Morph error trying to apply invalid classes #1819

Closed
@aleho

Description

@aleho

When live components try to apply changes to elements for some reason the different classes are picked up with whitespaces or even empty strings. Browser console then throws Uncaught (in promise) DOMException: DOMTokenList.remove: The empty string is not a valid token..

This happened here when an element was morphed that probably shouldn't have been in the first place (and data-skip-morph doesn't solve the problem).


For example when an inline menu (with ID and data-skip-morph) is displayed after clicking an element only the class "hidden" changes. Then after updating the live component the element and its menu are still there (but the menu should be invisible, as backend renders context menus hidden of course):

The changes that are picked up:

  • addedClasses: Set [ "w-full" ].
  • removedClasses: Set(3) [ "", "hidden\n", "w-full\n" ]

In my case, simply filtering class changes at least prevents the error and didn't have any side effects here:

className = className.trim();

if (className === '') {
    return;
}

addClass(className: string) {
if (!this.removedClasses.delete(className)) {
this.addedClasses.add(className);
}
}
removeClass(className: string) {
if (!this.addedClasses.delete(className)) {
this.removedClasses.add(className);
}
}

Am I doing something wrong?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions