From 040b1357ae7454a7db9d81528a836a1ecca2e86c Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 14 Sep 2026 20:53:18 +0000 Subject: [PATCH 1/2] translate(reference): renderToReadableStream (#674) (#706) Signed-off-by: Alessandro De Blasis --- .../server/renderToReadableStream.md | 193 +++++++++--------- 1 file changed, 100 insertions(+), 93 deletions(-) diff --git a/src/content/reference/react-dom/server/renderToReadableStream.md b/src/content/reference/react-dom/server/renderToReadableStream.md index 76819184c..e6c977b2a 100644 --- a/src/content/reference/react-dom/server/renderToReadableStream.md +++ b/src/content/reference/react-dom/server/renderToReadableStream.md @@ -1,10 +1,17 @@ --- title: renderToReadableStream +translationStatus: ai-draft --- + + +Questa pagina è stata tradotta automaticamente e supervisionata da un maintainer. Un'ulteriore revisione da parte della community sarebbe comunque utile. [Migliora questa traduzione](https://github.com/reactjs/it.react.dev/edit/main/src/content/reference/react-dom/server/renderToReadableStream.md). + + + -`renderToReadableStream` renders a React tree to a [Readable Web Stream.](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) +`renderToReadableStream` renderizza un albero React in uno [Stream Web Readable.](https://developer.mozilla.org/it/docs/Web/API/ReadableStream) ```js const stream = await renderToReadableStream(reactNode, options?) @@ -16,7 +23,7 @@ const stream = await renderToReadableStream(reactNode, options?) -This API depends on [Web Streams.](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API) For Node.js, use [`renderToPipeableStream`](/reference/react-dom/server/renderToPipeableStream) instead. +Questa API dipende dai [Web Streams.](https://developer.mozilla.org/it/docs/Web/API/Streams_API) Per Node.js, usa invece [`renderToPipeableStream`](/reference/react-dom/server/renderToPipeableStream). @@ -26,7 +33,7 @@ This API depends on [Web Streams.](https://developer.mozilla.org/en-US/docs/Web/ ### `renderToReadableStream(reactNode, options?)` {/*rendertoreadablestream*/} -Call `renderToReadableStream` to render your React tree as HTML into a [Readable Web Stream.](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) +Chiama `renderToReadableStream` per renderizzare il tuo albero React come HTML in uno [Stream Web Readable.](https://developer.mozilla.org/it/docs/Web/API/ReadableStream) ```js import { renderToReadableStream } from 'react-dom/server'; @@ -41,49 +48,49 @@ async function handler(request) { } ``` -On the client, call [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) to make the server-generated HTML interactive. +Sul client, chiama [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) per idratare l'HTML generato sul server e attivarne l'interattività. -[See more examples below.](#usage) +[Vedi altri esempi sotto.](#usage) #### Parameters {/*parameters*/} -* `reactNode`: A React node you want to render to HTML. For example, a JSX element like ``. It is expected to represent the entire document, so the `App` component should render the `` tag. - -* **optional** `options`: An object with streaming options. - * **optional** `bootstrapScriptContent`: If specified, this string will be placed in an inline ` ``` -On the client, your bootstrap script should [hydrate the entire `document` with a call to `hydrateRoot`:](/reference/react-dom/client/hydrateRoot#hydrating-an-entire-document) +Sul client, il tuo script bootstrap dovrebbe [idratare l'intero `document` con una chiamata a `hydrateRoot`:](/reference/react-dom/client/hydrateRoot#hydrating-an-entire-document) ```js [[1, 4, ""]] import { hydrateRoot } from 'react-dom/client'; @@ -139,15 +146,15 @@ import App from './App.js'; hydrateRoot(document, ); ``` -This will attach event listeners to the server-generated HTML and make it interactive. +Questo attaccherà i listener di eventi all'HTML generato sul server e lo renderà interattivo. -#### Reading CSS and JS asset paths from the build output {/*reading-css-and-js-asset-paths-from-the-build-output*/} +#### Leggere i percorsi delle risorse CSS e JS dall'output della build {/*reading-css-and-js-asset-paths-from-the-build-output*/} -The final asset URLs (like JavaScript and CSS files) are often hashed after the build. For example, instead of `styles.css` you might end up with `styles.123456.css`. Hashing static asset filenames guarantees that every distinct build of the same asset will have a different filename. This is useful because it lets you safely enable long-term caching for static assets: a file with a certain name would never change content. +Gli URL finali delle risorse (come file JavaScript e CSS) spesso vengono hashati dopo la build. Ad esempio, invece di `styles.css` potresti finire con `styles.123456.css`. L'hashing dei nomi file delle risorse statiche garantisce che ogni build distinta della stessa risorsa avrà un nome file diverso. Questo è utile perché ti permette di abilitare in sicurezza la cache a lungo termine per le risorse statiche: un file con un certo nome non cambierà mai contenuto. -However, if you don't know the asset URLs until after the build, there's no way for you to put them in the source code. For example, hardcoding `"/styles.css"` into JSX like earlier wouldn't work. To keep them out of your source code, your root component can read the real filenames from a map passed as a prop: +Tuttavia, se non conosci gli URL delle risorse fino a dopo la build, non c'è modo di inserirli nel codice sorgente. Ad esempio, hardcodare `"/styles.css"` nel JSX come prima non funzionerebbe. Per tenerli fuori dal codice sorgente, il tuo componente root può leggere i nomi file reali da una mappa passata come prop: ```js {1,6} export default function App({ assetMap }) { @@ -163,10 +170,10 @@ export default function App({ assetMap }) { } ``` -On the server, render `` and pass your `assetMap` with the asset URLs: +Sul server, renderizza `` e passa la tua `assetMap` con gli URL delle risorse: ```js {1-5,8,9} -// You'd need to get this JSON from your build tooling, e.g. read it from the build output. +// Dovresti ottenere questo JSON dal tuo build tooling, ad es. leggerlo dall'output della build. const assetMap = { 'styles.css': '/styles.123456.css', 'main.js': '/main.123456.js' @@ -182,10 +189,10 @@ async function handler(request) { } ``` -Since your server is now rendering ``, you need to render it with `assetMap` on the client too to avoid hydration errors. You can serialize and pass `assetMap` to the client like this: +Poiché il tuo server ora renderizza ``, devi renderizzarlo con `assetMap` anche sul client per evitare errori di hydration. Puoi serializzare e passare `assetMap` al client così: ```js {9-10} -// You'd need to get this JSON from your build tooling. +// Dovresti ottenere questo JSON dal tuo build tooling. const assetMap = { 'styles.css': '/styles.123456.css', 'main.js': '/main.123456.js' @@ -193,7 +200,7 @@ const assetMap = { async function handler(request) { const stream = await renderToReadableStream(, { - // Careful: It's safe to stringify() this because this data isn't user-generated. + // Attenzione: è sicuro fare stringify() di questo perché questi dati non sono generati dall'utente. bootstrapScriptContent: `window.assetMap = ${JSON.stringify(assetMap)};`, bootstrapScripts: [assetMap['/main.js']], }); @@ -203,7 +210,7 @@ async function handler(request) { } ``` -In the example above, the `bootstrapScriptContent` option adds an extra inline `