hanami / controller

Complete, fast and testable actions for Rack and Hanami

Home Page:http://hanamirb.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Regression: Return of the double-flash bug

nerdinand opened this issue · comments

It seems #196 has returned to haunt us.

Here's a minimal test app to reproduce this:
flash_test.zip

  1. Visit http://localhost:2300/. You will see:
    20180423_121750
  2. Click on Edit. You will see a form:
    20180423_121850
  3. Click on Save. As expected, the form will render again and show the success flash message:
    20180423_121943
  4. Click on Cancel. The root page will render but show the flash message again!
    20180423_122043

Expected behaviour: The root page renders without showing the flash message.

As with #196, adding

before { flash.clear }

to the index action is a workaround.

I'm having a look at this one.

Looks like the current behavior store the flash from the last request I imagine is to access it for redirects.

Maybe we can have a way of marking when a value has been accessed, and since flash message are meant for one use we could delete then in the next iteration.

WDYT? @jodosha

I have looked into a little more looks like the behavior is different depending on a redirect or a new request.

By adding this to the Update action from the sample app:

def call(params)
  flash[:success_notice] = "Saved successfully."
  self.status = 201
  redirect_to '/'
end

Works as expected. I understand that works as expected because since we are doing another request, the @last_request_id and the @request_id are updated, and in the last request the Hanami::Flash consider that flash stale and delete it.

@jodosha I'm guessing the users need to experience same behavior is they are using redirect or normal request cycle, right?

@nerdinand we have confirmed that problem exists. Thank you for opening the issue ❤️

We are working on the solution. I will try opening a PR ASAP.

Fixed by #267