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

Style scoping bug when moving to v0.11.x #154

Closed
cssandstuff opened this issue Apr 3, 2023 · 6 comments
Closed

Style scoping bug when moving to v0.11.x #154

cssandstuff opened this issue Apr 3, 2023 · 6 comments
Labels
bug Something isn't working
Milestone

Comments

@cssandstuff
Copy link

Given two webc components
c-red.webc

<div webc:root="override">
  <slot></slot>
</div>

<style webc:scoped>
  :host {
    background-color: red;
  }
</style>

c-blue.webc

<div webc:root="override">
  <slot></slot>
</div>

<style webc:scoped>
  :host {
    background-color: blue;
  }
</style>

and their usage:
page.webc

<c-red>Hi I am red</c-red>
<c-blue>Hi I am blue</c-blue>

<c-red>
  I am red.
  <c-blue>Hi I am blue</c-blue>
  still red
</c-red>

<c-blue>
  I am blue.
  <c-red>Hi I am red</c-red>
  still blue
</c-blue>

Prior to v0.11
would result in:

<div class="wpqw-v5wk">
  Hi I am red
</div>
<div class="wxarocnxj">
  Hi I am blue
</div>

<div class="wpqw-v5wk">
  I am red.
  <div class="wxarocnxj">Hi I am blue</div>
  still red
</div>

<div class="wxarocnxj">
  I am blue.
  <div class="wpqw-v5wk">Hi I am red</div>
  still blue
</div>

.wxarocnxj{background-color:blue}
.wpqw-v5wk{background-color:red}

but after moving to v0.11
it results in the same html but extra/borked css styles, it seems like the :host selector leaks upwards (if that makes any sense).

.wxarocnxj{background-color:blue}
.wpqw-v5wk{background-color:blue}
.wpqw-v5wk{background-color:red}
.wxarocnxj{background-color:red}
@cssandstuff
Copy link
Author

cssandstuff commented Apr 3, 2023

I guess the clearer description is that if you style using :host in a component and you're using that component inside another (via a slot) then the :host css for that component makes its way into the parent somehow.

@rijkvanzanten
Copy link

rijkvanzanten commented Apr 4, 2023

I just noticed the same behavior. Looks like the scoping of the styles is "scoped" to the outer parent component, meaning that things like

<style webc:scoped>
  div {
    color: red;
  }
</style>

suddenly have nasty side-effects if you're working with nested webc components

@zachleat
Copy link
Member

zachleat commented Apr 4, 2023

apologies, I think this may be the regression introduced in v0.11 and fixed with #152 but I will investigate further.

@zachleat zachleat added the bug Something isn't working label Apr 4, 2023
@zachleat zachleat added this to the WebC v0.11.2 milestone Apr 4, 2023
zachleat added a commit that referenced this issue Apr 4, 2023
@zachleat
Copy link
Member

zachleat commented Apr 4, 2023

I did confirm that this is fixed by #152 with the test case you supplied, thank you!

Shipping with v0.11.2 today.

@zachleat zachleat closed this as completed Apr 4, 2023
@rijkvanzanten
Copy link

Thanks @zachleat! Killing it as always 🚀

@zachleat
Copy link
Member

zachleat commented Apr 4, 2023

Thank you @rijkvanzanten!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants