Skip to content

Conversation

@malkovitc
Copy link

Summary

Add development-time warning when invalid HTML elements are used as children of the next/head component. This helps developers identify issues early instead of seeing confusing "next-head-count is missing" errors at runtime.

Problem

When developers accidentally put invalid elements like <div> inside <Head>, they get a cryptic "next-head-count is missing" error that doesn't help identify the root cause.

Solution

Add validation in development mode that warns about invalid children with a clear message:

Warning: <div> is not a valid child of next/head. 
Valid children are: title, meta, link, script, style, base, noscript.
See: https://nextjs.org/docs/messages/invalid-head-child

Changes

  • Add VALID_HEAD_TAGS constant
  • Add warnOnce() call for invalid element types in development
  • Create /errors/invalid-head-child.mdx documentation page

How tested

Manual testing with invalid Head children in development mode.

Fixes #20924

Add development-time warning when invalid HTML elements are used as
children of the next/head component. This helps developers identify
issues early instead of seeing confusing "next-head-count is missing"
errors at runtime.

Valid children are: title, meta, link, script, style, base, noscript.

Changes:
- Add VALID_HEAD_TAGS constant
- Add warnOnce() call for invalid element types in development
- Create /errors/invalid-head-child.mdx documentation page

Fixes vercel#20924
@nextjs-bot nextjs-bot added Documentation Related to Next.js' official documentation. type: next labels Dec 16, 2025
@nextjs-bot
Copy link
Collaborator

Allow CI Workflow Run

  • approve CI run for commit: f78a1d6

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

1 similar comment
@nextjs-bot
Copy link
Collaborator

Allow CI Workflow Run

  • approve CI run for commit: f78a1d6

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Related to Next.js' official documentation. type: next

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misleading "next-head-count is missing" error for invalid head tags

2 participants