Skip to content

[v2] Regression: Response sended before first stream payload #1510

Closed

Description

@katywings

Environment

  • h3: 2.0.1-rc.25
  • node: 24.18.0

Reproduction

v2.0.1-rc.25 (Broken status/headers)

import { H3, serve } from "h3";

const app = new H3().get("/", async (event) => {
  return ReadableStream.from((async function* () {
    event.res.status = 201;
    event.res.headers.set("hello", "world");

    yield "Hello World";
  })())
});

serve(app, { port: 3000 });

v1.15.11 (Working status/headers)

import { setResponseHeader, setResponseStatus } from "h3";
import { createApp, defineEventHandler, sendStream, toNodeListener } from "h3";
import { createServer } from "http";

const app = createApp();
app.use("/", defineEventHandler(async (event) => {
  return ReadableStream.from((async function* () {
    setResponseStatus(event, 201);
    setResponseHeader(event, "hello", "world");

    yield "Hello World";
  })())
}));

createServer(toNodeListener(app)).listen(3000)

Describe the bug

h3 v1 waited with sending the response until the first async stream payload. This allowed setting response status codes and headers from within a stream (as long as it was part of the first payload). In h3 v2 you must set response status codes and headers before returning the stream. Response changes made while async rendering the first stream payload are now ignored. This makes it impossible to set response status/headers depending on async data within stream based frameworks such as SolidStart.

Additional context

Related: solidjs/solid-start#2229

Logs

Activity

  1. changed the title [-]Regression: Response sended before first stream payload[/-] [+][v2] Regression: Response sended before first stream payload[/+] on Jul 24, 2026
  2. pi0 commented on Jul 24, 2026

    @pi0
    Member

    I will check it might be a fundumental difference when we migrated to web apis.

    btw any reason you are not using h3 iterable util? to send reponse

  3. katywings commented on Jul 24, 2026

    @katywings
    Author

    Thank you 🙂. No special reason, I didn't know iterable existed 😅

  4. pi0 commented on Jul 24, 2026

    @pi0
    Member

    @katywings please check #1512 it can be fixed partially using iterable in next releease but not sure if we could really fix limit of web apis. please ping me to reopen if still want to discuss it.

  5. katywings commented on Jul 24, 2026

    @katywings
    Author

    @pi0 #1512 indeed fixed the issue, thank you a lot ❤️🎉.

    Different issue (I gonna open it tomorrow 🙏), but rc.26 unfortunately resulted in a different regression with merged cookie headers from event.response being set twice for some reason 🙈.

    Edit: The cookie regression is probably unrelated to h3 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions