reactjs / reactjs/react.dev

What is the difference between "UI tree" and "render tree" in the docs?

Ouverte
#6,386 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
JavaScript
Étoiles
11.8k
Forks
7.9k
Merge moyen
1 j 11 h
PR mergées (30 j)
11

Description

Recently an article called "Your UI as a Tree" has been added, introducing a new concept called "render tree". However, the React docs have been using a similar term, "UI tree", such as in the article "Preserving and Resetting State" and "Passing Data Deeply with Context" where this term appears many times.

Are these exactly the same concept? Or are they different? Initially, I thought that they were the same concept, at least in the context of how React and ReactDOM work. But could they actually be different?

My current understanding is as follows:

  • JSX tree: The nested JSX tag hierarchy that developers can return from a component.
  • Render tree: The component hierarchy in a single pass of React rendering. This concept exists in the core React code, not ReactDOM. A new one is created for each render pass.
  • DOM tree: The tree of browser DOM elements you can traverse with querySelectorAll(), etc.. Changes over time as a result of the commit.
  • UI tree: ???

The question here is, "Is a render tree immutable?" According to "Your UI as a Tree", a render tree is an immutable data structure corresponding to a single render pass, like a snapshot of a specific render, traditionally referred to as "virtual DOM" or "(UI) description":

  • A render tree represents a single render pass of a React application.
  • Although render trees may differ across render passes, ...

It also equates the render tree and the UI tree:

  • React creates a UI tree from your components.
  • React creates a render tree, a UI tree, composed of the rendered components.

On the other hand, in "Preserving and Resetting State", it says, "React removed the Counter from the UI tree and destroyed its state". This seems to indicate that the UI tree is mutable, hence different from the render tree.

After reviewing the usage of "UI tree" throughout the documentation, my tentative conclusion is that "UI tree" has now become an ambiguous concept that may refer to either a render tree or a DOM tree depending on the context. Now that "render tree" is introduced and clearly defined, the term "UI tree" might be retired from most part of the documentation for the sake of consistency. What do you think?

I understand that such discussions are usually not much of an issue, but I don't want to see the problem of the legacy docs again, where consistency was lost as new articles were added. Once there's some consensus, I would like to create a PR to maintain consistency.

/CC @lunaleaps

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Comparez la terminologie et les exemples de « Your UI as a Tree », « Preserving and Resetting State » et « Passing Data Deeply with Context », y compris les utilisations documentées de « UI tree » et « render tree ». Commencez par établir un consensus sur la question de savoir si les termes doivent être distingués ou regroupés ; le travail est considéré comme terminé lorsqu’une décision terminologique commune peut guider un PR de documentation ultérieur.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript, react
Domaine
documentation
Type d'issue
Documentation
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.