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
This commit is contained in:
co-authored by
Claude Fable 5
parent
22c5045c25
commit
d22f996596
@@ -7,7 +7,10 @@ import { readFile } from 'node:fs/promises'
|
||||
import { join, normalize, extname, dirname } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
import { Readable } from 'node:stream'
|
||||
|
||||
import createApp from '../../examples/counter/app.js'
|
||||
import createStreamingApp from '../../examples/streaming/app.js'
|
||||
|
||||
const root = normalize(join(dirname(fileURLToPath(import.meta.url)), '..', '..'))
|
||||
|
||||
@@ -60,6 +63,18 @@ export function startServer () {
|
||||
return
|
||||
}
|
||||
|
||||
if (url.pathname === '/stream') {
|
||||
const delay = Number(url.searchParams.get('delay')) || 500
|
||||
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' })
|
||||
// padding nudges browsers to start parsing before the stream closes
|
||||
res.write('<!doctype html>\n<html lang="en">\n<head><meta charset="utf-8"><title>choo streams</title></head>\n' + '<!-- ' + ' '.repeat(1024) + ' -->\n')
|
||||
const body = Readable.fromWeb(createStreamingApp({ delay }).toStream('/'))
|
||||
body.pipe(res, { end: false })
|
||||
body.on('end', () => res.end('\n</html>'))
|
||||
body.on('error', () => res.destroy())
|
||||
return
|
||||
}
|
||||
|
||||
let pathname = decodeURIComponent(url.pathname)
|
||||
if (pathname.endsWith('/')) pathname += 'index.html'
|
||||
const file = normalize(join(root, pathname))
|
||||
|
||||
Reference in New Issue
Block a user