diff --git a/src/content/reference/react-dom/server/renderToPipeableStream.md b/src/content/reference/react-dom/server/renderToPipeableStream.md index c3fac16c3..c42af12e2 100644 --- a/src/content/reference/react-dom/server/renderToPipeableStream.md +++ b/src/content/reference/react-dom/server/renderToPipeableStream.md @@ -1,10 +1,17 @@ --- title: renderToPipeableStream +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/renderToPipeableStream.md). + + + -`renderToPipeableStream` renders a React tree to a pipeable [Node.js Stream.](https://nodejs.org/api/stream.html) +`renderToPipeableStream` renderizza un albero React in uno [Stream Node.js pipeable.](https://nodejs.org/api/stream.html) ```js const { pipe, abort } = renderToPipeableStream(reactNode, options?) @@ -16,7 +23,7 @@ const { pipe, abort } = renderToPipeableStream(reactNode, options?) -This API is specific to Node.js. Environments with [Web Streams,](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API) like Deno and modern edge runtimes, should use [`renderToReadableStream`](/reference/react-dom/server/renderToReadableStream) instead. +Questa API è specifica per Node.js. Negli ambienti con [Web Streams,](https://developer.mozilla.org/it/docs/Web/API/Streams_API) come Deno e i moderni edge runtime, usa invece [`renderToReadableStream`](/reference/react-dom/server/renderToReadableStream). @@ -26,7 +33,7 @@ This API is specific to Node.js. Environments with [Web Streams,](https://develo ### `renderToPipeableStream(reactNode, options?)` {/*rendertopipeablestream*/} -Call `renderToPipeableStream` to render your React tree as HTML into a [Node.js Stream.](https://nodejs.org/api/stream.html#writable-streams) +Chiama `renderToPipeableStream` per renderizzare il tuo albero React come HTML in uno [Stream Node.js.](https://nodejs.org/api/stream.html#writable-streams) ```js import { renderToPipeableStream } from 'react-dom/server'; @@ -40,52 +47,52 @@ const { pipe } = renderToPipeableStream(, { }); ``` -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'; @@ -138,15 +145,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' @@ -183,10 +190,10 @@ app.use('/', (request, response) => { }); ``` -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' @@ -194,7 +201,7 @@ const assetMap = { app.use('/', (request, response) => { const { pipe } = renderToPipeableStream(, { - // 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']], onShellReady() { @@ -205,7 +212,7 @@ app.use('/', (request, response) => { }); ``` -In the example above, the `bootstrapScriptContent` option adds an extra inline `