Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Defer Prop #623

Closed
wants to merge 5 commits into from
Closed

Add Defer Prop #623

wants to merge 5 commits into from

Conversation

adrum
Copy link

@adrum adrum commented May 15, 2024

Recreating this PR due to the master branch deletion. If the previous PR was closed on purpose, I apologize for the noise.

Original description: I felt inspired by Livewire 3 Lazy feature which automatically fetched the data on page load. I think there's a ton of value in Inertia's current Lazy prop feature, but I think there are also scenarios where adding a Defer prop feature which automatically loads Lazy data on page load.

This works in tandem with inertiajs/inertia#1617. It works by extending the Lazy feature but also informs the front-end on page load which deferred properties should be loaded automatically. These properties will then automatically trigger a reload with those properties automatically added in the only attribute.

This reduces the amount of front-end code required to pull this off. To add a long-running API query to be deferred, it would look like this:

return Inertia::render('Organizations/Index', [
            'filters' => Request::all('search', 'trashed'),
            'organizations' => Inertia::defer(
                fn () =>
                Auth::user()->account->organizations()
                ->orderBy('name')
                ->filter(Request::only('search', 'trashed'))
                ->paginate(10)
                ->withQueryString()
                ->through(fn ($organization) => [
                    'id' => $organization->id,
                    'name' => $organization->name,
                    'phone' => $organization->phone,
                    'city' => $organization->city,
                    'deleted_at' => $organization->deleted_at,
                ])
            ),
        ]);

These deferred properties will only ever be loaded automatically after page loads/navigations. Otherwise, they behave just the same as Lazy props.

@reinink
Copy link
Member

reinink commented May 27, 2024

@adrum Really appreciate you sharing this idea, but I'm going to close this one for now for the reasons stated in your other PR:

inertiajs/inertia#1617 (comment)

Once we've figured out an async story in Inertia I'd plan to loop back to this 👍

@reinink reinink closed this May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants