Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flash messages discarded unless kept #1374

Conversation

matthewmcgarvey
Copy link
Member

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 redirect

def redirect(to path : String, status : Int32 = 302) : Lucky::TextResponse
# flash messages are not consumed here, so keep them for the next action
flash.keep

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

  • - An issue already exists detailing the issue/or feature request that this PR fixes
  • - All specs are formatted with crystal tool format spec src
  • - Inline documentation has been added and/or updated
  • - Lucky builds on docker with ./script/setup
  • - All builds and specs pass on docker with ./script/test

Copy link
Member

@jwoertink jwoertink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nice. This makes sense to me 👍 And good call on the redirect since we already have flash.keep in there.

@matthewmcgarvey matthewmcgarvey merged commit f28331c into luckyframework:master Dec 28, 2020
@matthewmcgarvey matthewmcgarvey deleted the matthewmcgarvey/issue1271 branch December 28, 2020 23:03
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.

Flash messages are always displayed for 2 requests
2 participants