Flash messages discarded unless kept #1374
Merged
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.
Purpose
Fixes #1271
Description
Previously, flash messages written to the session by default and used in the next request. That led to seeing flashes twice if both requests rendered HTML. Now, we only pass flash messages onto the next request if
flash.keep
is called. Luckily, we call that when actions redirectlucky/src/lucky/redirectable.cr
Lines 122 to 124 in cff93b3
So, the two scenarios should be covered to avoid flash message duplicates. If flashes are set in an action that immediately renders HTML then they are discarded after, but if the action redirects the flash messages will carry over and continue carrying over until HTML is rendered.
I'm slightly wary of this because we are depending on code scattered across the library but I believe this is better than what we have right now.
Checklist
crystal tool format spec src
./script/setup
./script/test