How can I make the <InfiniteScroll> and <Deferred> components work together? #2621
Replies: 5 comments 2 replies
-
|
I think there are two issues with this. Firstly, the problem with this Inertia::defer(fn () => Inertia::scroll(fn () => ItemResource::collection($items)))is that the first closure you are passing to Inertia::defer is returning another closure, and that does not work. The first closure will need to return the data for Inertia to serialize and pass to the frontend. If the first closure returns another closure, Inertia will not execute the second closure, and hence you see nothing on the frontend. You could verify this with something simpler like this: Inertia::defer(fn () => fn () => 'Hello')As a workaround, you could explicitly call the second closure like so: Inertia::defer(fn () => (Inertia::scroll(fn () => ItemResource::collection($items))())Secondly, on the frontend, the deferred prop is not appended to the page's scrollProps. If you inspect |
Beta Was this translation helpful? Give feedback.
-
|
Same problem, no way to use deferred props with InfiniteScroll |
Beta Was this translation helpful? Give feedback.
-
|
any luck with that? I've switched to infinite scroll and now lost my skeleton deferred loaders which annoys me |
Beta Was this translation helpful? Give feedback.
-
|
As a workaround I've ended up using Inertia::defer with deepMerge:
with a custom IntersectionObserver on frontend: so my final frontend code looks like this: it seems to do the job for now and I did not see any issues for now |
Beta Was this translation helpful? Give feedback.
-
|
You can use Inertia::scroll(...)->defer() |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I want to defer data loading and merge it later
My first idea was to use something like:
Inertia::defer(fn () => Inertia::scroll(fn () => ItemResource::collection($items)))But the deferred request returns an empty result.
Beta Was this translation helpful? Give feedback.
All reactions