mirror of
https://github.com/zebrajr/react.git
synced 2025-12-07 12:20:38 +01:00
When we postpone a prerender in the shell, we should just leave an empty prelude and resume from the root. While preserving any options passed in. Since we haven't flushed anything we can't assume we've already emitted html/body tags or any resources tracked in the resumable state. This introduces a resetResumableState function to reset anything we didn't flush. This is a bit hacky. Ideally, we probably shouldn't have tracked it as already happened until it flushed or something like that. Basically, it's like restarting the prerender with the same options and then immediately aborting. When we add the preload headers, we'd track those as preload() being emitted after the reset and so they get readded to the resumable state in that case. |
||
|---|---|---|
| .. | ||
| npm | ||
| src | ||
| client.js | ||
| index.classic.fb.js | ||
| index.experimental.js | ||
| index.js | ||
| index.modern.fb.js | ||
| index.stable.js | ||
| package.json | ||
| README.md | ||
| server-rendering-stub.js | ||
| server.browser.js | ||
| server.bun.js | ||
| server.edge.js | ||
| server.js | ||
| server.node.js | ||
| static.browser.js | ||
| static.edge.js | ||
| static.js | ||
| static.node.js | ||
| test-utils.js | ||
| unstable_server-external-runtime.js | ||
| unstable_testing.classic.fb.js | ||
| unstable_testing.experimental.js | ||
| unstable_testing.js | ||
| unstable_testing.modern.fb.js | ||
| unstable_testing.stable.js | ||
react-dom
This package serves as the entry point to the DOM and server renderers for React. It is intended to be paired with the generic React package, which is shipped as react to npm.
Installation
npm install react react-dom
Usage
In the browser
import { createRoot } from 'react-dom/client';
function App() {
return <div>Hello World</div>;
}
const root = createRoot(document.getElementById('root'));
root.render(<App />);
On the server
import { renderToPipeableStream } from 'react-dom/server';
function App() {
return <div>Hello World</div>;
}
function handleRequest(res) {
// ... in your server handler ...
const stream = renderToPipeableStream(<App />, {
onShellReady() {
res.statusCode = 200;
res.setHeader('Content-type', 'text/html');
stream.pipe(res);
},
// ...
});
}
API
react-dom
See https://react.dev/reference/react-dom
react-dom/client
See https://react.dev/reference/react-dom/client