Skip to content

fix(useHead): avoid undefined document.title without a title - #122

Open
dajiaohuang wants to merge 1 commit into
0no-co:mainfrom
dajiaohuang:fix/usehead-undefined-title
Open

dajiaohuang wants to merge 1 commit into
0no-co:mainfrom
dajiaohuang:fix/usehead-undefined-title

Conversation

@dajiaohuang

@dajiaohuang dajiaohuang commented Oct 20, 2026 •

Copy link
Copy Markdown

Summary

useHead queued its title on mount even when no title was provided, and the dispatcher always wrote the first queued title to document.title. A metas-only useHead therefore set document.title to the literal string "undefined", and a metas-only child could overwrite a title set by useTitle in a parent.

  • Only queue a title from useHead when one is provided.
  • Only assign document.title while a title or template is queued, so a metas-only render leaves an existing/static title alone.

Reproduction

const Child = () => {
  useHead({ metas: [{ name: 'description', content: 'x' }] });
  return null;
};

const App = () => {
  useTitle('Parent title');
  return <Child />;
};

Before this change document.title became "undefined" after the first batch; with the change it stays "Parent title".

Validation

  • Added useHead regression tests for a metas-only render and a metas-only child under useTitle.
  • Added a useMeta-only regression test for the dispatcher title handling.
  • All three new regression tests fail against the base source and pass with this change.
  • pnpm test -- --run: 39 tests passed.
  • pnpm build: passed.

The changeset is a patch for hoofd.

useHead always queued its title, even when none was passed, and the dispatcher rendered that undefined queue entry as the literal string "undefined". A metas-only useHead could therefore replace the document title, including a title managed by useTitle in a parent component.

Only queue a title from useHead when one is provided, and only assign document.title while a title or template is queued. Add regression tests for metas-only useHead and useMeta.
@changeset-bot

changeset-bot Bot commented Oct 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8b14226

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
hoofd Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant