Skip to content
Source
Sign inSign up
TanStack/router

TanStack Start and React 19 Metadata Tags #3050

Send to my agent
OpenSoloReverse(GitHub profile, opens in a new tab) opened this issue 11 comments

Which project does this relate to?

Start

Describe the bug

The issue is simple. I am attempting to use React 19's metadata tags to manage my metadata, but each components is being rendered twice on the DOM, even after adding a key to it. This is in Development and Production.

Image

I am sure this is SSR issue. Also If someone someone has a solution to dynamically render head meta elements using the router directly that would be great, (I would like the loader context to fetch the updated context not the initial state). My current solution is straight up DOM manipulation.

Your Example Website or App

edit: tanstack-react19 Repo

Steps to Reproduce the Bug or Issue

Use any tag inside a react component.

Image

Expected behavior

Rendering a single tag in the head

Screenshots or Videos

No response

Platform

  • OS: macOS / iOS
  • Browser: Chrome and Safari

Additional context

No response

  1. Commenting this line out from start/client/Meta.tsx

        <>
          {meta.map((asset, i) => (
            <Asset {...asset} key={`tsr-meta-${JSON.stringify(asset)}`} />
          ))}
          <>

    Seems to fix the problem, however. I don't know why and why is it getting the meta tag from react as opposed to the router.

  2. Also this weirdly enough resolved an issue where a ternary wasn't being evaluated properly on the client after hydration.

    Image

    The client would render the dark mode image due to an undefined context value on the server, but later would result in a value on the client that goes ignored, not changing the image to align with the theme. This fixed that issue, but results in a horrible first paint. that flashes unstyled content which I guess is expected if Asset.tsx renders link tags as well.

  3. can you please provide a complete minimal example? do you render the Meta component from start ?

  4. can you please provide a complete minimal example? do you render the Meta component from start ?

    Here's the codebase I am working with atm. https://github.com/SoloReverse/tanstack-react19

    edit: and No I am rendering the meta component in the header component using react 19's tag. Tags rendered by the createRootRoute are not affected.

  5. but you are rendering the <Meta> component in the root route. this does not work well (as you discovered ) with some <meta> rendered elsewhere. we need to see if it is possible to allow both.

    the obvious solution right now is not using <meta> but to provide the meta information via the route definition.

    alternatively, don't use <Meta>

  6. Removing the <Meta/> just stops the whole app from rendering, I think in start its responsible for a lot of stuff. Its's fine for now, but I think support for React's 19 own <meta/> is necessary in the future.

  7. SeanCassiere added labelsinformation needed

  8. SeanCassiere added labelsstart

  9. This needs investigation into how React 19 moves elements into the head and how Start performs deduping and the removal of stale tags.

  10. is this still relevant with the latest version? please note that <Meta> was renamed to <HeadContent> and is to be imported from @tanstack/router

  11. @schiller-manuel ill give it ago and check. will update in a few days.

  12. Pardon for hijacking the discussion. I figured out three different ways to set titles based on dynamically fetched results https://github.com/TanStack/router/discussions/1056#discussioncomment-12470124 with start-basic on 1.125.0 on https://github.com/yjoer/start-basic-meta/. Deduplication works as expected to override the root component's title when the new title is defined through route definitions. However, title updates did not work when using React 19 document metadata in either the component tied directly to the route definition or in a nested, suspended component.

    ✅ Route definition https://github.com/yjoer/start-basic-meta/commit/b8452e251b66c9bbb6ce5e45c77e013e2212f18f ❎ React 19 document metadata https://github.com/yjoer/start-basic-meta/commit/1ff74726983f3fc3b3438ef2f131a1ae7533e8b0 ❎ Suspended components https://github.com/yjoer/start-basic-meta/commit/74ba1d1a5c7d82a777f62f83def7dd704a8f6b83

    2️⃣ In the second scenario, the title is prepended while the root component's title is doubled in the DOM. Image

    In the server-rendered markup, the title is prepended, but the root component's title is not doubled. Image

    3️⃣ In the third scenario, the title is completely ignored and fails to be hoisted into the head. Image

    The same applies to the server-rendered markup. Image

Sign in to join this conversation.