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 attributes (breaking change) #4124

Closed
Tracked by #2964
nolanlawson opened this issue Apr 5, 2024 · 4 comments · Fixed by #4553
Closed
Tracked by #2964

Normalize whitespace for attributes (breaking change) #4124

nolanlawson opened this issue Apr 5, 2024 · 4 comments · Fixed by #4553

Comments

@nolanlawson
Copy link
Collaborator

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
Collaborator 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.

Copy link

git2gus bot commented Aug 5, 2024

This issue has been linked to a new work item: W-16419702

@nolanlawson nolanlawson changed the title Normalize whitespace for style and class attributes (breaking change) Normalize whitespace for attributes (breaking change) Aug 5, 2024
@nolanlawson
Copy link
Collaborator Author

Per #3548 this is also true for arbitrary attributes.

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

Successfully merging a pull request may close this issue.

2 participants