deferStream does not work
this works when coming from an initial request (server) but not from a <a>
i expected it to work on client like server
why is it like this?
45 Replies
You can't return early in solidjs components
Try
can you explain "return early"?
what it means, is that components are run once
if you "return early"
when something changes in the component body
it is not going to rerun the component and allow you to return from a different return in the function
you should have a single return in a component to avoid this
@Trader101 does that fix one of your issues?
why would i need it to rerun
ok, I might miss understood the original question
I was answering in a more general sense
is that your problem or Thomas problem who can verify what works ?
Madaxen's solution worked
Thomas also needed deferStream redirects to work client-side i think
ok, yeah so I think the single return advice is still good
yeah but i wanted it to actually click, not just keep it as a rule in my mind
ok, if you remove the redirect logic I can help explain it in a more simple way, is that something you interested in ?
yes
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
Maybe this helps:
The components body is not a reactive context - meaning it will not update on signal changes.
Reactive contexts are:
- functions
- createMemo, createEffect, createComputed, ...
- JSX
By reading the signal here
The reactivity is broken. It's kind of the same as
i understand this, but why do i need reactivity in that example? i thought deferStream makes the value already available
lol, i guess, I wasn't clear, I can explain the basic of why the double return in solid fail
excludin the logic for the redirect / deferStream
maybe @Madaxen86 can expand on that
like a signal that has an initial value:
becomes:
Well deferStream means "don't stream a response to the client until the async is resolved"
But it will not prevent the component to render with the default "undefined" value or whatever is in the query cache.
And because reactivity is broken the rendered JSX of the initial render will be returned.
In a nutshell:
In Solid no early JSX returns. Make conditional JSX instead with
Show
or Switch + Match
so why does the page freeze with deferStream?
because it waits until the value is not undefined?
I think I get it, there is no reactivity in solid server side .
whatever value you have in the signal that is what it will work with
this is logging undefined then true
so, thats "reactivity" whatever reactivity means
yeah, this is promise resolving.
so i guess I still not getting the problem you are having
but even
console.log("yes");
logs twice
i have no problem, but i wanna understand regardless :)sure let me see if I can understand this
ok I am starting to understand it
"But it will not prevent the component to render with the default "undefined" value or whatever is in the query cache." https://discord.com/channels/722131463138705510/1398301947760480306/1398348330882437250
thinking ...
but that's exactly what deferStream does!
ok I get it now
I have 0 issues rn with solid but thanks 👍
yep, i'm trying to understand how both reactivity and deferStream work together, they seem contradictory to me, since deferStream guarantees for you that the query will have its value the first time its used
ok follow me
1. components run once
2.
shouldRedirect
initial value is undefined
3. based on rule 1
Home() will run once, and only once
4. it will be falsy, because undefined
and will return on
return <>why are you here</>
5. deferStream, will hold off the response until the async is resolvedif that's true even with deferStream, my redirect shouldn't work, but its working
6. but Home is already rendered
i'm basically doing "why is it working" here 🤣
not why its not working
you broke the chain lol
.
if its logging undefined, isn't it too late for the server to redirect?
7. the redirect is probably at the client side
no, i checked
just so i understand when you load the page
do you see
<>why are you here</>;
?no
you get the not found page
this is the working code
but what i'm wondering about is
how it's logging undefined and yet its not too late to redirect on the server
that's all
this logs on the server both undefined and true?
to test if it redirected on the server correctly:
yes
ok , so looks like solid might be reevaluating the Home function ?
unless it is the client making the api call ?
but no actually
if it was just an innocent reevaluation it'd log true true instead of undefined true
the log is outside
true
but put another log , it might be able to cache the async
I am just speculating
yeah ok so it does re run the function on the server
mystery solved