Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

joaofarias's avatar

Props problem with inertia

Hello i'm using a laravel starter kit with inertia + react and figured out that i have a problem here, when i update some info and go to another page sometimes that info its lost. for example if i update my name and go to dashboard, it displays the old name. only if i refresh the page it shows me the updated info.

This happens with all props but not every time, just sometimes. if someone could help me i would appreciate.

0 likes
1 reply
LaryAI's avatar

This issue is commonly related to how Inertia handles client-side navigation and how your backend returns updated props. When you update user information (like your name), but navigate to another page without a full reload, Inertia will use the data returned from your backend for that page. If your backend is still returning stale data (e.g., from a cached user object or session), the frontend will show the old info until you refresh.

Possible Causes and Solutions:

  1. Ensure Backend Returns Fresh Data

    After updating user info, make sure your backend controller returns the latest user data. For example, if you update the user in a controller, fetch the updated user from the database before returning the Inertia response:

    public function update(Request $request)
    {
        $user = auth()->user();
        $user->update($request->only('name'));
    
        // Fetch the latest user data
        $user->refresh();
    
        return Inertia::render('Dashboard', [
            'user' => $user,
        ]);
    }
    
  2. Shared Props Might Be Cached

    If you’re using Inertia’s share method (e.g., in AppServiceProvider), make sure you’re always returning the latest data:

    Inertia::share([
        'auth.user' => function () {
            return auth()->user() ? auth()->user()->only('id', 'name', 'email') : null;
        },
    ]);
    

    Using a closure ensures the latest user data is fetched on every request.

  3. Force Inertia to Reload Props

    If you navigate using Inertia’s <Link> component, it will not reload props unless you tell it to. You can use the preserveState={false} or preserveScroll={false} props, or use the Inertia.reload() method to force a reload.

    Example (React):

    import { Inertia } from '@inertiajs/inertia';
    
    // After updating user info
    Inertia.reload({ only: ['auth.user'] });
    

    This will reload only the auth.user prop from the backend.

  4. Check for Client-Side State Caching

    If you’re storing user info in React state or context, make sure you update it after a successful update, or rely on Inertia props instead of local state.


Summary Checklist:

  • Always return fresh data from your backend after updates.
  • Use closures in Inertia::share to avoid stale shared props.
  • Use Inertia.reload() if you need to force a prop refresh.
  • Avoid unnecessary client-side caching of props.

If you follow these steps, your updated info should appear immediately after navigation without needing a full page refresh.

Please or to participate in this conversation.