Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Merged
merged 2 commits into from
Feb 9, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -64,12 +66,12 @@ export function ErrorOverlay({

return (
<Errors
{...commonProps}
debugInfo={state.debugInfo}
readyErrors={readyErrors}
onClose={() => {
setIsErrorOverlayOpen(false)
}}
{...commonProps}
/>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

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

TypeScript already checks switch exhaustiveness. No need for this pattern and unused return statements: #75854

return ''
}

Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Layout({ children }) {
return <body>{children}</body>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return <p>hello world</p>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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')
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @type {import('next').NextConfig}
*/
module.exports = {
experimental: {
newDevOverlay: true,
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('app-dir - missing required html tags', () => {
)

await openRedbox(browser)
// TODO(NDX-768): Should show "missing tags" error
Copy link
Member

Choose a reason for hiding this comment

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

Why was this removed? No assertion was added that shows this was fixed. Underlying issue was also not marked as done.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops messed with another task in a different pr, this one should be kept.

Copy link
Member

Choose a reason for hiding this comment

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

Will be restored in #75796


expect(await getRedboxDescription(browser)).toMatchInlineSnapshot(`
"In HTML, <p> cannot be a child of <#document>.
This will cause a hydration error."
Expand Down
Loading