Next.js page/layout convention exports are in correct file types
Why it matters
A metadata export inside a 'use client' page is one of the most common silent failures in AI-generated Next.js code: the model writes both directives in the same file, Next.js drops the metadata without any warning, and the page ships with no <title> or <meta description>. The same applies to generateStaticParams placed in a component file — it runs nowhere. CWE-489 (Active Debug Code) maps loosely, but the practical harm is SEO blackout and broken static generation — neither of which surfaces in development because the app still renders.
Severity rationale
Medium because the failure is silent data loss (missing metadata, skipped static params) rather than a security vulnerability, but it directly harms SEO and deployment correctness.
Remediation
Split 'use client' pages that export metadata into a server wrapper and a client component. Move all convention exports to the server file.
// app/dashboard/page.tsx — server component (no 'use client')
export const metadata = { title: 'Dashboard', description: 'Your overview' }
export { default } from './dashboard-client'
// app/dashboard/dashboard-client.tsx
'use client'
import { useState } from 'react'
export default function Dashboard() {
const [count, setCount] = useState(0)
return <div>{count}</div>
}
For dynamic or revalidate found in component files under src/components/, move the export to the page.tsx, layout.tsx, or route.ts that imports the component. Config exports have no effect in component files.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Hallucinated References Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-489 — Active Debug Code: 'use client' pages with metadata are a silent misconfiguration analogous to debug/placeholder code left active
Taxons
History
- 2026-04-18·v1.0.0·Initial import from ai-slop-hallucinations·automated
- 2026-04-20·v1.1.0·Add Phase 6.1 detect-node snippet for 'use client' + route-convention misplacement·by cakleinman