Skip to content

(React) Title and other metadata are not unset when component unmounts #558

Closed

Description

@jkbach

Environment

Issue is observed in both of the following environments:

Stackblitz env:

> node --version
v20.19.1

Vite: v7.0.1
React: 19.1.0

My env:

Node v22.8
React 18.2.0
Vite 5.1.0

Reproduction

https://stackblitz.com/edit/vitejs-vite-ijas5txg?file=src%2FApp.tsx

Repro steps:

  1. The app is initially rendering the <Page2> element, which does not set any <meta> tags.
  2. Observe the <head> of the rendered app. Observe that the title tag is set to the fallback title "Example fallback" and there is a description <meta> tag with content "some description" as configured in the init parameter of the createHead function. (Expected)
  3. Click the button labeled "Page 1" to mount the <Page1> component. Observe that the title and description are updated based on the values set in the useHead hook in the <Page1> component. (Expected).
  4. Click the button "Page 2" to unmount the <Page1> component and remount the <Page2> component.
  5. Observe that the meta tags are still displaying the Page1 values, even though the <Page1> component was unmounted. (Unexpected behavior)

Expected behavior:

The <meta> values configured by the <Page1> component are removed when the component is unmounted, and the values from the init parameter of the createHead function are added again.

Describe the bug

When a component unmounts, it doesn't unset <meta> tags that were configured in that component, nor are the <meta> tags reset to the values in the init parameter of the createHead function.

Additional context

I'm new to this library, so I might be completely misunderstanding the expected behavior here. Thanks for your help!

Logs

Activity

  1. added
    bug
    on Jul 3, 2025
  2. harlan-zw commented on Jul 6, 2025

    @harlan-zw
    Collaborator

    Thanks for this detailed issue. This was an Unhead bug, I've pushed up a fix in v2.0.12 which looks to fix it here https://stackblitz.com/edit/vitejs-vite-nqsjcyrq?file=package.json

    LMK if you have any other ikssues

  3. petrovmiroslav commented on Feb 17, 2026

    @petrovmiroslav
  4. added 4 commits that reference this issue on Feb 24, 2026
    8b5f06e
    81b9f10
    7ea7bd5
    50ffe37
  5. harlan-zw commented on Feb 24, 2026

    @harlan-zw
    Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions