Skip to content

[6.x] Fix toasts breaking when sessions are serialized as JSON - #15015

Merged
jasonvarga merged 1 commit into
statamic:6.xfrom
mynetx:fix/toast-json-serialization
Jul 15, 2026
Merged

[6.x] Fix toasts breaking when sessions are serialized as JSON#15015
jasonvarga merged 1 commit into
statamic:6.xfrom
mynetx:fix/toast-json-serialization

Conversation

@mynetx

@mynetx mynetx commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Fixes #14797.

Flashing a toast and redirecting, like this:

Toast::success('Success!');

return Inertia::back();

made the next request receive _toasts: [[]] and throw Uncaught TypeError: this[type] is not a function in the console instead of showing the toast.

The toast manager flashes Toast objects into the session. When the response is a redirect, the toast has to survive session persistence into the next request. Laravel supports serializing session data as JSON (session.serialization), and current app skeletons ship 'serialization' => 'json' as the default. Toast only has private properties and didn't implement JsonSerializable, so json_encode() turned it into {}, which decoded back to an empty array on the next request. Flows that deliver toasts in the same response (like saving an entry) never round-trip through the session, which is why they were unaffected.

This makes Toast implement JsonSerializable, so it survives the round-trip. Sessions serialized with the php strategy are unchanged, and the fluent ->duration() chaining after push keeps working since the session still holds the object itself.

Verified in a live CP with JSON session serialization: before, the follow-up request's _toasts prop was [[]]; after, it's [{"message":"Sandbox toast test","type":"success","duration":null}] and the toast displays.

🤖 Generated with Claude Code

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@jasonvarga
jasonvarga merged commit e5fff43 into statamic:6.x Jul 15, 2026
20 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.

Server-side Toasts with a redirect creates a JS error

2 participants