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

[Bug?]: Middleware returning Response is not working properly #1523

Open
2 tasks done
Playify opened this issue Jun 3, 2024 · 0 comments
Open
2 tasks done

[Bug?]: Middleware returning Response is not working properly #1523

Playify opened this issue Jun 3, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Playify
Copy link

Playify commented Jun 3, 2024

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

when returning a Response object from the middleware, the headers and body get mixed up, if both the middleware returns a Promise and the file router returns a webpage. (Or if multiple middleware return Responses)

Expected behavior 🤔

Only one of the Responses should be used, instead of mixing mutliple responses together. The middleware response should have priority, and only if no Response is returned, the webpage should try to render.

Steps to reproduce 🕹

Steps:

  1. create a routes/[...404].js error page
  2. create a middleware, that returns a new Response("some content"), when accessing a specific page
  3. check in browser, what gets returned. Sometimes it returns "some content", other times "<!DOCTYPE ht" (the start from the 404 error page, with same length as the "some content" string from the middleware)

Context 🔦

I was trying to create a file server, that returns files from the middleware, and directory listings via solid routes.

The problem lies in packages/start/src/middleware/index.tsx, as sendWebResponse is not awaited in any of the wrap* functions, and createMiddleware also doesn't await properly, if an array is passed in.

As a workaround, i currently do

await sendWebResponse(fetchEvent.nativeEvent,response);
return;

instead of

return response;

in my project.

Your environment 🌎

No response

@Playify Playify added the bug Something isn't working label Jun 3, 2024
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

No branches or pull requests

1 participant