-
Notifications
You must be signed in to change notification settings - Fork 27.6k
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
Mismatch of names in grid-template-areas and grid-area across different css modules with --turbo #64509
Comments
I'm experiencing the same issue. I've got a grid container in the header.module.scss file: and the same grid-area name in the mega-menu.module.scss file: This completely breaks the grid and layout |
Also experiencing this, and it's a pretty big blocker. I work in a turborepo monorepo. Decided to try turbopack on a new Next.js app I was working on, and one of my shared components uses Think I'll just exclude turbopack/ |
I'm not entirely sure this is solely due to an issue in turbopack. It might as well be due to lightningcss doing something weird under-the-hood. Fortunately, there's a work-around for those of you who want to keep using CSS modules with Using turbopack in a nextjs project, this "setup" has worked for me: /* layout.module.css */
.layout {
grid-template-areas:
'header header header header'
'nav main main main'
'nav main main main'
'footer footer footer footer;
}
.header {
grid-area: header;
}
.nav {
grid-area: nav;
}
.main {
grid-area: main;
} /* header.module.css */
.header {
composes: header from './layout.module.css';
*/ ... */
} /* nav.module.css */
.nav {
composes: nav from './layout.module.css';
*/ ... */
} /* main.module.css */
.main {
composes: main from './layout.module.css';
*/ ... */
} And so on... |
The reason these get prefixed is that we're using LightningCSS for processing CSS which is smarter with CSS Modules, it also ensures grid names don't conflict as per the documentation: https://lightningcss.dev/css-modules.html#css-grid Webpack's CSS modules handling doesn't do this (but it probably should). That's what is causing the mismatch as you're upgrading. My recommendation would be to restructure the grid templates to be defined in global CSS instead of CSS Modules. |
Global styles are good for general layout of whole site which would be used for every page. |
CSS Modules CSS rules are intended to be scoped, this includes e.g. CSS animations by default. The only reason grid wasn't prefixed before is that it's a newer CSS standard and webpack's CSS handling didn't have an implementation for it, whereas the more modern LightningCSS compiler we use in Turbopack does support it. In the case that you're describing it's basically leaking grid names making them "global" even though they're defined in a CSS Module. Basically previously that was a bug with the webpack handling. |
Your second explanation makes a lot more sense than the link in the lightningcss (which sounded like mumbo jumbo). |
## What? Requires vercel/turborepo#8176 first. Grid scoping in CSS Modules is disabled because Webpack CSS Modules handling doesn't handle grid currently. This ensures moving from Webpack to Turbopack doesn't have mismatching behavior around CSS grid. Fixes #64509 Fixes #63758 Fixes PACK-2976 <!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Adding or Updating Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # -->
Looks like this will be sorted in an upcoming release? @timneutkens thanks for sorting this, appreciated ❤️ |
Yes indeed! I ended up talking to Devon (maintainer of Lightning CSS about it) and we agreed that having a way towards compatibility with webpack's CSS modules handling would be beneficial for people migrating to Lightning CSS and for Turbopack as everyone using it is coming from webpack's CSS modules handling right now 👍 More info here: https://x.com/timneutkens/status/1791586981337604443 Overall I still believe scoping grid is the right thing to do but having compatibility is more important 🙏 |
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
## What? Requires vercel/turborepo#8176 first. Grid scoping in CSS Modules is disabled because Webpack CSS Modules handling doesn't handle grid currently. This ensures moving from Webpack to Turbopack doesn't have mismatching behavior around CSS grid. Fixes #64509 Fixes #63758 Fixes PACK-2976 <!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Adding or Updating Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # -->
Link to the code that reproduces this issue
https://github.com/Arctomachine/next-grid-template-areas-bug
To Reproduce
Current vs. Expected behavior
Expected: areas have same name in grid and cards
Current: area names mismatch. Grid will append its module name to grid-template-area, but card will append its module name to grid-area. Since they are different names, browser will not put cards into grid correctly.
Example of area name in grid:
![image](https://private-user-images.githubusercontent.com/29041820/322555135-32dcb2e9-65a3-4235-bc78-d7e2987d917c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0ODU3NDMsIm5iZiI6MTczOTQ4NTQ0MywicGF0aCI6Ii8yOTA0MTgyMC8zMjI1NTUxMzUtMzJkY2IyZTktNjVhMy00MjM1LWJjNzgtZDdlMjk4N2Q5MTdjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEzVDIyMjQwM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTA1NGZhNWUxNTVlMTJiNDM3Y2M3NTgzY2M0MzQxMDM3YmYxYTdiZmI5ODI4YmM4YzlhNzBmNWY5OGFhZDljMjUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.AA9gjfDZeEtxfnuODGn0f6Vbte9Yymstz-_l_G9vqy4)
![image](https://private-user-images.githubusercontent.com/29041820/322555264-0c7c6ced-9a2f-42d5-8583-f5278ee0a028.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0ODU3NDMsIm5iZiI6MTczOTQ4NTQ0MywicGF0aCI6Ii8yOTA0MTgyMC8zMjI1NTUyNjQtMGM3YzZjZWQtOWEyZi00MmQ1LTg1ODMtZjUyNzhlZTBhMDI4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEzVDIyMjQwM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTExZjVmNTIxNjhiZjUzOTgzZjE2ZWI4ZmNiNmVmNmVkODBlZGI4Y2VmMDg0M2YwNWUwZWY3YjRmMGMzMjkyZDMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.C3F76esMOcowLQkJQuY86bqNInay9970GjIMNKimC28)
And in card:
Provide environment information
Which area(s) are affected? (Select all that apply)
Turbopack (--turbo)
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
Only happens for turbopack in dev mode. Production build is not affected
PACK-2976
The text was updated successfully, but these errors were encountered: