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 variables missing in Next.js #3

Open
sumanbh opened this issue Sep 26, 2024 · 4 comments
Open

Style variables missing in Next.js #3

sumanbh opened this issue Sep 26, 2024 · 4 comments

Comments

@sumanbh
Copy link

sumanbh commented Sep 26, 2024

Something is off with the logic of nextjsMode - it does not include all the generated styles if the styles are coming from a library/package:

Screenshot 2024-09-26 at 11 06 41 AM

Workaround: if we remove the clear call, then we do get all the styles (as far as I can tell).

@SukkaW
Copy link
Owner

SukkaW commented Sep 27, 2024

The .clear() was used to de-duplicated stylex rules, since stylex-webpack is able to collect stylex rules from both chunk information and the loader.

It is weird that the styles coming from library/modules are not included in the stylex chunk:

stylex-webpack/src/index.ts

Lines 110 to 116 in 67b9c12

compiler.options.optimization.splitChunks.cacheGroups[STYLEX_CHUNK_NAME] = {
name: STYLEX_CHUNK_NAME,
test: VIRTUAL_CSS_PATTERN,
type: 'css/mini-extract',
chunks: 'all',
enforce: true
};

@sumanbh
Copy link
Author

sumanbh commented Dec 3, 2024

Could it be related to RSC? Not an exact replication but we can see a similar issue here - https://github.com/sumanbh/next-stylex-webpack - navigating from home / to /test by clicking "Go to test" results in no styles from the test page.

Also, shouldn't stylex-webpack collect styles from all pages? I've found this next.js specific logic results in different file sizes (and missing style variables) for the generated css file based on the route user's in.

@SukkaW
Copy link
Owner

SukkaW commented Dec 4, 2024

Could it be related to RSC? Not an exact replication but we can see a similar issue here - https://github.com/sumanbh/next-stylex-webpack - navigating from home / to /test by clicking "Go to test" results in no styles from the test page.

I can't re-produce this using npm run build && npm run start. So this only happens with HMR.

Also, shouldn't stylex-webpack collect styles from all pages? I've found this next.js specific logic results in different file sizes (and missing style variables) for the generated css file based on the route user's in.

In fact, the nextjsMode was trying to collect styles from all pages because Next.js by default compiles RSC and client bundle separately.

@SukkaW
Copy link
Owner

SukkaW commented Dec 4, 2024

Update

Actually, after navigation to /test, the new CSS Rules have been collected and the new CSS has been generated:

image

However, for some reason compilation.updateAsset didn't trigger the HMR update of the new module. And this is something out of my reach.

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