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

Propose an alternative method to use Twind with Web components and Lit for Firefox and Safari #181

Closed
gawlk opened this issue May 2, 2021 · 4 comments
Labels
💡 Proposal Request for comments

Comments

@gawlk
Copy link

gawlk commented May 2, 2021

Hi,

Love this project, it works great, ton of great ideas but I have one small issue with it: it's with adoptedStyleSheets. It works great with Chrome but as you know it doesn't with Firefox or Safari. As it's the only way to use both twind with web components it's not at all usable in production.

I was wondering if you guys had any idea for an alternative method that would work on more browsers.

If not I fully understand, just thought to point the need for such functionality.

Anyway,

Thanks for you work

@gawlk gawlk changed the title Propose a different method to use Twind with Web components and Lit Propose an alternative method to use Twind with Web components and Lit-html May 2, 2021
@gawlk gawlk changed the title Propose an alternative method to use Twind with Web components and Lit-html Propose an alternative method to use Twind with Web components and Lit for Firefox and Safari May 2, 2021
@spitzertim
Copy link

spitzertim commented May 4, 2021

Hi,

I also really like the project. But as @gawlk mentioned, the implementation from the example is unusable in production due to the limitations in Firefox and Safari.
This problem applies to lit-element in particular. Even when using a polyfill, lit will analyse a sheet that is put in its static get styles() only once (and too early) and not update the injected styles tags after tw has "learned" about the relevant style classes.
I have build a workaround that injects a respective style tag from the firstUpdated hook, but it still has a major caveat. When working with conditionally applied classes, twind is updating the sheet again, which then needs to be reflected in the style-tag. I found no way to hook into this.
You can find an example here https://stackblitz.com/edit/lit-twind-firefox?file=index.js.

I would suggest some kind of hook/event that could be listened for to re-trigger the creation of the style.
An approach to solve this might be (optionally) providing tw as a real lit-element directive that causes lit-element to update all relevant parts when tw "learns" about new classes and updates its sheet. The Chrome version only works, because the sheet change is directly reflected by the browser without the need for lit-element to change anything in the shadow-dom.

Anyways, cool project! Keep up the good work!

@sastan
Copy link
Collaborator

sastan commented May 6, 2021

I'm not that familiar with web components and their frameworks. Would it be possible to use a style element (maybe using the dom sheet) for each web component which is updated per web component instance?

@just214 just214 added the 💡 Proposal Request for comments label Jun 8, 2021
@Zozman
Copy link

Zozman commented Nov 5, 2021

I gotta +1 this as well. I had a FANTASTIC time using this library over the last week on a project (super easy to use and super easy to tell what's a tailwind class and what's my class) until I noticed that my font sizes weren't right on Firefox and had to rip it all out and replace it with using PostCSS + Tailwind (using lit-element as well).

@stale stale bot added the 🛑 Abandoned The issue or Pull Request will not be worked on label Nov 18, 2022
@sastan sastan added 🙅 Hold Progress on the issue is stopped and removed 🛑 Abandoned The issue or Pull Request will not be worked on labels Nov 19, 2022
@sastan sastan removed the 🙅 Hold Progress on the issue is stopped label Dec 15, 2022
@sastan
Copy link
Collaborator

sastan commented Dec 15, 2022

This has been implemented in a new integration: @twind/with-web-components. It supports modern and legacy browsers.

You can view a preview of the docs here: https://next.twind-style.pages.dev/with-web-components. I have added a Lit example as well in case you are using that: https://next.twind-style.pages.dev/with-lit

This will be released soon (#417). Until is released you can use the pre-release version (for example @twind/with-web-components@next, @twind/core@next or @twind/preset-tailwind@next).

If you have any issues or questions please re-open this issue.

@sastan sastan closed this as completed Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💡 Proposal Request for comments
Projects
None yet
Development

No branches or pull requests

5 participants