Skip to content

Commit c4db81b

Browse files
authored
Merge pull request #567 from reactjs/copy/renderToString
Translation of the "renderToString" page
2 parents 1c72ef4 + 8f851e0 commit c4db81b

File tree

3 files changed

+40
-39
lines changed

3 files changed

+40
-39
lines changed

TRANSLATORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Voici la liste par ordre alphabétique (prénom, nom). **🙏🏻 Mille mercis
108108
<li><a href="https://fr.react.dev/reference/react-dom/server/renderToNodeStream"><code>renderToNodeStream</code></a></li>
109109
<li><a href="https://fr.react.dev/reference/react-dom/server/renderToStaticMarkup"><code>renderToStaticMarkup</code></a></li>
110110
<li><a href="https://fr.react.dev/reference/react-dom/server/renderToStaticNodeStream"><code>renderToStaticNodeStream</code></a></li>
111+
<li><a href="https://fr.react.dev/reference/react-dom/server/renderToString"><code>renderToString</code></a></li>
111112
<li><a href="https://fr.react.dev/reference/react/legacy">API React historique</a></li>
112113
<li><a href="https://fr.react.dev/reference/react/createElement"><code>createElement</code></a></li>
113114
<li><a href="https://fr.react.dev/reference/react/createFactory"><code>createFactory</code></a></li>

