solidjs / solid-router

A universal router for Solid inspired by Ember and React Router
MIT License
1.11k stars 138 forks source link

Thrown `redirect`'s inside of `cache` are not being catched anymore for all versions after `0.12.0` #378

Closed gabrielmfern closed 5 months ago

gabrielmfern commented 5 months ago

Describe the bug

If you create a cache function that throws a redirect it will exit the server saying that the promise was unhandled:

[UnhandledPromiseRejection: This error originated either by throwing inside of an async 
function without a catch block, or by
rejecting a promise which was not handled with .catch(). The promise rejected 
with the reason "#<_Response>".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

I encountered this issue specifically under the context of start but I found that downgrading the @solidjs/router version to 0.12.0 fixed this. This seems to only happen when deferStream is not set to true as well.

Your Example Website or App

https://github.com/solidjs/solid-start/tree/main/examples/with-auth

Steps to Reproduce the Bug or Issue

This can be very well reproduced using the with-auth Solid Start example.

  1. Remove deferStream from createAsync inside of src/routes/index.tsx
  2. Run pnpm dev
  3. Open http://localhost:3000 directly and it will error on the server

Both when deferStream is enabled on @solidjs/router@0.12.3 and when deferStream is disabled on @solidjs/router@0.12.0 this does work.

Expected behavior

That the redirect is caught on the server and responds with the appropriate Response such that the user is redirected without errors on the server.

Screenshots or Videos

No response

Platform

Additional context

No response

ryansolid commented 5 months ago

Thanks for reporting that was an unintended early return.. fixed by https://github.com/solidjs/solid-router/commit/533b7a0bca01a64b8a525e470cd1321e51d14366

ryansolid commented 5 months ago

Released in 0.12.4