Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bun serve with a Response with empty ReadableStream won't redirect. #15320

Open
adrifer opened this issue Nov 21, 2024 · 1 comment · May be fixed by #15322
Open

Bun serve with a Response with empty ReadableStream won't redirect. #15320

adrifer opened this issue Nov 21, 2024 · 1 comment · May be fixed by #15322
Assignees
Labels
bug Something isn't working

Comments

@adrifer
Copy link

adrifer commented Nov 21, 2024

What version of Bun is running?

1.1.36+ededc168c

What platform is your computer?

Microsoft Windows NT 10.0.22631.0 x64

What steps can reproduce the bug?

Run this code:

Bun.serve({
    port: process.env.NITRO_PORT || process.env.PORT || 3e3,
    websocket: void 0,
    async fetch(req, server2) {
      const url = new URL(req.url);
      if(url.pathname === "/redirect") {
          const emptyStream = new ReadableStream({
            start(controller) {
              // Immediately close the stream to make it empty
              controller.close();
            }
          });
          
          return new Response(emptyStream, {
            status: 307,
            headers: {
                location: "/"
            }
          });
    }
    
    return new Response("Hello world");
    }
  });
  1. navigate to localhost:3000/redirect

Nothing will happen, the response the browser receives is empty (no headers or body) and no redirect.

What is the expected behavior?

It should redirect to / and show Hello world in the browser.

What do you see instead?

White screen, because the response contains no body or headers.

Additional information

No response

@adrifer
Copy link
Author

adrifer commented Nov 21, 2024

As context, this breaks new TanStack Starts framework, basically when using Bun all redirects will do nothing and an empty page will be rendered. TanStack/router#2819

@cirospaciari cirospaciari self-assigned this Nov 21, 2024
@cirospaciari cirospaciari linked a pull request Nov 22, 2024 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants