Skip to content

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

@jkbach

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions