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

Fix CSS imports not included in entries with a custom extension #46571

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,12 @@ export class FlightManifestPlugin {
if (entryName?.startsWith('app/')) {
// The `key` here should be the absolute file path but without extension.
// We need to replace the separator in the entry name to match the system separator.
const key = this.appDir + entryName.slice(3).replace(/\//g, sep)
const key =
this.appDir +
entryName
.slice(3)
.replace(/\//g, sep)
.replace(/\.[^\\/.]+$/, '')
entryCSSFiles[key] = files.concat(entryCSSFiles[key] || [])
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/app-dir/app-css/app/mdx/content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import styles from './content.module.css'

export const Content = () => <h1 className={styles.root}>Hello World!</h1>
3 changes: 3 additions & 0 deletions test/e2e/app-dir/app-css/app/mdx/content.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.root {
color: red;
}
3 changes: 3 additions & 0 deletions test/e2e/app-dir/app-css/app/mdx/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Content } from './content'

<Content />
12 changes: 12 additions & 0 deletions test/e2e/app-dir/app-css/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ createNextDescribe(
react: 'latest',
'react-dom': 'latest',
sass: 'latest',
'@next/mdx': 'canary',
},
},
({ next, isNextDev: isDev }) => {
Expand Down Expand Up @@ -231,6 +232,17 @@ createNextDescribe(
})
})

describe('page extensions', () => {
it('should include css imported in MDX pages', async () => {
const browser = await next.browser('/mdx')
expect(
await browser.eval(
`window.getComputedStyle(document.querySelector('h1')).color`
)
).toBe('rgb(255, 0, 0)')
})
})

if (isDev) {
describe('multiple entries', () => {
it('should only inject the same style once if used by different layers', async () => {
Expand Down
1 change: 1 addition & 0 deletions test/e2e/app-dir/app-css/mdx-components.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const useMDXComponents = (components) => components
10 changes: 9 additions & 1 deletion test/e2e/app-dir/app-css/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
module.exports = {
const mdx = require('@next/mdx')

const withMDX = mdx()

const nextConfig = {
pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
experimental: {
appDir: true,
mdxRs: true,
},
}

module.exports = withMDX(nextConfig)