Skip to content

Using createRootRoute, Scripts, and HeadContent components adds same script multiple times #4585

@max-programming

Description

@max-programming

Which project does this relate to?

Start

Describe the bug

When using the Scripts component and defining scripts array inside createRootRoute, the same script gets added multiple times in the head tag. This also results in double scripts for hot reload inside the body

Removing the <Scripts /> component removes the entire client side functionality

Your Example Website or App

https://codesandbox.io/p/devbox/github/tanstack/router/tree/main/examples/react/start-basic?embed=1&theme=dark&file=src/routes/__root.tsx

Steps to Reproduce the Bug or Issue

  1. Go to the codesandbox url
  2. Open the devtools using the button to the right of the URL bar (in codesandbox preview)
  3. Open the head tag

Expected behavior

The script tag should be added only once, because it is defined only once

Screenshots or Videos

Image Image Image

Platform

  • Router / Start Version: 1.125.4
  • OS: Linux (Codesandbox)
  • Browser: Edge
  • Browser Version: 139.0.3405.13
  • Bundler: Vite
  • Bundler Version: 6.3.5

Additional context

I think this may be caused due to the script being added automatically by createRootRoute, HeadContent and Scripts. There must be a way to filter out duplicate scripts in order to fix this

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions