-
-
Notifications
You must be signed in to change notification settings - Fork 319
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
[LiveComponent] Morph error trying to apply invalid classes #1819
Comments
Where and how is the |
|
Could you create a minimal reproducer ? It would be easier to investigate, thank you :) |
Hey I tried to reproduce your issue on the UX website but couldn't! What I did was take a live component where the class changes and add space at the beginning of the class attribute on this component:
There may maybe something I don't understand about your issue, could you try to reproduce your issue on this component ? |
The class attribute can be tokenized by any white space as defined by the HTML spec. A class string containing new lines was not correctly cleaned / trimmed, resulting in incorrectly detected class changes and a browser error if empty classes or classes with newlines were applied. Fixes symfony#1819
After investigating further I finally found the root of the problem:
According to the HTML standard the class attribute can contain "a set of space-separated tokens". Splitting on spaces only will tokenize newlines too resulting in an array containing newlines and empty spaces. ux/src/LiveComponent/assets/src/Rendering/ExternalMutationTracker.ts Lines 193 to 201 in 3962582
You can easily reproduce this with a simple markup for a live component: <div {{ attributes }}>
<p
class="
a
b
c
"
>
<button type="button" data-action="live#$render" onclick="this.parentElement.classList.remove('a')">
Remove class and render
</button>
</p>
</div> |
Ok i'm pretty sure we already had a problem with that but great if you have a fix :) |
The class attribute can be tokenized by any white space as defined by the HTML spec. A class string containing new lines was not correctly cleaned / trimmed, resulting in incorrectly detected class changes and a browser error if empty classes or classes with newlines were applied. Fixes symfony#1819
What class |
The class attribute can be tokenized by any white space as defined by the HTML spec. A class string containing new lines was not correctly cleaned / trimmed, resulting in incorrectly detected class changes and a browser error if empty classes or classes with newlines were applied. Fixes symfony#1819
The class attribute can be tokenized by any white space as defined by the HTML spec. A class string containing new lines was not correctly cleaned / trimmed, resulting in incorrectly detected class changes and a browser error if empty classes or classes with newlines were applied. Fixes symfony#1819
The class attribute can be tokenized by any white space as defined by the HTML spec. A class string containing new lines was not correctly cleaned / trimmed, resulting in incorrectly detected class changes and a browser error if empty classes or classes with newlines were applied. Fixes symfony#1819
The class attribute can be tokenized by any white space as defined by the HTML spec. A class string containing new lines was not correctly cleaned / trimmed, resulting in incorrectly detected class changes and a browser error if empty classes or classes with newlines were applied. Fixes symfony#1819
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:
ux/src/LiveComponent/assets/src/Rendering/ElementChanges.ts
Lines 13 to 23 in 80b36bc
Am I doing something wrong?
The text was updated successfully, but these errors were encountered: