Bug: Hoisted <title> containing more than 1 JSX child will contain nothing
React version: 19.1.0
Steps To Reproduce
Add a <title> attribute with more than than 1 JSX child e.g.
<title>{projectName} | Projects</title>
or
<title>{projectName}{section}</title>
Link to code example: https://stackblitz.com/edit/vitejs-vite-nch86hgd?file=src%2FApp.tsx
The current behavior
The title that gets hoisted to <head> is empty (i.e. <title></title>), with no console errors
The expected behavior
The children are concatenated, e.g. <title>My Project | Projects</title>
You can of course work around the issue by ensuring there is only one child
<title>{projectName + " | Projects"}</title>
This is documented behavior: https://react.dev/reference/react-dom/components/title
We should have a warning though.
This behavior makes sense from a spec-compliance and design consistency perspective.
That said, I also agree that a warning would be helpful — this is easy to overlook, and the browser silently ignores the title when multiple children are passed.
You’re right — when you write:
It ends up rendering multiple children inside
✅ The workaround you mentioned is the best practice:
or using a template literal:
This ensures only one string child is passed, and works as expected.
I found that there was an existing warning for this, but only for SSR. I've applied the same warning to the client: #33349
🐛 Bug:
Summary: When using multiple JSX children inside a
⸻
Example Code:
Expected Behavior: React (or the underlying tooling) should concatenate the children into a string and render:
❤️
@eps1lon is this still open?