Deploying React applications to the edge has traditionally been limited to simple static assets or basic SSR. With modern RSC runtimes, we can now stream full-stack applications directly from edge nodes.

Edge Benefits

  1. Near-Zero Latency: Requests are processed at the data center closest to the client.
  2. Streaming HTML: Time to First Byte (TTFB) drops dramatically as the shell streams immediately.
  3. KV and D1 Integration: Co-located storage eliminates round-trip penalties to distant databases.
export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const stream = await renderAppToReadableStream(request, env)
    return new Response(stream, {
      headers: { 'Content-Type': 'text/html; charset=utf-8' },
    })
  },
}