Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"@next/swc": "workspace:*",
"@next/third-parties": "workspace:*",
"@opentelemetry/api": "1.4.1",
"@picocss/pico": "1.5.10",
"@svgr/webpack": "5.5.0",
"@swc/cli": "0.1.55",
"@swc/core": "1.3.55",
Expand Down
10 changes: 2 additions & 8 deletions packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,10 @@ export async function renderToHTMLOrFlight(
const createComponentAndStyles = async ({
filePath,
getComponent,
shouldPreload,
injectedCSS,
}: {
filePath: string
getComponent: () => any
shouldPreload?: boolean
injectedCSS: Set<string>
}): Promise<any> => {
const cssHrefs = getCssInlinedLinkTags(
Expand All @@ -433,11 +431,8 @@ export async function renderToHTMLOrFlight(
// During HMR, it's critical to use different `precedence` values
// for different stylesheets, so their order will be kept.
// https://github.com/facebook/react/pull/25060
const precedence = shouldPreload
? process.env.NODE_ENV === 'development'
? 'next_' + href
: 'next'
: undefined
const precedence =
process.env.NODE_ENV === 'development' ? 'next_' + href : 'next'

return (
<link
Expand Down Expand Up @@ -614,7 +609,6 @@ export async function renderToHTMLOrFlight(
? await createComponentAndStyles({
filePath: template[1],
getComponent: template[0],
shouldPreload: true,
injectedCSS: injectedCSSWithCurrentLayout,
})
: [React.Fragment]
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions test/e2e/app-dir/app-css/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ createNextDescribe(

describe('special entries', () => {
it('should include css imported in loading.js', async () => {
const html = await next.render('/loading-bug/hi')
// The link tag should be included together with loading
expect(html).toMatch(
/<link rel="stylesheet" href="(.+)\.css(\?v=\d+)?"\/><h2>Loading...<\/h2>/
)
const $ = await next.render$('/loading-bug/hi')
// The link tag should be hoist into head with precedence properties
expect($('head link[data-precedence]').length).toBe(2)

expect($('body h2').text()).toBe('Loading...')
})

it('should include css imported in client template.js', async () => {
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/app-dir/not-found/css-precedence/app/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Layout({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
23 changes: 23 additions & 0 deletions test/e2e/app-dir/not-found/css-precedence/app/not-found.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use client'

import { Button } from '../components/button/button'
import { useRouter } from 'next/navigation'

function NotFound() {
const router = useRouter()
return (
<div>
<h1>404 - Page Not Found</h1>
<Button
id="go-to-index"
onClick={() => {
router.push('/')
}}
>
Home
</Button>
</div>
)
}

export default NotFound
20 changes: 20 additions & 0 deletions test/e2e/app-dir/not-found/css-precedence/app/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use client'

import { useRouter } from 'next/navigation'
import { Button } from '../components/button/button'

export default function Page() {
const router = useRouter()
return (
<>
<Button
id="go-to-404"
onClick={() => {
router.push('/404')
}}
>
Not Found
</Button>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use client'

import styles from './button.module.css'
import React from 'react'

export const Button = ({ children, ...props }) => {
return (
<button {...props} className={styles.button}>
{children}
</button>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.button {
border: 1px solid #ccc;
border-radius: 4px;
background: rgb(0, 128, 0);
color: #fff;
padding: 8px 16px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use client'

import { Button } from './button/button'
import { useRouter } from 'next/navigation'

export default function Navigate404Section() {
const router = useRouter()
return (
<p>
<Button
id="go-to-navigate-404"
onClick={() => {
router.push('/navigate-404')
}}
>
Go to /navigate-404
</Button>
</p>
)
}
43 changes: 43 additions & 0 deletions test/e2e/app-dir/not-found/css-precedence/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { createNextDescribe } from 'e2e-utils'
import { check } from 'next-test-utils'

createNextDescribe(
'app dir css',
{
files: __dirname,
skipDeployment: true,
dependencies: {
sass: 'latest',
},
},
({ next }) => {
it('should load css while navigation between not-found and page', async () => {
const browser = await next.browser('/')
await check(
async () =>
await browser.eval(
`window.getComputedStyle(document.querySelector('#go-to-404')).backgroundColor`
),
'rgb(0, 128, 0)'
)
await browser.elementByCss('#go-to-404').click()
await browser.waitForElementByCss('#go-to-index')
await check(
async () =>
await browser.eval(
`window.getComputedStyle(document.querySelector('#go-to-index')).backgroundColor`
),
'rgb(0, 128, 0)'
)
await browser.elementByCss('#go-to-index').click()
await browser.waitForElementByCss('#go-to-404')
await check(
async () =>
await browser.eval(
`window.getComputedStyle(document.querySelector('#go-to-404')).backgroundColor`
),
'rgb(0, 128, 0)'
)
})
}
)