Skip to content
New issue

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

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

Already on GitHub? # to your account

Session-based shared data not refreshing between Inertia navigations (asset versioning) #711

Open
l0n3s0m3-w0lf13 opened this issue Feb 6, 2025 · 0 comments

Comments

@l0n3s0m3-w0lf13
Copy link

Hi! I’m using Laravel + Inertia + Vue and sharing some session-based data as global props via HandleInertiaRequests. The issue is that after I update this session data on one page and then navigate to another, the page.props does not reflect the changes unless I perform a full page refresh (F5) or call .reload() manually.

My data is purely in session, and I’d like it to stay updated across navigations without forcing a full page reload.

Here’s a simplified example:

// app/Http/Middleware/HandleInertiaRequests.php
public function share(Request $request): array
{
    return array_merge(parent::share($request), [
        'mySessionData' => $request->session()->get('mySessionData', []),
    ]);
}

// Controllers that set/modify the session
public function updateSessionData(Request $request)
{
    session()->put('mySessionData', $request->input('foo'));
    return to_route('somewhere');
}

And on the frontend:

<script setup>
import { usePage } from '@inertiajs/vue3';

const page = usePage();
</script>

<template>
  <div>
    <p>My session data: {{ page.props.mySessionData }}</p>
    <!-- ... -->
  </div>
</template>
  • After session()->put('mySessionData', ...), the props do not automatically refresh in subsequent page visits.
  • I looked into asset versioning and tried overriding version() in HandleInertiaRequest to include a hash of the session data, which works a priori but breaks the performance of Inertia Modal for my use case and doesn’t feel like the cleanest solution.
  • Forcing a reload works but causes a flicker, and I’d like to avoid that.

Any advice would be greatly appreciated!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant