You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This API depends on [Web Streams.](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API) For Node.js, use [`resumeToNodeStream`](/reference/react-dom/server/renderToPipeableStream) instead.
19
+
Esta API depende de [Web Streams.](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API) Para Node.js, use [`resumeToNodeStream`](/reference/react-dom/server/renderToPipeableStream) em vez disso.
Call`resume`to resume rendering a pre-rendered React tree as HTML into a [Readable Web Stream.](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream)
29
+
Chame`resume`para retomar a renderização de uma árvore React pré-renderizada como HTML em um [Readable Web Stream.](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream)
30
30
31
31
```js
32
32
import { resume } from'react-dom/server';
@@ -39,39 +39,39 @@ async function handler(request, writable) {
39
39
}
40
40
```
41
41
42
-
[See more examples below.](#usage)
42
+
[Veja mais exemplos abaixo.](#usage)
43
43
44
-
#### Parameters {/*parameters*/}
44
+
#### Parâmetros {/*parameters*/}
45
45
46
-
* `reactNode`: The React node you called `prerender` with. For example, a JSX element like `<App />`. It is expected to represent the entire document, so the `App`component should render the`<html>` tag.
47
-
* `postponedState`: The opaque `postpone`object returned from a [prerender API](/reference/react-dom/static/index), loaded from wherever you stored it (e.g. redis, a file, or S3).
48
-
* **optional** `options`: An object with streaming options.
49
-
* **optional** `nonce`: A [`nonce`](http://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#nonce) string to allow scripts for [`script-src` Content-Security-Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src).
50
-
* **optional** `signal`: An [abort signal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) that lets you [abort server rendering](#aborting-server-rendering) and render the rest on the client.
51
-
* **optional** `onError`: A callback that fires whenever there is a server error, whether [recoverable](/reference/react-dom/server/renderToReadableStream#recovering-from-errors-outside-the-shell) or [not.](/reference/react-dom/server/renderToReadableStream#recovering-from-errors-inside-the-shell) By default, this only calls`console.error`. If you override it to [log crash reports,](/reference/react-dom/server/renderToReadableStream#logging-crashes-on-the-server) make sure that you still call`console.error`.
46
+
* `reactNode`: O nó React com o qual você chamou `prerender`. Por exemplo, um elemento JSX como `<App />`. Espera-se que ele represente o documento inteiro, então o componente `App`deve renderizar a tag`<html>`.
47
+
* `postponedState`: O objeto opaco `postpone`retornado de uma [API de prerender](/reference/react-dom/static/index), carregado de onde quer que você o tenha armazenado (por exemplo, redis, um arquivo ou S3).
48
+
* **opcional** `options`: Um objeto com opções de streaming.
49
+
* **opcional** `nonce`: Uma string [`nonce`](http://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#nonce) para permitir scripts para [`script-src` Content-Security-Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src).
50
+
* **opcional** `signal`: Um [sinal de abortar](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) que permite [abortar a renderização do servidor](#aborting-server-rendering) e renderizar o restante no cliente.
51
+
* **opcional** `onError`: Um callback que é acionado sempre que ocorre um erro no servidor, seja [recuperável](/reference/react-dom/server/renderToReadableStream#recovering-from-errors-outside-the-shell) ou [não.](/reference/react-dom/server/renderToReadableStream#recovering-from-errors-inside-the-shell) Por padrão, isso apenas chama`console.error`. Se você o substituir para [registrar relatórios de falhas,](/reference/react-dom/server/renderToReadableStream#logging-crashes-on-the-server) certifique-se de ainda chamar`console.error`.
52
52
53
53
54
-
#### Returns {/*returns*/}
54
+
#### Retorna {/*returns*/}
55
55
56
-
`resume`returns a Promise:
56
+
`resume`retorna uma Promise:
57
57
58
-
- If`resume`successfully produced a [shell](/reference/react-dom/server/renderToReadableStream#specifying-what-goes-into-the-shell), that Promise will resolve to a [Readable Web Stream.](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) that can be piped to a [Writable Web Stream.](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).
59
-
- If an error happens in the shell, the Promise will reject with that error.
58
+
- Se`resume`produziu com sucesso uma [shell](/reference/react-dom/server/renderToReadableStream#specifying-what-goes-into-the-shell), essa Promise será resolvida para um [Readable Web Stream.](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) que pode ser encadeado a um [Writable Web Stream.](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).
59
+
- Se ocorrer um erro na shell, a Promise será rejeitada com esse erro.
60
60
61
-
The returned stream has an additional property:
61
+
O stream retornado tem uma propriedade adicional:
62
62
63
-
* `allReady`: A Promise that resolves when all rendering is complete. You can`awaitstream.allReady`before returning a response [for crawlers and static generation.](/reference/react-dom/server/renderToReadableStream#waiting-for-all-content-to-load-for-crawlers-and-static-generation) If you do that, you won't get any progressive loading. The stream will contain the final HTML.
63
+
* `allReady`: Uma Promise que resolve quando toda a renderização é concluída. Você pode`awaitstream.allReady`antes de retornar uma resposta [para crawlers e geração estática.](/reference/react-dom/server/renderToReadableStream#waiting-for-all-content-to-load-for-crawlers-and-static-generation) Se você fizer isso, não obterá nenhum carregamento progressivo. O stream conterá o HTML final.
64
64
65
-
#### Caveats {/*caveats*/}
65
+
#### Ressalvas {/*caveats*/}
66
66
67
-
- `resume`does not accept options for `bootstrapScripts`, `bootstrapScriptContent`, or`bootstrapModules`. Instead, you need to pass these options to the`prerender`call that generates the `postponedState`. You can also inject bootstrap content into the writable stream manually.
68
-
- `resume`does not accept `identifierPrefix` since the prefix needs to be the same in both `prerender`and`resume`.
69
-
- Since`nonce`cannot be provided to prerender, you should only provide`nonce`to`resume`if you're not providing scripts to prerender.
70
-
- `resume` re-renders from the root until it finds a component that was not fully pre-rendered. Only fully prerendered Components (the Component and its children finished prerendering) are skipped entirely.
67
+
- `resume`não aceita opções para `bootstrapScripts`, `bootstrapScriptContent` ou`bootstrapModules`. Em vez disso, você precisa passar essas opções para a chamada`prerender`que gera o `postponedState`. Você também pode injetar o conteúdo bootstrap no stream gravável manualmente.
68
+
- `resume`não aceita `identifierPrefix`, pois o prefixo precisa ser o mesmo em `prerender`e`resume`.
69
+
- Como`nonce`não pode ser fornecido ao prerender, você só deve fornecer`nonce`ao`resume`se não estiver fornecendo scripts ao prerender.
70
+
- `resume` re-renderiza da raiz até encontrar um componente que não foi totalmente pré-renderizado. Apenas Componentes totalmente pré-renderizados (o Componente e seus filhos terminaram o pré-renderização) são pulados inteiramente.
71
71
72
-
## Usage {/*usage*/}
72
+
## Uso {/*usage*/}
73
73
74
-
### Resuming a prerender {/*resuming-a-prerender*/}
74
+
### Retomando um prerender {/*resuming-a-prerender*/}
75
75
76
76
<Sandpack>
77
77
@@ -202,35 +202,4 @@ export async function flushReadableStreamToFrame(readable, frame) {
202
202
constdocument=frame.contentWindow.document;
203
203
constdecoder=newTextDecoder();
204
204
forawait (constchunkofreadable) {
205
-
constpartialHTML=decoder.decode(chunk);
206
-
document.write(partialHTML);
207
-
}
208
-
}
209
-
210
-
// This doesn't need to be an error.
211
-
// You can use any other means to check if an error during prerender was
212
-
// from an intentional abort or a real error.
213
-
exportclassPostponedextendsError {}
214
-
215
-
// We're just hardcoding a session here.
216
-
exportfunctiongetUser(sessionID) {
217
-
return {
218
-
name:"Alice",
219
-
};
220
-
}
221
-
222
-
exportfunctionsleep(timeoutMS) {
223
-
returnnewPromise((resolve) => {
224
-
setTimeout(() => {
225
-
resolve();
226
-
}, timeoutMS);
227
-
});
228
-
}
229
-
```
230
-
231
-
</Sandpack>
232
-
233
-
### Further reading {/*further-reading*/}
234
-
235
-
Resuming behaves like `renderToReadableStream`. For more examples, check out the [usage section of `renderToReadableStream`](/reference/react-dom/server/renderToReadableStream#usage).
236
-
The [usage section of `prerender`](/reference/react-dom/static/prerender#usage) includes examples of how to use `prerender` specifically.
0 commit comments