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

[📖] CSS Modules and useStyles$() hook approach incompatibility #7145

Open
shukklin opened this issue Dec 10, 2024 · 0 comments
Open

[📖] CSS Modules and useStyles$() hook approach incompatibility #7145

shukklin opened this issue Dec 10, 2024 · 0 comments
Labels
COMP: docs Improvements or additions to documentation STATUS-1: needs triage New issue which needs to be triaged

Comments

@shukklin
Copy link

shukklin commented Dec 10, 2024

Suggestion

Original docs URL are:
https://qwik.dev/docs/components/styles/#css-modules
https://qwik.dev/docs/components/styles/#usestyles

The context:

  1. We have several Qwik repositories - UI Kit and SSR application.
  2. We build the UI Kit using Vite with separate index (.js, .css) files for each components to support further tree-shaking in the SSR application.
  3. Then we use these builded files in the SSR application and link styles using the useStyles$() hook to support tree-shaking. Because if we import only pure CSS modules without processing it with useStyles$() hook, we will get one large CSS file bundled, which is not good for a large amount of CSS code (currently we have about 840KB CSS bundle size code in total).

We have found that Qwik does not support the use of CSS Modules together with useStyles$()/useStylesScoped$() hooks to load only required CSS rules on the page, as the styles loaded from CSS Modules don't tree-shake (look at the screenshot below with identical styles in different chunks). This leads to CSS code duplication and increased bundle size.

image

As it turned out, useStyles$()/useStylesScoped$ hooks only supports plain CSS, but not CSS Modules.

I think this point should be better reflected in the documentation, because at the moment there is nothing about it and it is not entirely clear.

@shukklin shukklin added COMP: docs Improvements or additions to documentation STATUS-1: needs triage New issue which needs to be triaged labels Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
COMP: docs Improvements or additions to documentation STATUS-1: needs triage New issue which needs to be triaged
Projects
None yet
Development

No branches or pull requests

1 participant