-
Notifications
You must be signed in to change notification settings - Fork 291
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
Next 13/14 App Router Issue #1230
Comments
@headline-design This could likely be the result of next loading styles out of order in dev mode vs production (not something we can really fix on our end). I think the issue here might not be your actual reset styles, but rather the order you're importing them. In dev they just happened to be correct, but in prod the order your modules resolve dictates the stylesheet order. Are you importing your reset styles at the top of your app? If you just rely on your Alternatively, scoping your reset styles to a cascade layer can help. |
I ran into a similar issue. We use this in our code: import { globalLayer } from '@vanilla-extract/css';
export const resetLayer = globalLayer('reset');
export const baseLayer = globalLayer('base');
export const uiPrimitivesBaseLayer = globalLayer('uiPrimitivesBase');
export const uiPrimitivesPropsLayer = globalLayer('uiPrimitivesProps');
export const uiCompositesLayer = globalLayer('uiComposites');
export const sectionLayer = globalLayer('section'); In dev-mode this works well (checking the dev-tools in Chrome): But on production you'll see the order all wrong: I could fix this by writing a small script (in the root folder) that prepends the correct order of the layers in all generated css-files, like this: // fix-build-css.js
/**
* Small script to prepend the correct layer-order into each generated css-file for NextJS Builds
* This is necessary because the Vanilla-extract files are loaded out of order during production-build, which will screw up the layer-ordering
*/
const fs = require('fs');
const path = require('path');
const cssFilesPath = path.posix.join(
__dirname,
`.next`,
'static/css'
);
const cssLayerFixStyle =
'@layer reset, base, uiPrimitivesBase, uiPrimitivesProps, uiComposites, section;\n';
const fixCssFiles = async () => {
const folderContent = await fs.readdirSync(cssFilesPath);
const cssFiles = folderContent.filter(
(item) => path.extname(item) === '.css'
);
cssFiles.forEach((filename) => {
const filepath = path.posix.join(cssFilesPath, filename);
const cssContent = fs.readFileSync(filepath);
fs.writeFileSync(filepath, cssLayerFixStyle + cssContent);
});
console.log('fixed Vanilla Extract build css-files');
};
fixCssFiles(); And trigger this script after each prod-build like this: // package.json
"build: next build && yarn fix-build-css.js" It works, but I am very unhappy of course with this 'solution' and would love to see some guidance of VE-team on how to fix this better? |
@headline-design Could you please try out v2.4.0 of the next plugin to see if that addresses any of your issue? If it doesn't, it would really help if you could provide a minimal reproduction. @rnacken I can't reproduce your out-of-order layers bug with the latest next plugin. Not sure if this was because of the fixes in that version, or other fixes on the next side. Could be related to #1112. |
@askoufis Sorry it took a while; can confirm - it works now. Thanks |
All good, thanks for following up! @headline-design Any update from your end? |
Describe the bug
So this is an issue and solution we have encountered with Vanilla Extract and App Router - Next13/14. Everything looks fine in development, but as soon as you go to build the application, styles are no longer applied correctly. The classnames are set correctly but the specificity is all screwed up. Basically, what appears to be happening is that the Next build system is placing the wrong styles at the top of the stack. After quite a bit of digging, what we discovered was that the issue could be resolved by removing the reset/default style for the Box element. Anyone working with a design system and encounters this problem can try the remove reset solution. It's more of a temp solution, but it fixed the issue. We tried this with at least a dozen different configurations of versions for vanilla extract and next. This is specificaly an issue on app router, no such issues on pages router.
Reproduction
n/a.
System Info
Used Package Manager
yarn
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: