Skip to content

Commit

Permalink
always use next precedence, update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Aug 22, 2023
1 parent 89a0335 commit 6e459e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
12 changes: 1 addition & 11 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,7 @@ 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 = 'next'

return (
<link
Expand Down Expand Up @@ -614,15 +608,13 @@ export async function renderToHTMLOrFlight(
? await createComponentAndStyles({
filePath: template[1],
getComponent: template[0],
shouldPreload: true,
injectedCSS: injectedCSSWithCurrentLayout,
})
: [React.Fragment]

const [ErrorComponent, errorStyles] = error
? await createComponentAndStyles({
filePath: error[1],
shouldPreload: true,
getComponent: error[0],
injectedCSS: injectedCSSWithCurrentLayout,
})
Expand All @@ -631,7 +623,6 @@ export async function renderToHTMLOrFlight(
const [Loading, loadingStyles] = loading
? await createComponentAndStyles({
filePath: loading[1],
shouldPreload: true,
getComponent: loading[0],
injectedCSS: injectedCSSWithCurrentLayout,
})
Expand All @@ -654,7 +645,6 @@ export async function renderToHTMLOrFlight(
const [NotFound, notFoundStyles] = notFound
? await createComponentAndStyles({
filePath: notFound[1],
shouldPreload: true,
getComponent: notFound[0],
injectedCSS: injectedCSSWithCurrentLayout,
})
Expand Down
11 changes: 6 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,12 @@ 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 included together with loading with "next" precedence

expect($('link[data-precedence="next"]').length).toBe(1)

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

it('should include css imported in client template.js', async () => {
Expand Down

0 comments on commit 6e459e6

Please sign in to comment.