Skip to content

Commit

Permalink
should not contain pages css in app dir (#44151)
Browse files Browse the repository at this point in the history
* Filter out the css chunk from `pages/`
* add indent for flight manifests in dev mode for development convenience

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
  • Loading branch information
huozhi committed Dec 19, 2022
1 parent 723311b commit ded93bf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
18 changes: 11 additions & 7 deletions packages/next/build/webpack/plugins/flight-client-entry-plugin.ts
Expand Up @@ -345,14 +345,18 @@ export class FlightClientEntryPlugin {
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH,
},
(assets: webpack.Compilation['assets']) => {
const manifest = JSON.stringify({
...serverCSSManifest,
...edgeServerCSSManifest,
__entry_css__: {
...serverCSSManifest.__entry_css__,
...edgeServerCSSManifest.__entry_css__,
const manifest = JSON.stringify(
{
...serverCSSManifest,
...edgeServerCSSManifest,
__entry_css__: {
...serverCSSManifest.__entry_css__,
...edgeServerCSSManifest.__entry_css__,
},
},
})
null,
this.dev ? 2 : undefined
)
assets[FLIGHT_SERVER_CSS_MANIFEST + '.json'] = new sources.RawSource(
manifest
) as unknown as webpack.sources.RawSource
Expand Down
6 changes: 4 additions & 2 deletions packages/next/build/webpack/plugins/flight-manifest-plugin.ts
Expand Up @@ -191,7 +191,9 @@ export class FlightManifestPlugin {
ssrNamedModuleId = `./${ssrNamedModuleId.replace(/\\/g, '/')}`

if (isCSSModule) {
const chunks = [...chunk.files].filter((f) => f.endsWith('.css'))
const chunks = [...chunk.files].filter(
(f) => !f.startsWith('static/css/pages/') && f.endsWith('.css')
)
if (!manifest[resource]) {
manifest[resource] = {
default: {
Expand Down Expand Up @@ -350,7 +352,7 @@ export class FlightManifestPlugin {
})

const file = 'server/' + FLIGHT_MANIFEST
const json = JSON.stringify(manifest)
const json = JSON.stringify(manifest, null, this.dev ? 2 : undefined)

ASYNC_CLIENT_MODULES.clear()

Expand Down
5 changes: 5 additions & 0 deletions test/e2e/app-dir/index.test.ts
Expand Up @@ -1315,6 +1315,11 @@ createNextDescribe(
).toBe('rgb(0, 0, 255)')
})

it('should not contain pages css in app dir page', async () => {
const html = await next.render('/css/css-page')
expect(html).not.toContain('/pages/_app.css')
})

if (!isDev) {
it('should not include unused css modules in the page in prod', async () => {
const browser = await next.browser('/css/css-page/unused')
Expand Down

0 comments on commit ded93bf

Please sign in to comment.