Skip to content
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

Normalize whitespace for style and class attributes (breaking change) #4124

Open
Tracked by #2964
nolanlawson opened this issue Apr 5, 2024 · 2 comments
Open
Tracked by #2964

Comments

@nolanlawson
Copy link
Contributor

For HTML templates containing static style/class attributes such as this:

<div class=" foo bar     baz "></div>
<div style=" color  :  red ! important  "></div>

... we are inconsistent about how this is actually serialized to the DOM. For static-optimized nodes, the attributes are kept as-is. For non-static-optimized nodes, the whitespace/semicolons are normalized:

<div class="foo bar baz"></div>
<div style="color: red !important;"></div>

This also applies to the case of blank vs missing attributes. For example:

<div class=""></div>
<div style=" "></div>

In the static-optimized case, these attributes are kept as-is. For the non-static-optimized case, the attributes are removed entirely:

<div></div>
<div></div>

This doesn't really matter unless the developer is doing something zany (e.g. querySelector('[class="foo bar baz"]') rather than querySelector('.foo.bar.baz')), but we should at least be consistent about it.

We have also warned developers about this in the past, but not every developer follows these guidelines.

This would be a potentially breaking change.

@HermanBide
Copy link

can i work on this ?

@nolanlawson
Copy link
Contributor Author

@HermanBide I would recommend against taking this one, since it is a breaking change and so we will have to be careful about it.

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

No branches or pull requests

2 participants