Unverified Commit ded93bf6 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

should not contain pages css in app dir (#44151)

* 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)
parent 723311bd
...@@ -345,14 +345,18 @@ export class FlightClientEntryPlugin { ...@@ -345,14 +345,18 @@ export class FlightClientEntryPlugin {
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH, stage: webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH,
}, },
(assets: webpack.Compilation['assets']) => { (assets: webpack.Compilation['assets']) => {
const manifest = JSON.stringify({ const manifest = JSON.stringify(
...serverCSSManifest, {
...edgeServerCSSManifest, ...serverCSSManifest,
__entry_css__: { ...edgeServerCSSManifest,
...serverCSSManifest.__entry_css__, __entry_css__: {
...edgeServerCSSManifest.__entry_css__, ...serverCSSManifest.__entry_css__,
...edgeServerCSSManifest.__entry_css__,
},
}, },
}) null,
this.dev ? 2 : undefined
)
assets[FLIGHT_SERVER_CSS_MANIFEST + '.json'] = new sources.RawSource( assets[FLIGHT_SERVER_CSS_MANIFEST + '.json'] = new sources.RawSource(
manifest manifest
) as unknown as webpack.sources.RawSource ) as unknown as webpack.sources.RawSource
......
...@@ -191,7 +191,9 @@ export class FlightManifestPlugin { ...@@ -191,7 +191,9 @@ export class FlightManifestPlugin {
ssrNamedModuleId = `./${ssrNamedModuleId.replace(/\\/g, '/')}` ssrNamedModuleId = `./${ssrNamedModuleId.replace(/\\/g, '/')}`
if (isCSSModule) { 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]) { if (!manifest[resource]) {
manifest[resource] = { manifest[resource] = {
default: { default: {
...@@ -350,7 +352,7 @@ export class FlightManifestPlugin { ...@@ -350,7 +352,7 @@ export class FlightManifestPlugin {
}) })
const file = 'server/' + FLIGHT_MANIFEST const file = 'server/' + FLIGHT_MANIFEST
const json = JSON.stringify(manifest) const json = JSON.stringify(manifest, null, this.dev ? 2 : undefined)
ASYNC_CLIENT_MODULES.clear() ASYNC_CLIENT_MODULES.clear()
......
...@@ -1315,6 +1315,11 @@ createNextDescribe( ...@@ -1315,6 +1315,11 @@ createNextDescribe(
).toBe('rgb(0, 0, 255)') ).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) { if (!isDev) {
it('should not include unused css modules in the page in prod', async () => { it('should not include unused css modules in the page in prod', async () => {
const browser = await next.browser('/css/css-page/unused') const browser = await next.browser('/css/css-page/unused')
......
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