Unverified Commit 5fa40c80 authored by Jan Nicklas's avatar Jan Nicklas Committed by GitHub

exempt data URL CSS from Pages Router global CSS restriction (#89901)

### What?

Skip the Pages Router global CSS restriction for `data:` URL imports
(similar to app router and mixed app/pages router)

### Why?

`data:text/css` should work the same no matter if pages router, app
router or mixed router usage

### How?

the validation in `crates/next-api/src/module_graph.rs` already had a
carve-out for `node_modules`. This adds the same for data URL modules.

fixes #89900

- [x] Related issues linked using `fixes #89900`
- [x] Tests added

---------
Co-authored-by: 's avatarTim Neutkens <tim@timneutkens.nl>
parent cfd5d5db
...@@ -846,9 +846,12 @@ async fn validate_pages_css_imports_individual( ...@@ -846,9 +846,12 @@ async fn validate_pages_css_imports_individual(
candidates candidates
.into_iter() .into_iter()
.map(async |issue| { .map(async |issue| {
let path = issue.module.ident().path().await?;
// We allow imports of global CSS files which are inside of `node_modules`. // We allow imports of global CSS files which are inside of `node_modules`.
// We also allow data URL CSS imports (e.g. `data:text/css,...`) since they
// are mostly tooling-generated and co-located with the importing components
Ok( Ok(
if !issue.module.ident().path().await?.is_in_node_modules() { if !path.is_in_node_modules() && !path.file_name().starts_with("data:") {
Some(issue) Some(issue)
} else { } else {
None None
...@@ -868,8 +871,9 @@ async fn validate_pages_css_imports_individual( ...@@ -868,8 +871,9 @@ async fn validate_pages_css_imports_individual(
/// Validates that the global CSS/SCSS/SASS imports are only valid imports with the following /// Validates that the global CSS/SCSS/SASS imports are only valid imports with the following
/// rules: /// rules:
/// * The import is made from a `node_modules` package /// * The import is made from a `node_modules` package
/// * The imported CSS is a `data:` URL module
/// * The import is made from a `.module.css` file /// * The import is made from a `.module.css` file
/// * The import is made from the `pages/_app.js`, or equivalent file. /// * The import is made from the `pages/_app.js`, or equivalent file
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn validate_pages_css_imports( pub async fn validate_pages_css_imports(
graph: Vc<ModuleGraph>, graph: Vc<ModuleGraph>,
......
import { nextTestSetup } from 'e2e-utils'
// CSS data urls are only supported in Turbopack
;(process.env.IS_TURBOPACK_TEST ? describe : describe.skip)(
'css-data-url-global-pages',
() => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should apply styles from data url correctly', async () => {
const browser = await next.browser('/')
const fontWeight = await browser
.elementByCss('#styled')
.getComputedCss('font-weight')
expect(fontWeight).toBe('700')
})
}
)
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
/* config options here */
}
export default nextConfig
import 'data:text/css,#styled{font-weight:700}'
export default function Home() {
return <div id="styled">This text should be bold</div>
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment