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

Inconsistent rendering of empty class/style in static vs dynamic nodes #3548

Open
Tracked by #2964
nolanlawson opened this issue Jun 1, 2023 · 4 comments
Open
Tracked by #2964
Labels

Comments

@nolanlawson
Copy link
Contributor

nolanlawson commented Jun 1, 2023

Description

The following template HTML:

<!-- empty class -->
<div data-dynamic={dynamic} class=""></div>
<div class=""></div>
<!-- empty style -->
<div data-dynamic={dynamic} style=""></div>
<div style=""></div>
<!-- empty attr -->
<div data-dynamic={dynamic} data-attr=""></div>
<div data-attr=""></div>
<!-- nonexistent class/style/attr -->
<div data-dynamic={dynamic}></div>
<div></div>

...results in the following serialized HTML:

<!-- empty class -->
<div></div>
<div class=""></div>
<!-- empty style -->
<div></div>
<div style=""></div>
<!-- empty attr -->
<div data-attr></div>
<div data-attr=""></div>
<!-- nonexistent class/style/attr -->
<div></div>
<div></div>

Update: this works the same for client-rendering as well: playground.

Note that class and style are inconsistent – they are serialized as '' in the static case, and nonexistent in the dynamic case.

This means that the behavior of getAttribute differs at runtime – either returning '' or null. Also, CSS selectors like [class] or [style] will behave differently.

Steps to Reproduce

git clone git@github.com:nolanlawson/lwc-barebone.git
cd lwc-barebone
git checkout 214418d
yarn dev # go to localhost:3000

Expected Results

Serialized output is the same regardless of whether the vnode is static-optimized or not.

Actual Results

Static optimization leads to different results, only for class and style.

@nolanlawson
Copy link
Contributor Author

For the most consistency, and to align with author intention, I think we should serialize the empty string in all cases. If the author put class="", then let's serialize class="".

FYI @divmain

@git2gus
Copy link

git2gus bot commented Jun 1, 2023

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

@nolanlawson nolanlawson changed the title [SSR] Inconsistent serialization of empty class/style in static vs dynamic nodes Inconsistent rendering of empty class/style in static vs dynamic nodes Jun 1, 2023
@nolanlawson
Copy link
Contributor Author

Just realized this works the same as CSR, not just SSR. Updated.

@nolanlawson
Copy link
Contributor Author

Since it already works this way in CSR, this would be an observable (breaking) change.

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

No branches or pull requests

1 participant