Simple SSR server redirect not working
I've found a few similar questions with auth redirects, and I thought I've ticked all the boxes, but I still can't get a server redirect happening as soon as there's an await.
Everything works, response is logged properly, but the <div> still loads. As soon as I remove the fetch, the redirect works. I've tried with/without <Suspense>, reading/not reading the routeData, throwing or returning the redirect.
To replicate,
- create a new solid start typescript/tailwind project.
- create blah.tsx in /routes and paste in:
- navigate to
http://localhost:3000/blah
, see the response logged, and also see the forbidden <div>
with no redirect. What am I missing!?10 Replies
Set the
deferStream
property on createServerData$ to true
also throw redirect
is best inside routedata
e.g. in my own app, I have something like
and in terms of usage, you need to access routeData, but don't have to actually save it or log anything from it, e.g. useRouteData<typeof routeData>();
by itself is good enoughI hadn't tried
deferStream
, but just did and things still aren't redirecting!
I see both the logs, as well as the <div>
on page load....in entry-server.tsx, are you using renderAsync or renderStream?
I'll create a brand new ss project now just to make sure it's not a project issue...
Instead of <div>Nope!</div>, try
Also yeah-data has to be invoked to trigger suspense
I get nothing with the
<Show>
in your test case here, you call
data
, but don't actually read it, as you should have data()
so nothing renders?nope, blank page
well that is good, possibly
hm
not sure why it isn't redirecting
Here is a snippet of code that had fixed this issue for me in the past: https://discord.com/channels/722131463138705510/910635844119982080/1011688878983348245
Just did a new project, and with the
<Show when={data()}>
it does redirect... but yeah you were right, the ()
and deferStream
were the missing pieces... that said, my project still doesn't redirect.
Sooooo, something is up with my project.
Thanks for the link as well, that's super helpful