[6.x] Fix toasts breaking when sessions are serialized as JSON - #15015
Merged
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #14797.
Flashing a toast and redirecting, like this:
made the next request receive
_toasts: [[]]and throwUncaught TypeError: this[type] is not a functionin the console instead of showing the toast.The toast manager flashes
Toastobjects 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.Toastonly has private properties and didn't implementJsonSerializable, sojson_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
ToastimplementJsonSerializable, so it survives the round-trip. Sessions serialized with thephpstrategy 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
_toastsprop was[[]]; after, it's[{"message":"Sandbox toast test","type":"success","duration":null}]and the toast displays.🤖 Generated with Claude Code