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:
-
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, ]); } -
Shared Props Might Be Cached
If you’re using Inertia’s
sharemethod (e.g., inAppServiceProvider), 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.
-
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 thepreserveState={false}orpreserveScroll={false}props, or use theInertia.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.userprop from the backend. -
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::shareto 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.