A @tanstack.com start design question ( @tannerlinsley.com @tkdodo.eu ) Why do you have to THROW a redirect instead of (early) returning it? tanstack.com/start/latest... Throw is commonly supposed to handle an erroneous situation. Redirect doesn't seem like one. TIA for response!
Post
tanstack.comServer Functions | TanStack Start React DocsWhat are Server Functions? Server functions allow you to specify logic that can be invoked almost anywhere (even the client), but run only on the server. In fact, they are not so different from an API...
"Well for one it doesn't mess with the types." Do you mean that server functions can ignore returning the redirect? If so, IMO that's not a good thing, as it'll bring more confusion. Looking at a limited return type you won't expect a behavior that's baked in by design. Explicit > Implicit.
0 reposts0 likes
I think I was using Remix a few years ago and I returned a redirect and some data. Now in the code I had to check if the response was a redirect, but the way redirects work your code in the frontend for that redirect won't run because the redirect has interrupted it and moves the flow to another url