Skip to content

script and link tags are not deduplicated (compared to react-helmet-async) #666

Closed

Description

@adbayb

Environment

Node.js: v24.13.0.
Unhead/react: v2.1.6.

Reproduction

Sandbox: https://stackblitz.com/edit/github-5hqsxyid-da1rkaug?file=src%2FApp.tsx

Describe the bug

I’m migrating from react-helmet-async to @unhead/react and noticed a difference in deduplication behavior.

In @unhead/react, script and link tags with the same attributes (src, href, as, rel) are not deduplicated. However, title and meta (e.g., description) are correctly deduplicated.

With react-helmet-async, identical script and link tags are properly deduplicated (only one instance is injected into the DOM).

The issue reproduces:

  • In CSR
  • In SSR

Thank you!

Expected behavior

When multiple script or link tags are defined with identical attributes (e.g., src, href, as, rel, async, defer, ...), only a single instance should be rendered in the DOM, similar to the behavior of react-helmet-async.

Actual behavior

Duplicate script and link elements are rendered in the DOM, even when all identifying attributes match.

Additional context

This creates inconsistencies when migrating from react-helmet-async, where deduplication works as expected for these tags.

Here are some screenshots showcasing the actual results (taken from the sandbox):

Image Image

Logs

Activity

  1. added
    bug
    on Feb 25, 2026
  2. added 4 commits that reference this issue on Feb 25, 2026
    eddb5a3
    3704c23
    0eea994
    5c0b293
  3. harlan-zw commented on Feb 25, 2026

    @harlan-zw
    Collaborator

    Thanks for the detailed issue. So Unhead out of the box is meant to dedupe any identical tags (unless a key is provided). It seems like there's a SSR bug in that it doesn't check this logic within the tag render group, so for SSR shell, you run into the issue you've outlined.

    It should be fixed in v2.1.7 https://stackblitz.com/edit/github-5hqsxyid-2tmhihxq?file=package.json

  4. added a commit that references this issue on Feb 25, 2026
    1c25833
  5. adbayb commented on Feb 25, 2026

    @adbayb
    Author

    Thank you @harlan-zw, it works like a charm 👍 .

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