Skip to content

Route with renderToStream not working as expected #674

@matiaskorhonen

Description

@matiaskorhonen

I'm trying to figure out how to get responses with a chunked transfer encoding using RedwoodSDK but I'm running into an error when I try to do so.

I have a very basic app with a “normal” route and a streamed route that I pretty much copied from the kitchen sink example:

import { defineApp, renderToStream } from "rwsdk/worker";
import { route, render } from "rwsdk/router";
import { Document } from "@/app/Document";
import { setCommonHeaders } from "@/app/headers";
import { setupSessionStore } from "./session/store";
import { Session } from "./session/durableObject";
import { env } from "cloudflare:workers";
export { SessionDurableObject } from "./session/durableObject";

export type AppContext = {
  session: Session | null;
};

export default defineApp([
  setCommonHeaders(),
  async () => {
    setupSessionStore(env);
  },
  render(Document, [route("/", () => <h1>Not streamed</h1>)]),
  route("/stream", async () => {
    const stream = await renderToStream(
      <div>
        <h1>Streamed route</h1>
        <p>This should be a chunked response</p>
      </div>,
      { Document }
    );
    return new Response(stream, {
      status: 200,
      headers: { "Content-Type": "text/html" },
    });
  }),
]);

When I load the stream route in the browser, the contents briefly flash but then vanish and there's a ‘Connection closed’ error in the browser console:

Error.-.Connection.Closed.mov

I get the same behaviour locally and on Cloudflare workers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    1.0Issues that must be fixed for the 1.0 releasebugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions