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
Copy file name to clipboardExpand all lines: README.md
+100Lines changed: 100 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -144,6 +144,106 @@ main().catch((error) => {
144
144
145
145
---
146
146
147
+
### Streaming
148
+
149
+
> [!NOTE]
150
+
> This is an early version of our streaming implementation.
151
+
152
+
Preact supports streaming HTML to the client incrementally, flushing `<Suspense>` fallbacks immediately and replacing them with the resolved content as data arrives. This reduces Time to First Byte and allows the browser to start parsing earlier.
153
+
154
+
Suspended subtrees are rendered into a hidden `<div>` and swapped into place on the client via a small inline script. When rendering a full HTML document (component tree rooted at `<html>`), a `<!DOCTYPE html>` declaration is prepended automatically and deferred content is injected before the closing `</body>` tag to keep the markup valid.
155
+
156
+
#### `renderToReadableStream` — Web Streams (Edge / Deno / Bun / Cloudflare Workers)
// Works in any Web Streams environment (Deno, Bun, Cloudflare Workers, …)
176
+
exportdefault {
177
+
fetch() {
178
+
conststream=renderToReadableStream(<App />);
179
+
180
+
// stream.allReady resolves once all suspended content has been flushed
181
+
returnnewResponse(stream, {
182
+
headers: { 'Content-Type':'text/html' }
183
+
});
184
+
}
185
+
};
186
+
```
187
+
188
+
The returned `ReadableStream` has an extra `allReady: Promise<void>` property that resolves once every suspended subtree has been written. Await it before sending the response if you need the complete document before anything is flushed (e.g. for static export).
0 commit comments