Unverified Commit 2c592a9f authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

[error overlay] missing html tags error should be blocking (#75839)

### What

missing html tags error should always show the overlay when exist, and
the dev indicator count should be 1 since we require users to resolve
this first then React can hydrate the right content. After this they can
move to others.

Since the indicator count is not covered in old test, I add a new test
for new overlay rn, later we can merge them

#### Observed 

* Currently it requires to click the indicator to show the error
* The indicator count shows 2

#### Expected

* The overlay should pop up as it's a runtime error
* The indicator count shows 1
parent ab6aeab5
......@@ -43,14 +43,16 @@ export function ErrorOverlay({
if (!!state.rootLayoutMissingTags?.length) {
return (
<RootLayoutMissingTagsError
missingTags={state.rootLayoutMissingTags}
{...commonProps}
// This is a runtime error, forcedly display error overlay
rendered
missingTags={state.rootLayoutMissingTags}
/>
)
}
if (state.buildError !== null) {
return <BuildError message={state.buildError} {...commonProps} />
return <BuildError {...commonProps} message={state.buildError} />
}
// No Runtime Errors.
......@@ -64,12 +66,12 @@ export function ErrorOverlay({
return (
<Errors
{...commonProps}
debugInfo={state.debugInfo}
readyErrors={readyErrors}
onClose={() => {
setIsErrorOverlayOpen(false)
}}
{...commonProps}
/>
)
}
......@@ -30,8 +30,7 @@ function getErrorSignature(ev: SupportedErrorEvent): string {
break
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _ = event satisfies never
event satisfies never
return ''
}
......@@ -109,7 +108,7 @@ export function useErrorHook({
// missing tags won't be dismissed until resolved, the
// total number of errors may be fixed to their length.
totalErrorCount: rootLayoutMissingTags?.length
? rootLayoutMissingTags.length
? 1
: !!buildError
? 1
: readyErrors.length,
......
export default function Layout({ children }) {
return <body>{children}</body>
}
export default function Page() {
return <p>hello world</p>
}
import { nextTestSetup } from 'e2e-utils'
import {
assertHasRedbox,
assertNoRedbox,
getRedboxDescription,
getToastErrorCount,
hasErrorToast,
retry,
} from 'next-test-utils'
import { outdent } from 'outdent'
// TODO: merge with test/development/app-dir/missing-required-html-tags/index.test.ts
// once new overlay is stable
describe('app-dir - missing required html tags', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should display correct error count in dev indicator', async () => {
const browser = await next.browser('/')
retry(async () => {
expect(await hasErrorToast(browser)).toBe(true)
})
// Dev indicator should show 1 error
expect(await getToastErrorCount(browser)).toBe(1)
await assertHasRedbox(browser)
await retry(async () => {
expect(await getRedboxDescription(browser)).toEqual(outdent`
The following tags are missing in the Root Layout: <html>.
Read more at https://nextjs.org/docs/messages/missing-root-layout-tags
`)
})
await next.patchFile('app/layout.js', (code) =>
code.replace(
'return <body>{children}</body>',
'return <html><body>{children}</body></html>'
)
)
await assertNoRedbox(browser)
expect(await browser.elementByCss('p').text()).toBe('hello world')
})
})
/**
* @type {import('next').NextConfig}
*/
module.exports = {
experimental: {
newDevOverlay: true,
},
}
......@@ -64,7 +64,7 @@ describe('app-dir - missing required html tags', () => {
)
await openRedbox(browser)
// TODO(NDX-768): Should show "missing tags" error
expect(await getRedboxDescription(browser)).toMatchInlineSnapshot(`
"In HTML, <p> cannot be a child of <#document>.
This will cause a hydration error."
......
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