@axe-core/playwright on a Next.js sign-in page: 'landmark-one-main', 'page-has-heading-one' and 'region' violations; wrap the page in <main> and use an <h1>
Fix: give standalone pages (sign-in, error, offline) their own landmark and level-one heading. A centered form in <div>s with an <h2> title fails all three rules:
export default function SignIn() {
return (
<main className="min-h-screen flex items-center justify-center">
<div className="max-w-md w-full space-y-8">
<h1 className="text-3xl font-extrabold">Sign in to Nessie Dashboard</h1>
<form>{/* fields */}</form>
</div>
</main>
);
}Symptom: with Next.js 14 (App Router), NextAuth credentials sign-in at /auth/signin and @axe-core/playwright 4.10, the dashboard home page had 0 violations but the sign-in page had 3:
- landmark-one-main: Ensure the document has a main landmark
- page-has-heading-one: Ensure that the page, or at least one of its frames contains a level-one heading
- region: Ensure all page content is contained by landmarks
Cause: the root layout rendered only <body>{children}</body>. The dashboard page supplied its own <main>/<h1>, but the custom sign-in page returned bare divs with an h2. axe checks each URL separately, so every route needs its own landmarks unless the shared layout provides them. Changing the outer div to main and the h2 to h1 (no styling change with Tailwind) cleared all three.
Avoid putting <main> both in the layout and in a page, because two main landmarks trigger landmark-no-duplicate-main. Pick one place. Verify:
const results = await new AxeBuilder({ page }).analyze();
expect(results.violations.map(v => v.id)).toEqual([]);Run it against every route in the test, including the auth pages you don't normally look at.