Files
buuh/examples/streaming/app.js
T
Bendik Aagaard LynghaugandClaude Fable 5 d22f996596 feat(examples)+test(e2e): streaming SSR demo, proven progressive in Chromium
examples/streaming is a runnable Node server piping toStream() through
Readable.fromWeb. The e2e server gains /stream, and two tests prove real
streaming: shell bytes arrive over HTTP before the async hole resolves,
and Chromium builds the shell DOM mid-stream, then grows the slow section
into the same document without navigation.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014NgfSjHE11oFpoSnLVKLXd
2026-09-08 18:44:52 +02:00

36 lines
1.1 KiB
JavaScript

// Streaming SSR demo: the shell flushes immediately, the slow section
// streams in when its promise resolves. Run it:
// node examples/streaming/server.js
//
// This page is server-rendered only (no hydration script): async holes
// stream on the server, while client-side views must be synchronous.
// Serializing streamed state for hydration is bankai v10 territory.
import choo from '@choojs/core'
import html from '@choojs/html'
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
export default function createApp ({ delay = 500 } = {}) {
const app = choo()
app.use((state) => { state.delay = delay })
app.route('/', mainView)
app.route('*', mainView)
return app
}
function mainView (state, emit) {
return html`
<body>
<h1>choo streams</h1>
<p>This shell was flushed before the slow part finished.</p>
${slowSection(state)}
</body>
`
}
async function slowSection (state) {
await wait(state.delay)
return html`<section id="slow">…and this arrived ${state.delay}ms later, same response.</section>`
}