reactjs / reactjs/react.dev

[Suggestion]: Clarify SSR metadata hoisting behavior for fragment-based rendering

Abierto Apto para principiantes
#8,559 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

type: documentation
Lenguaje dominante
JavaScript
Estrellas
11.8k
Forks
7.9k
Merge medio
1 d 11 h
PR fusionados (30 d)
11

Descripción

Summary

React 19's documentation for tags title, meta and link states that they are automatically hoisted to the document </head/>. However, there is a critical nuance regarding Server-Side Rendering (SSR) that should be explicitly documented.

When React is used to render only a fragment of a page (e.g., mounted inside </div id="root"/> rather than controlling the full HTML document), metadata tags are not hoisted to the actual HTML during SSR. Instead, they appear at the top of React's rendered tree (which is inside the </body/> in the initial HTML response).

Page

https://react.dev/reference/react-dom/components/title

Details

You can watch it at any basic SSR template, I also created an example
If you run it, you will see, that <title> and will not be hoisted to the actual HTML .

This is server html response
Image

This is browser render
Image

I propose adding a note in the React 19 documentation under the "Rendering Metadata" section that clarifies:

Important: React 19's automatic hoisting works at the React tree level, not the HTML document level. During SSR with renderToString renderToPipeableStream and others, metadata tags are placed at the top of React's rendered output. If React controls the entire document, this means </head/>. If React renders only a fragment (e.g., inside a </div id="root"/>), the tags will be in this fragment and will no be moved to </head/>. For SEO-critical metadata that must appear in the initial HTML </head/>, server-side integration (e.g., rendering these tags in your backend framework's layout) is still required in fragment-based setups.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con las páginas de documentación de React 19 para title, meta y link, especialmente la sección "Rendering Metadata". Revisa el comportamiento de SSR descrito en el issue y compáralo con el ejemplo enlazado que usa renderToString o renderToPipeableStream. Se considera terminado cuando la documentación explica claramente la colocación de SSR basada en fragmentos frente al renderizado de documentos completos y la necesidad de integración del lado del servidor cuando corresponda.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript, react
Área
documentation
Tipo de issue
Documentación
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Tranquilo
Claridad
Bien especificado
Aptitud para principiantes
72/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.