SolidStart layout shifts using createAsync
Hi, I found out that I experience layout shifts whenever a createAsync is re-triggered.
For example here:
I have a "middle div" colored in red here. Whenever I change one of the params (such as page or search filters), the createAsync is retriggered. But while it does that the middle part (in red) disappears for a split second and the page is re-scrolled back up. This makes using the pagination very obnoxious. Has anyone ever experienced that ? I don't understand why in this case it is needed for Solid to re-render the whole div each time.
21 Replies
That's probably because the Suspense fallback gets shown while the
createAsync
refetches
You can either wrap the setParams
call with startTransition
or use the latest
field of data
instead of calling ituse the latest field of data instead of calling itThank you a lot ;) Im wondering also if I should at all use a Suspense to show loading since the page won't be shown before it has finished loading the createAsync server side
That would only apply for the first load - if you navigate there from another page then the suspense may be shown
I'd recommend keeping the Suspense
Nah, it just wait before it has finished loading on my side
Ah if you don't have a suspense then that might happen
The suspense is still there
I don't see one around Pagination so that might be it
I only changed this :
Following your recommendations
If the
Pagination
component is calling pagination()
then that's also a place that can suspend
Since it accesses data
For my pagination I use those:
Add a
Suspense
around main
and the navigation from another page should be instant instead of waitingMmh I see
That did work, nice
The idea is that navigation happens inside a Transition, and since an existing Suspense somewhere higher up in your app is being triggered by accessing
data
, the Transition pauses the navigation until the Suspense resolvesYeah maybe I'll add a big suspense above everything, even with multiple asyncs I guess its better than having the layout load in multiple steps
Yeah it's entirely up to you, you can add and remove Suspense in different places to achieve different styles of loading states
When you add the Suspense around
main
the data
access is then caught by that brand new Suspense that doesn't have any previous UI to show, rather than an existing Suspense that can keep showing the route you're navigating from
So it navigates instantly and you see the suspense fallback🫡
I'm going out of scope but shouldn't the loading be instant since I use
cache
?
I have added a Bun.sleep here just to see the loading suspense, but shouldn't it just skip thins function alltogether ?No? It's still gotta run the function -
cache
is per-request, not a global cacheOh I thought so
Anyway it seems like its deprecated but query should work the same I guess
Ye same thing different name
So it would only help if I called the function multiple times during the same request, like a parent and child component both calling it ? If I understand
Yeah