How to get 'client side' createResource behavior in SolidStart?
I noticed that if I don't have Suspense component in SolidStart, the whole page refreshes and
createResource
loading state doesn't render at all.
For example if use this snippet from regular docs in solidstart project:
It will not show loading text at all, just the whole page refreshes when typing to input.
This is quiet confusing when coming from normal SolidJS, that createResource loading
etc are now useless.
Thanks!38 Replies
it might be because start lazy loads routes which changes some of the async behaviours, best to just wrap your whole app in Suspense so that it's consistent
@Brendonovich how would you do the snippet I pasted above? If I wrap whole thing in Suspense then the input still disappears
when typing to
input
IMO, createResource cannot be used for interactivity anymore
there needs to be some createClientResource
or somethingbecause
user()
will re-suspend each time it refetchesyou can use
user.latest
which doesn't suspend after the first run
or wrap the setUserId
call in startTransition
so that user()
shows the previous value while fetching the next oneOkay I'm trying to understand, however I think the docs need updating, if some of the examples don't work as intended with SolidStart
where would I put the
user.latest
I also tried:
I don't think it works either
I like that SolidStart can be used to hydrate, but breaking createResource
beyond recognition seems like too much to take at once.
We need some way to toggle between old behavior for createResource and newUse .latest instead of calling user
I see like this:
then it refreshes whole page on first change of input
but subsequent change works
Code looks like this at the moment:
screen goes white for 2 seconds on first change of input
but after that it works reactively
I think it is easier to make own
createResource
Oh because nothing would have been fetched on initial load
Try providing an initialValue to the createResource
I'm cooking my own
createClientResource
I don't yet understand this whole thingThe behaviour that you’re observing is how createResource is supposed to work, it’s expected that there is a Suspense boundary regardless of Start
Or even easier just set a default value for userId
Create the signal with an empty string
I'm not sure about this, why would docs have this exact example, that is so broken?
Though that’ll suspend the page on initial load
That code is frist example here: https://docs.solidjs.com/guides/fetching-data#using-createresource
That example is super barebones, are you doing it in app.tsx or in a route?
Im doing it in my own component
that is added to index.tsx of page
in solidstart
So in a route?
that
TestFetch
is my component
with that createResource exampleYeah I’m just wondering if you’re doing so in a route or in the root level app.tsx
that is index.tsx from solidstart template
Ok so probably route
routes/index.tsx
That basic example assumes there’s no lazy loading, no suspense, super barebones. Id guess that start’s lazy loading messes with resources when no Suspense is present
Note that the example isn’t part of the start docs, it’s part of the plain solid docs
yeah, I know 🙂
that's the whole premise, I'm coming from solidjs and trying to use solidstart
Provide an initialValue to the createResource and it should work as you expect
this also works:
Can’t say I’m a fan of it but whatever works
I don't think I like it either 😄
I provided initialValue but it still blinks
I forgot user.latest
Okay! It works with initialValue and user.latest hack
Thanks @Brendonovich I now have to think how all of this works
user() will suspend whenever a new fetch happens, user.latest will suspend on only the first fetch and only if there isn’t a default
solidstart handles suspends somehow differently from regular old solidjs
did you have a Suspense in the non-start version?
if you did i think it'd behave the same
I don't think I did
inside router or startserver there is suspense?
No, but routes do get lazy loaded which could mess with things
Try doing that same example in
app.tsx
insteadhey! it works in app.tsx
When I use the original code inside TestFetch
Yeah checks out
and I see, the original app.tsx has suspense
that is solidstart's app.tsx
it has already Suspense
Ah yeah the non-bare templates do
If I remove it, SolidStart freaks out