Skip to content

[6.x] Fix toasts being replayed on partial reloads - #15210

Merged
jasonvarga merged 1 commit into
statamic:6.xfrom
heidkaemper:fix/toast-replay-on-partial-reload
Aug 18, 2026
Merged

[6.x] Fix toasts being replayed on partial reloads#15210
jasonvarga merged 1 commit into
statamic:6.xfrom
heidkaemper:fix/toast-replay-on-partial-reload

Conversation

@heidkaemper

Copy link
Copy Markdown
Contributor

This PR fixes a problem where toast messages on Inertia CP pages are replayed on every partial reload. We ran into this on a custom page that polls a queue via usePoll(5000, { only: [...] }) after a form.post() redirect. The success toast reappeared every 5 seconds until navigating away.

The problem: _toasts is shared as a regular Inertia prop, but it is flash data. Partial responses only contain the requested props, and Inertia merges them into the existing page props. So a stale _toasts survives every partial reload, and the success listener in Toasts.js re-displays it each time.

To reproduce the problem: Flash a toast on any CP page that uses usePoll(…, { only: [...] }).
See "Reproduction Code" down below.

The fix removes the prop from the page props once the toasts have been displayed, so a later partial reload has nothing left to replay.

An alternative approach would be to change toasts logic to Inertia's flash data (Inertia::flash()). But that requires inertia-laravel >= 2.0.16 and touches the initial page load path (displayInitialToasts()). So it felt a bit too big of a change for this bugfix.


Reproduction Code
// routes/cp.php
Route::get('toast-repro', fn () => Inertia::render('toast-repro/Index', ['time' => now()->toTimeString()]));
Route::post('toast-repro', fn () => redirect('/cp/toast-repro')->with('success', 'Flashed once'));
<!-- resources/js/cp/pages/toast-repro/Index.vue -->
<script setup>
import { router, usePoll } from '@statamic/cms/inertia'

defineProps({ time: String })

usePoll(3000, { only: ['time'] })
</script>

<template>
    <div>
        <p>{{ time }}</p>
        <button @click="router.post('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/cp/toast-repro')">Flash a toast</button>
    </div>
</template>
// resources/js/cp/cp.js
import Index from './pages/toast-repro/Index.vue'

Statamic.$inertia.register('toast-repro/Index', Index)

Click the button: expected is one toast, actual is a toast every 3 seconds

@jasonvarga
jasonvarga merged commit ead20fa into statamic:6.x Aug 18, 2026
62 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.

2 participants