TanStack Start and React 19 Metadata Tags #3050
Send to my agentWhich 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.
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.
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
Also this weirdly enough resolved an issue where a ternary wasn't being evaluated properly on the client after hydration.
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.tsxrenders link tags as well.can you please provide a complete minimal example? do you render the Meta component from start ?
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.
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>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.SeanCassiere added labelsinformation needed
SeanCassiere added labelsstart
This needs investigation into how React 19 moves elements into the
headand how Start performs deduping and the removal of stale tags.is this still relevant with the latest version? please note that
<Meta>was renamed to<HeadContent>and is to be imported from@tanstack/router@schiller-manuel ill give it ago and check. will update in a few days.
@SoloReverse did you check it?
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.
In the server-rendered markup, the title is prepended, but the root component's title is not doubled.
3️⃣ In the third scenario, the title is completely ignored and fails to be hoisted into the head.
The same applies to the server-rendered markup.
Sign in to join this conversation.
Commenting this line out from start/client/Meta.tsx
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.