-
Notifications
You must be signed in to change notification settings - Fork 28.5k
CSS "@import <file> layer()" isn't working #55763
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
Comments
Lol, this one is fun, I can reproduce it, it looks like the layers are not working from imported files inside the app directory. It will work if you move your theme.css file to the public directory, then import it @import "/theme.css" layer(theme); |
Just chipping in to share a similar experience, but in my case it looks like the statement doesn't even compile. Example:
Expected ';', got 'layer' The above code does compile without the layer addition. This is a bit of a deal-breaker for working with CSS layers in Next.js, in particular when you organize your own custom CSS into layers and then import a npm package that has styles. As the styles of the npm package are not in any of your layers, they take a higher specificity than any of your layers, thus making layer order somewhat pointless. The above syntax, if it would work, would solve that. It allows for the importing of external styles neatly into your layer order. For now I worked around it by copying the external styles, putting them in my own styles folder and wrapping the external styles into a layer, like so:
The downside is of course that this breaks npm update. |
For us, this was fixed by installing postcss-import, and adding it to |
It also appears that any This problem is also fixed by @hipdev 's workaround so I'm unsure if this is a separate bug (that would only have a visible effect once this bug is resolved) or a symptom of the same problem. |
I've been messing around with trying to get CSS Cascade layers working with NextJS, and found some interesting things of note. If you try to do @media layer(someLayer) {
// your css
} Which is basically invalid CSS and the selectors are essentially black hole'd. One interesting finding I did have though, is using However, all that said, when I build the bundle for prod, the broken |
## What's the purpose of this pull request? This PR aims to: - [x] add the tsconfig needed to run Next 13. It also set `"strictNullChecks": false` to make the Section Override v2 API work as previously. - [x] Fix styles order problem by adding webpack config in next.config.js. See vercel/next.js#51030 (comment) - [x] adds the initial prefix folder, root layout and initial page layout ## How to test it? run locally and you should see the initial structure under: http://localhost:3000/fs-next-update ### Starters Deploy Preview <!--- Add a link to a deploy preview from `gatsby.store` AND `nextjs.store` with this branch being used. ---> <!--- Tip: You can get an installable version of this branch from the CodeSandbox generated when this PR is created. ---> ## References Next 13 file conventions https://nextjs.org/docs/app/api-reference/file-conventions/layout CSS order issues: [[NEXT-1308] Css is imported multiple times and out of order in /app dir · Issue #51030 · vercel/next.js](vercel/next.js#51030 (comment)) [Verify CSS import ordering · Issue #16630 · vercel/next.js](vercel/next.js#16630) [CSS "@import <file> layer()" isn't working · Issue #55763 · vercel/next.js](vercel/next.js#55763) [[NEXT-1308] Css is imported multiple times and out of order in /app dir · Issue #51030 · vercel/next.js](vercel/next.js#51030 (comment)) strictNullChecks vercel/next.js#39942 https://www.typescriptlang.org/tsconfig/#strictNullChecks
This PR aims to: - [x] add the tsconfig needed to run Next 13. It also set `"strictNullChecks": false` to make the Section Override v2 API work as previously. - [x] Fix styles order problem by adding webpack config in next.config.js. See vercel/next.js#51030 (comment) - [x] adds the initial prefix folder, root layout and initial page layout run locally and you should see the initial structure under: http://localhost:3000/fs-next-update <!--- Add a link to a deploy preview from `gatsby.store` AND `nextjs.store` with this branch being used. ---> <!--- Tip: You can get an installable version of this branch from the CodeSandbox generated when this PR is created. ---> Next 13 file conventions https://nextjs.org/docs/app/api-reference/file-conventions/layout CSS order issues: [[NEXT-1308] Css is imported multiple times and out of order in /app dir · Issue #51030 · vercel/next.js](vercel/next.js#51030 (comment)) [Verify CSS import ordering · Issue #16630 · vercel/next.js](vercel/next.js#16630) [CSS "@import <file> layer()" isn't working · Issue #55763 · vercel/next.js](vercel/next.js#55763) [[NEXT-1308] Css is imported multiple times and out of order in /app dir · Issue #51030 · vercel/next.js](vercel/next.js#51030 (comment)) strictNullChecks vercel/next.js#39942 https://www.typescriptlang.org/tsconfig/#strictNullChecks
Currently facing the exact same thing. It still is an issue. |
This is a blocker to upgrading to Tailwind v4 for us, since disabling Tailwind's Preflight styles requires using the unsupported @hipdev's work-around (putting the CSS in public to let the browser handle the |
It appears that support for I might be able to contribute these changes if I had some indication that updates to Next's bundled css-loader (and next-style-loader) would be welcome. |
@sentience Thank you! Long time no see on this thread. If you need further assistance, I’m happy to help as well. |
Link to the code that reproduces this issue
https://codesandbox.io/p/sandbox/next-js-css-import-layer-bug-h3j5tq
To Reproduce
global.css
) add@import './theme.css' layer(theme)
Current vs. Expected behavior
Expected behaviour:
All styles from
theme.css
are applied.Actual behaviour:
No styles from
theme.css
are applied.Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.6.0: Wed Jul 5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000 Binaries: Node: 18.13.0 npm: 8.19.3 Yarn: N/A pnpm: N/A Relevant Packages: next: 13.5.3-canary.0 eslint-config-next: 13.5.2 react: 18.2.0 react-dom: 18.2.0 typescript: 5.2.2 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Not sure
Additional context
This bug appears in both the old pages router and app router. It does not happen with a bare-bones React application created with
created-react-app
, where importing css layers works as expected.The text was updated successfully, but these errors were encountered: