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 not being bundled in app dir #45787

Merged
merged 33 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ff6e824
fix css not bundled
shuding Feb 10, 2023
0fb12db
Merge branch 'canary' into shu/7yrw
shuding Feb 16, 2023
7531460
update test
shuding Feb 17, 2023
8891f78
Merge branch 'canary' into shu/7yrw
shuding Feb 17, 2023
3ac673a
Merge branch 'canary' into shu/7yrw
kodiakhq[bot] Feb 17, 2023
30ebeb6
Merge branch 'canary' into shu/7yrw
shuding Feb 17, 2023
a35c336
Merge branch 'canary' into shu/7yrw
shuding Feb 17, 2023
5fcb1ac
Merge branch 'canary' into shu/7yrw
shuding Feb 17, 2023
9bbdf5f
Merge branch 'canary' into shu/7yrw
kodiakhq[bot] Feb 18, 2023
7a00f42
Merge branch 'canary' into shu/7yrw
ijjk Feb 18, 2023
4776a6c
Merge branch 'canary' into shu/7yrw
kodiakhq[bot] Feb 18, 2023
9c278c1
Merge branch 'canary' into shu/7yrw
kodiakhq[bot] Feb 18, 2023
75dc81e
Merge branch 'canary' into shu/7yrw
kodiakhq[bot] Feb 18, 2023
02d46b4
Merge branch 'canary' into shu/7yrw
kodiakhq[bot] Feb 18, 2023
f05baec
Merge branch 'canary' into shu/7yrw
kodiakhq[bot] Feb 18, 2023
c7e9ab6
Merge branch 'canary' into shu/7yrw
kodiakhq[bot] Feb 18, 2023
7af6e69
adjust timeout
shuding Feb 20, 2023
d75a90a
Merge branch 'canary' into shu/7yrw
shuding Feb 20, 2023
0425001
merge canary
shuding Feb 27, 2023
84612d4
udpate test
shuding Feb 27, 2023
1a7e7d7
add pre-render
shuding Feb 27, 2023
3b3e3fc
update test
ijjk Feb 27, 2023
18c3d5e
use check
ijjk Feb 28, 2023
fe19619
Merge branch 'canary' into shu/7yrw
ijjk Feb 28, 2023
e1ac3a3
update check usage
ijjk Feb 28, 2023
50d90f6
Merge branch 'canary' into shu/7yrw
shuding Mar 4, 2023
48ffc52
Merge branch 'canary' into shu/7yrw
shuding Mar 5, 2023
6798b2c
add debug code
shuding Mar 6, 2023
bfb8c37
attach error
shuding Mar 6, 2023
ed9dd66
Merge branch 'canary' into shu/7yrw
shuding Mar 10, 2023
1f7f43c
Merge branch 'canary' into shu/7yrw
shuding Mar 16, 2023
236ec11
Merge branch 'canary' into shu/7yrw
shuding Mar 17, 2023
8536910
prefetch target page
shuding Mar 17, 2023
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 @@ -22,12 +22,11 @@ export default async function transformSource(this: any): Promise<string> {

const requests = modules as string[]
const code = requests
// Filter out css files on the server
// Filter out CSS files in the SSR compilation
.filter((request) => (isServer ? !regexCSS.test(request) : true))
.map((request) =>
regexCSS.test(request)
? `(() => import(/* webpackMode: "lazy" */ ${JSON.stringify(request)}))`
: `import(/* webpackMode: "eager" */ ${JSON.stringify(request)})`
.map(
(request) =>
`import(/* webpackMode: "eager" */ ${JSON.stringify(request)})`
)
.join(';\n')

Expand Down
19 changes: 11 additions & 8 deletions packages/next/src/server/load-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,18 @@ export async function loadDefaultErrorComponents(distDir: string) {
}
}

async function loadManifest<T>(manifestPath: string, attempts = 1): Promise<T> {
try {
return require(manifestPath)
} catch (err) {
if (attempts >= 3) {
throw err
/**
* Load manifest file with retries, defaults to 3 attempts.
*/
async function loadManifest<T>(manifestPath: string, attempts = 3): Promise<T> {
while (true) {
try {
return require(manifestPath)
} catch (err) {
attempts--
if (attempts <= 0) throw err
await new Promise((resolve) => setTimeout(resolve, 100))
}
await new Promise((resolve) => setTimeout(resolve, 100))
return loadManifest(manifestPath, attempts + 1)
}
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

12 changes: 0 additions & 12 deletions test/e2e/app-dir/app-css/app/css/css-page/unused/page.js

This file was deleted.

4 changes: 0 additions & 4 deletions test/e2e/app-dir/app-css/app/css/css-page/unused/styles.js

This file was deleted.

This file was deleted.

34 changes: 11 additions & 23 deletions test/e2e/app-dir/app-css/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,6 @@ createNextDescribe(
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')
expect(
await browser.eval(
`[...document.styleSheets].some(({ rules }) => [...rules].some(rule => rule.selectorText.includes('this_should_not_be_included')))`
)
).toBe(false)
})

it('should not include unused css modules in nested pages in prod', async () => {
const browser = await next.browser(
'/css/css-page/unused-nested/inner'
)
expect(
await browser.eval(
`[...document.styleSheets].some(({ rules }) => [...rules].some(rule => rule.selectorText.includes('this_should_not_be_included_in_inner_path')))`
)
).toBe(false)
})
}
})

describe('client layouts', () => {
Expand Down Expand Up @@ -221,6 +199,16 @@ createNextDescribe(
})
})

describe('chunks', () => {
it('should bundle css resources into chunks', async () => {
const html = await next.render('/dashboard')
expect(
[...html.matchAll(/<link rel="stylesheet" href="[^.]+\.css"/g)]
.length
).toBe(3)
})
})

if (isDev) {
describe('multiple entries', () => {
it('should only inject the same style once if used by different layers', async () => {
Expand All @@ -240,7 +228,7 @@ createNextDescribe(
// Even if it's deduped by Float, it should still only be included once in the payload.
// There are two matches, one for the rendered <link> and one for the flight data.
expect(
initialHtml.match(/duplicate-2_style_module_css\.css/g).length
initialHtml.match(/css-duplicate-2\/layout\.css/g).length
).toBe(2)
})

Expand Down