src/content/reference/react-dom/server/renderToNodeStream.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Un [flux Node.js en lecture](https://nodejs.org/api/stream.html#readable-streams
4949

5050
#### Limitations {/*caveats*/}
5151

52-
* Cette méthode attendra que toutes les [frontières Suspense](/reference/react/Suspense) aboutissent avant de commencer à produire le moindre rendu.
52+
* Cette méthode attendra que toutes les [périmètres Suspense](/reference/react/Suspense) aboutissent avant de commencer à produire le moindre rendu.
5353

5454
* À partir de React 18, cette méthode utilise un tampon pour l'ensemble de sa production, de sorte qu'elle n'a aucun des avantages du *streaming*. C'est pourquoi nous vous conseillons plutôt de migrer vers [`renderToPipeableStream`](/reference/react-dom/server/renderToPipeableStream).
5555

src/content/reference/react-dom/server/renderToString.md

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ title: renderToString
44

55
<Pitfall>
66

7-
`renderToString` does not support streaming or waiting for data. [See the alternatives.](#alternatives)
7+
`renderToString` ne prend en charge ni le *streaming* ni l'attente du chargement de données. [Découvrez les alternatives](#alternatives).
88

99
</Pitfall>
1010

1111
<Intro>
1212

13-
`renderToString` renders a React tree to an HTML string.
13+
`renderToString` fait le rendu d'un arbre React sous forme de texte HTML.
1414

1515
```js
1616
const html = renderToString(reactNode)
@@ -22,93 +22,94 @@ const html = renderToString(reactNode)
2222

2323
---
2424

25-
## Reference {/*reference*/}
25+
## Référence {/*reference*/}
2626

2727
### `renderToString(reactNode)` {/*rendertostring*/}
2828

29-
On the server, call `renderToString` to render your app to HTML.
29+
Côté serveur, appelez `renderToString` pour produire le HTML de votre appli.
3030

3131
```js
3232
import { renderToString } from 'react-dom/server';
3333

3434
const html = renderToString(<App />);
3535
```
3636

37-
On the client, call [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) to make the server-generated HTML interactive.
37+
Côté client, appelez [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) pour rendre interactif ce HTML généré côté serveur.
3838

39-
[See more examples below.](#usage)
39+
[Voir d'autres exemples ci-dessous](#usage).
4040

41-
#### Parameters {/*parameters*/}
41+
#### Paramètres {/*parameters*/}
4242

43-
* `reactNode`: A React node you want to render to HTML. For example, a JSX node like `<App />`.
43+
* `reactNode` : un nœud React dont vous souhaitez produire le HTML. Ça pourrait par exemple être un élément JSX tel que `<App />`.
4444

45-
#### Returns {/*returns*/}
45+
#### Valeur renvoyée {/*returns*/}
4646

47-
An HTML string.
47+
Une chaîne de caractères contenant le HTML.
4848

49-
#### Caveats {/*caveats*/}
49+
#### Limitations {/*caveats*/}
5050

51-
* `renderToString` has limited Suspense support. If a component suspends, `renderToString` immediately sends its fallback as HTML.
51+
* `renderToString` n'a qu'une prise en charge limitée de Suspense. Si votre composant suspend, `renderToString` renverra immédiatement le HTML de son JSX de secours.
5252

53-
* `renderToString` works in the browser, but using it in the client code is [not recommended.](#removing-rendertostring-from-the-client-code)
53+
* `renderToString` fonctionne côté navigateur, mais nous [déconseillons](#removing-rendertostring-from-the-client-code) de l'utiliser côté client.
5454

5555
---
5656

57-
## Usage {/*usage*/}
57+
## Utilisation {/*usage*/}
5858

59-
### Rendering a React tree as HTML to a string {/*rendering-a-react-tree-as-html-to-a-string*/}
59+
### Produire le HTML d'un arbre React sous forme d'une chaîne de caractères {/*rendering-a-react-tree-as-html-to-a-string*/}
6060

61-
Call `renderToString` to render your app to an HTML string which you can send with your server response:
61+
Appelez `renderToString` pour produire le texte HTML de votre appli, que vous pourrez alors renvoyer dans votre réponse serveur :
6262

6363
```js {5-6}
6464
import { renderToString } from 'react-dom/server';
6565

66-
// The route handler syntax depends on your backend framework
66+
// La syntaxe du gestionnaire de route dépend de votre
67+
// framework côté serveur
6768
app.use('/', (request, response) => {
6869
const html = renderToString(<App />);
6970
response.send(html);
7071
});
7172
```
7273

73-
This will produce the initial non-interactive HTML output of your React components. On the client, you will need to call [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) to *hydrate* that server-generated HTML and make it interactive.
74+
Ça produira le HTML initial, non interactif, de vos composants React. Côté client, vous aurez besoin d'appeler [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) pour *hydrater* ce HTML généré côté serveur et le rendre interactif.
7475

7576

7677
<Pitfall>
7778

78-
`renderToString` does not support streaming or waiting for data. [See the alternatives.](#alternatives)
79+
`renderToString` ne prend en charge ni le *streaming* ni l'attente du chargement de données. [Découvrez les alternatives](#alternatives).
7980

8081
</Pitfall>
8182

8283
---
8384

8485
## Alternatives {/*alternatives*/}
8586

86-
### Migrating from `renderToString` to a streaming method on the server {/*migrating-from-rendertostring-to-a-streaming-method-on-the-server*/}
87+
### Migrer de `renderToString` vers une méthode de *streaming* côté serveur {/*migrating-from-rendertostring-to-a-streaming-method-on-the-server*/}
8788

88-
`renderToString` returns a string immediately, so it does not support streaming or waiting for data.
89+
`renderToString` renvoie immédiatement un texte, elle ne prend donc en charge ni le *streaming* ni la suspension pour chargement de données.
8990

90-
When possible, we recommend using these fully-featured alternatives:
91+
Autant que possible nous conseillons d'utiliser plutôt une de ces alternatives plus capables :
9192

92-
* If you use Node.js, use [`renderToPipeableStream`.](/reference/react-dom/server/renderToPipeableStream)
93-
* If you use Deno or a modern edge runtime with [Web Streams](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API), use [`renderToReadableStream`.](/reference/react-dom/server/renderToReadableStream)
93+
* Si vous utilisez Node.js, utilisez [`renderToPipeableStream`](/reference/react-dom/server/renderToPipeableStream).
94+
* Si vous utilisez Deno ou un moteur léger moderne doté des [Web Streams](https://developer.mozilla.org/fr/docs/Web/API/Streams_API), utilisez [`renderToReadableStream`](/reference/react-dom/server/renderToReadableStream).
9495

95-
You can continue using `renderToString` if your server environment does not support streams.
96+
Vous pouvez continuer avec `renderToString` si votre environnement serveur ne prend pas en charge les flux.
9697

9798
---
9899

99-
### Removing `renderToString` from the client code {/*removing-rendertostring-from-the-client-code*/}
100+
### Retirer `renderToString` du code côté client {/*removing-rendertostring-from-the-client-code*/}
100101

101-
Sometimes, `renderToString` is used on the client to convert some component to HTML.
102+
Il arrive que `renderToString` soit utilisée côté client pour convertir un composant en HTML.
102103

103104
```js {1-2}
104-
// 🚩 Unnecessary: using renderToString on the client
105+
// 🚩 Inutile : utilisation de renderToString côté client
105106
import { renderToString } from 'react-dom/server';
106107

107108
const html = renderToString(<MyIcon />);
108-
console.log(html); // For example, "<svg>...</svg>"
109+
console.log(html); // Par exemple "<svg>...</svg>"
109110
```
110111

111-
Importing `react-dom/server` **on the client** unnecessarily increases your bundle size and should be avoided. If you need to render some component to HTML in the browser, use [`createRoot`](/reference/react-dom/client/createRoot) and read HTML from the DOM:
112+
L'import de `react-dom/server` **côté client** augmente pour rien la taille de votre *bundle*, nous vous le déconseillons donc. Si vous avez besoin d'obtenir côté client le HTML d'un composant, utilisez [`createRoot`](/reference/react-dom/client/createRoot) puis lisez le HTML directement depuis le DOM :
112113

113114
```js
114115
import { createRoot } from 'react-dom/client';
@@ -119,20 +120,19 @@ const root = createRoot(div);
119120
flushSync(() => {
120121
root.render(<MyIcon />);
121122
});
122-
console.log(div.innerHTML); // For example, "<svg>...</svg>"
123+
console.log(div.innerHTML); // Par exemple "<svg>...</svg>"
123124
```
124125

125-
The [`flushSync`](/reference/react-dom/flushSync) call is necessary so that the DOM is updated before reading its [`innerHTML`](https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML) property.
126+
L'appel à [`flushSync`](/reference/react-dom/flushSync) est nécessaire pour que le DOM soit bien mis à jour avant de lire la propriété [`innerHTML`](https://developer.mozilla.org/fr/docs/Web/API/Element/innerHTML).
126127

127128
---
128129

129-
## Troubleshooting {/*troubleshooting*/}
130+
## Dépannage {/*troubleshooting*/}
130131

131-
### When a component suspends, the HTML always contains a fallback {/*when-a-component-suspends-the-html-always-contains-a-fallback*/}
132+
### Quand un composant suspend, le HTML reflète la version de secours {/*when-a-component-suspends-the-html-always-contains-a-fallback*/}
132133

133-
`renderToString` does not fully support Suspense.
134+
`renderToString` ne prend pas pleinement en charge Suspense.
134135

135-
If some component suspends (for example, because it's defined with [`lazy`](/reference/react/lazy) or fetches data), `renderToString` will not wait for its content to resolve. Instead, `renderToString` will find the closest [`<Suspense>`](/reference/react/Suspense) boundary above it and render its `fallback` prop in the HTML. The content will not appear until the client code loads.
136-
137-
To solve this, use one of the [recommended streaming solutions.](#migrating-from-rendertostring-to-a-streaming-method-on-the-server) They can stream content in chunks as it resolves on the server so that the user sees the page being progressively filled in before the client code loads.
136+
Si un composant suspend (il est par exemple défini *via* [`lazy`](/reference/react/lazy) ou charge des données), `renderToString` n'attendra pas l'aboutissement du traitement. `renderToString` cherchera plutôt le périmètre [`<Suspense>`](/reference/react/Suspense) parent le plus proche et affichera le HTML de sa prop `fallback`. Le contenu n'apparaîtra pas jusqu'à ce que le code client soit chargé.
138137

138+
Pour résoudre ça, utilisez une de nos [solutions recommandées de *streaming*](#migrating-from-rendertostring-to-a-streaming-method-on-the-server). Elles peuvent *streamer* le contenu par morceaux au fil de l'aboutissement des traitements côté serveur, afin que l'utilisateur puisse bénéficier d'un chargement progressif de la page avant même que le code client ne soit chargé.

0 commit comments

Comments
 (0)