Skip to content

[test] More robust extraction off CSS sources in Flight chunks #80243

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 17 additions & 35 deletions test/e2e/app-dir/app-css/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { nextTestSetup } from 'e2e-utils'
import { check } from 'next-test-utils'

const isPPREnabledByDefault = process.env.__NEXT_EXPERIMENTAL_PPR === 'true'

describe('app dir - css', () => {
const { next, isNextDev, skipped } = nextTestSetup({
files: __dirname,
Expand Down Expand Up @@ -490,47 +488,31 @@ describe('app dir - css', () => {
// Even if it's deduped by Float, it should still only be included once in the payload.

const matches = initialHtml
.match(/\/_next\/static\/css\/.+?\.css/g)
// The same css chunk could be split into 2 RSC script
// normalize "/_next/static/css/app/\"])</script><script>self.__next_f.push([1,\"not-found.css"
// e.g.
// "/_next/static/css/app/"])</script><script>self.__next_f.push([1,"not-found.css"
// "/_next/stati"])</script><script>self.__next_f.push([1,"c/css/app/not-found.css?v=1749205445967"
// to "/_next/static/css/app/not-found.css"
.map((href) =>
href.replace('"])</script><script>self.__next_f.push([1,"', '')
)
.replaceAll('"])</script><script>self.__next_f.push([1,"', '')
.match(/\/_next\/static\/css\/.+?\.css/g)
.sort()

// Heavy on testing React implementation details.
// Assertions may change often but what needs to be checked on change is if styles are needlessly duplicated in Flight data
// There are 3 matches, one for the rendered <link> (HTML), one for Float preload (Flight) and one for the <link> inside Flight payload.
// And there is one match for the not found style
if (isPPREnabledByDefault) {
expect(matches).toEqual([
// may be split across chunks when we bump React
Comment on lines -506 to -508
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion fork was made obsolete a while ago. The expected value was equivalent in both branches.

'/_next/static/css/app/css/css-duplicate-2/layout.css',
'/_next/static/css/app/css/css-duplicate-2/layout.css',
'/_next/static/css/app/css/css-duplicate-2/layout.css',
'/_next/static/css/app/css/layout.css',
'/_next/static/css/app/css/layout.css',
'/_next/static/css/app/css/layout.css',
'/_next/static/css/app/layout.css',
'/_next/static/css/app/layout.css',
'/_next/static/css/app/layout.css',
'/_next/static/css/app/not-found.css',
])
} else {
expect(matches).toEqual([
'/_next/static/css/app/css/css-duplicate-2/layout.css',
'/_next/static/css/app/css/css-duplicate-2/layout.css',
'/_next/static/css/app/css/css-duplicate-2/layout.css',
'/_next/static/css/app/css/layout.css',
'/_next/static/css/app/css/layout.css',
'/_next/static/css/app/css/layout.css',
'/_next/static/css/app/layout.css',
'/_next/static/css/app/layout.css',
'/_next/static/css/app/layout.css',
'/_next/static/css/app/not-found.css',
])
}
expect(matches).toEqual([
'/_next/static/css/app/css/css-duplicate-2/layout.css',
'/_next/static/css/app/css/css-duplicate-2/layout.css',
'/_next/static/css/app/css/css-duplicate-2/layout.css',
'/_next/static/css/app/css/layout.css',
'/_next/static/css/app/css/layout.css',
'/_next/static/css/app/css/layout.css',
'/_next/static/css/app/layout.css',
'/_next/static/css/app/layout.css',
'/_next/static/css/app/layout.css',
'/_next/static/css/app/not-found.css',
])
}
})

Expand Down
Loading