fix(session): age flash values at the start of the request#2198
Open
osbre wants to merge 2 commits into
Open
Conversation
Benchmark ResultsComparison of Open to see the benchmark results
Generated by phpbench against commit 27c5ee6 |
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.
Closes #1734. Addresses #210.
Problem
A flash value is meant to live for one request and then go away.
The old logic removed a flash value once it was read. But the cleanup happened before the view was rendered - and views are often where the value is actually read (for example, the default form and input components). By then it was too late: the value was already saved back into the session, so it showed up again on the next request.
And if a flash value was never read, it was never removed at all.
Fix
Instead of expiring flash values at the end of the request, expire them at the start:
Reads no longer affect this, so a flash value stays readable for the whole request, including whilst the view renders, and is reliably gone on the next one.
The session is still saved right away. This is a bit different from the idea in #210 (removing once the response is sent): expiring at the start of the next request gives the same result without deferring any work, and doesn't change the public API.
Notes
Three tests checked the old read-based timing (
flash()then a singlecleanup()); they now check the two-request lifecycle. A new test covers a flash value expiring even when it's never read.