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
+98Lines changed: 98 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -144,6 +144,104 @@ 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.
// Works in any Web Streams environment (Deno, Bun, Cloudflare Workers, …)
174
+
exportdefault {
175
+
fetch() {
176
+
conststream=renderToReadableStream(<App />);
177
+
178
+
// stream.allReady resolves once all suspended content has been flushed
179
+
returnnewResponse(stream, {
180
+
headers: { 'Content-Type':'text/html' }
181
+
});
182
+
}
183
+
};
184
+
```
185
+
186
+
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). At which point you might be better off using `renderToStringAsync` though.
0 commit comments