8000 CSS :host() does not work · Issue #2144 · lit/lit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

CSS :host() does not work #2144

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

Closed
busynest opened this issue Sep 9, 2021 · 5 comments
Closed

CSS :host() does not work #2144

busynest opened this issue Sep 9, 2021 · 5 comments

Comments

@busynest
Copy link
busynest commented Sep 9, 2021

Description

  • Jacek Markiewicz

  • To make :host() work again. Stopped working after upgrade.

  • To encapsulate CSS within element, without leaking out.

  • Example: All various form{} properties effect a form that is suppoed to be encapulated.

  • adding and removing<script src="node_modules/lit/polyfill-support.js"> causes weird breaks (mostly toast and drawer) , but doesn't help.

Project:

From what I can tell, maybe typescript merge brings everything together in a non encapsulated way.

I also tried static get styles() vs static styles

@busynest
Copy link
Author
busynest commented Sep 9, 2021

update to lit Solved: :host() and encapsulation works again.

somehow I circled back to static get styles():CSSResult { return css' :host{} ... ' }

The problem was probaly caused by instructions saying to use static styles = css' :host {} ...'
and somehow polyfill-support.js loads properly now.

@thescientist13
Copy link
Contributor

@busynest
I think the way I understand the distinction between these two

static styles = css`
  p {
    color: green;
  }
`;
static get styles() {
  const mainColor = css`red`;
  return css`
    div { color: ${mainColor} }
  `;
}

is that the first will only be evaluated once, and so the second form is intended for use with expressions (since it is a getter function), such that say if that mainColor variable changes, then only in the second case would the styles get updated again to reflect the new value / styles in your component.

Not sure if that applies to your use case since I don't know the full CSS.


I think an exception to the first case would be if you used CSS custom properties? In that case you could avoid having to implement the second variant and still get the performance benefit of the former.

I may be wrong, but just my thoughts on the subject, hopefully someone can help confirm for you.

@justinfagnani
Copy link
Collaborator

A static field and getter should behave the same. The only reason we ever showed the static getter is because fields weren't standardized quite yet. We don't call the getter multiple times.

@busynest
Copy link
Author
busynest commented Sep 9, 2021

Seems like "polyfill-support.js" was not loading, but works now.
Probably got fixed during a reinstall.

But this glitch was nice to see how Typescript merges everything into top-level application.

@sorvell
Copy link
Member
sorvell commented Sep 9, 2021

Closing since this appears to be resolved. Feel free to re-open with more info if the problem persists. Thanks.

@sorvell sorvell closed this as completed Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
0