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

@unocss/astro doesn't work with client:only components #2325

Closed
4 tasks done
kidonng opened this issue Mar 7, 2023 · 2 comments
Closed
4 tasks done

@unocss/astro doesn't work with client:only components #2325

kidonng opened this issue Mar 7, 2023 · 2 comments

Comments

@kidonng
Copy link
Contributor

kidonng commented Mar 7, 2023

UnoCSS version

0.50.4

Describe the bug

Astro has a client:only directive that skips server rendering of components. Currently this directive makes UnoCSS's Astro integration unaware of the component and skips generating styles for it.

It is mentioned changing page-ssr to page here works:

injectScript('page-ssr', injects.join('\n'))

This does generate correct CSS, however the CSS file is not imported in the generated HTML, so the fix is not that simple.

Reproduction

https://stackblitz.com/edit/node-6xfq8u

Notice how in the generated CSS, .text-blue in Astro component is present, but .text-red in Svelte component with client:only is missing.

System Info

No response

Validations

@sibbng
Copy link
Member

sibbng commented Mar 7, 2023

It will work if you nest your components under components folder.

Alternatively, you can provide additional files in extraContent option:

extraContent: {
  filesystem: ['src/component.svelte']
},

@sibbng sibbng closed this as completed Mar 7, 2023
@kidonng
Copy link
Contributor Author

kidonng commented Mar 7, 2023

I did notice this:

options.extraContent.filesystem.push(resolve(fileURLToPath(config.root), 'src/components/**/*').replace(/\\/g, '/'))

However I never thought it would be the culprit. Just opened a #2326 for this.

Meanwhile, I think the info you provided is helpful enough to be in the README, I will also open a pull request for this.

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

2 participants