Skip to content

Conversation

@pascalbaljet
Copy link
Member

@pascalbaljet pascalbaljet commented Dec 3, 2025

This PR introduces once props. Some data rarely changes, is expensive to compute, or is simply large. Rather than including this data in every response, once props are remembered by the client and reused on subsequent pages that include the same prop.

return Inertia::render('Billing', [
    'plans' => Inertia::once(fn () => Plan::all()),
]);

You may share once props globally using the Inertia::share() method.

Inertia::share('countries', Inertia::once(fn () => Country::all()));

Or use the shareOnce() helper method.

Inertia::shareOnce('countries', fn () => Country::all());

You may also define a dedicated shareOnce() method in your middleware.

public function shareOnce(Request $request): array
{
    return [
        'countries' => fn () => Country::all(),
    ];
}

The once() modifier may be chained onto defer(), merge(), and optional() props.

return Inertia::render('Dashboard', [
    'permissions' => Inertia::defer(fn () => Permission::all())->once(),
    'activity' => Inertia::merge(fn () => $user->recentActivity())->once(),
    'categories' => Inertia::optional(fn () => Category::all())->once(),
]);

You may force a once prop to be refreshed using the fresh() method. This method also accepts a boolean, allowing you to conditionally refresh the prop.

return Inertia::render('Billing', [
    'plans' => Inertia::once(fn () => Plan::all())->fresh(),
]);

You may set an expiration time using the until() method. This method accepts a DateTimeInterface, DateInterval, or an integer (seconds).

return Inertia::render('Dashboard', [
    'rates' => Inertia::once(fn () => ExchangeRate::all())->until(now()->addDay()),
]);

You may assign a custom key using the as() method. This is useful when you want to share data across multiple pages while using different prop names.

// Team member list...
return Inertia::render('Team/Index', [
    'memberRoles' => Inertia::once(fn () => Role::all())->as('roles'),
]);

// Invite form...
return Inertia::render('Team/Invite', [
    'availableRoles' => Inertia::once(fn () => Role::all())->as('roles'),
]);

Client-side PR: inertiajs/inertia#2732

@michaelnabil230
Copy link

Hey @pascalbaljet,

I just wanted to say that I really appreciate the work you did on this. It looks fantastic!

I'd also appreciate it if you could mention my name in the commit/PR description when referencing the parts I contributed, just so my work can also be recognized.

Thanks again!

@pascalbaljet pascalbaljet merged commit 9170201 into 2.x Dec 9, 2025
46 checks passed
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.

3 participants