Enhancing Lazy Loading and Merge Functionality in Inertia v2 #2059
Unanswered
HichemTab-tech
asked this question in
Help (React)
Replies: 1 comment
-
Well after second thinking i would go with the second proposition which is to add a prop <Deferred fallback={<div>Loading....</div>} data='items'>
{items?.length ? items.map((item) => (
)) : (
<div className="flex items-center justify-center h-full text-gray-500">
No items available
</div>
)}
{items?.length > 20 && (
<WhenVisible
fallback={(
<SpinnerWithRetry/>
)}
data='items'
/>
) || null}
</Deferred> but like this i explicitly said that the offset is 20 and it's not dynamic so like i said the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
💬 Enhancing Lazy Loading and Merge Functionality in Inertia v2
🔍 Overview:
We have two new components in Inertia v2:
WhenVisible
andDeferred
. TheWhenVisible
component triggers a request and loads data when the corresponding HTML becomes visible (commonly used for infinite scroll scenarios). TheDeferred
component, on the other hand, defers loading data until after the page has initially loaded, while displaying a loading state. On the backend, we have thedefer
method to handle deferred requests, and themerge
method to allow merging new data with existing data.I need to achieve a "merged but deferred" behavior with the
WhenVisible
component. Here's the problem:Deferred
).WhenVisible
, the request executes directly the first time because no data is initially loaded on the frontend. This defeats the purpose of deferring until visibility.lazy
method skips initial data loading, which works as needed here, but it doesn't support merge.Deferred
withmerge
works, but it requires placing theWhenVisible
component inside aDeferred
component. This results in theWhenVisible
request being triggered only after the deferred data loads, which is redundant and suboptimal.💡 Proposed Solutions:
Add a Merge Option to
lazy
Method: Enhance thelazy
method on the backend to support themerge
behavior, making it more suitable for infinite lists that should load in a deferred manner.This example shows how the
lazy
method could be extended to include amerge
option, allowing new data to be added to the existing dataset rather than replacing it entirely. This would be useful for scenarios where the list is dynamically loaded (e.g., infinite scrolling).Customize
WhenVisible
to Ignore First Trigger: Add a customization option forWhenVisible
to not execute on the first render if the data is already present, allowing more control over when the data should be fetched. This is particularly useful when we have initial data loaded on the page and want to avoid an unnecessary request on the first trigger.In this example, the
WhenVisible
component is configured with thealways
prop which allow it to execute the request on each reach of whenvisible .🔄 Recap of Needs:
Deferred
), but also support merge for dynamic extension of the data.lazy
,merge
,WhenVisible
,Deferred
) don't quite provide the desired combination without cumbersome nesting or redundant requests.Would ❤️ to get thoughts from the team on how we could address this. Is adding
merge
tolazy
a feasible enhancement, or can we introduce more control in theWhenVisible
component?Beta Was this translation helpful? Give feedback.
All reactions