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

Session messages not removed properly - persist across multiple requests #10107

Closed
epson121 opened this issue Jun 30, 2017 · 12 comments
Closed
Labels
bug report Component: Catalog Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed

Comments

@epson121
Copy link

Preconditions

Magento CE 2.1.5 (experienced in 2.1.7 as well) with sample data in Google Chrome

Steps to reproduce

  1. Customer opens a product page
  2. Customer sets quantity to a high number
  3. Customer clicks "Add to cart"
  4. Page refreshes, and a message is displayed "We don't have as many ... as you requested"
  5. Customer refreshes page again, or navigates to another page (category, product, homepage)

Expected result

Message "We don't have as many ... as you requested" should not be displayed on the next request

Actual result

Message "We don't have as many ... as you requested" is displayed on the next request

Workflow that causes this issue:

  1. POST request to checkout/cart/add is made
  2. since there is not enough of the item in the stock, backend logic performs a redirect back to product page (vendor/magento/module-checkout/Controller/Cart/Add.php:149), and a cookie "mage-messages" is set with message: "We don't have as many ... as you requested"
  3. redirect performs a GET request to the same URL (product page)
  4. response is received, and message is displayed to a customer
  5. XHR GET request is performed to "review/product/listAjax/id/[some_id]" and its request headers contain "mage-messages" cookie, with message in it
  6. vendor/magento/module-theme/view/frontend/web/js/view/messages.js script is triggered on frontend, and "mage-messages" cookie is cleared
  7. XHR response is received (from step 6.), and due to backend logic in vendor/magento/module-theme/Controller/Result/MessagePlugin.php:82, "mage-messages" cookie value is returned as received which causes "mage-messages" cookie to revert back to the state where it contains a message.
  8. Upon refresh or navigating to a new page, same message is displayed again

So basically we have a race condition where cookie is set (with message), then it is removed via messages.js script, and then again set by returning XHR response that was sent before cookie was removed.

Workaround:

copy vendor/magento/module-theme/view/frontend/web/js/view/messages.js to your theme file, and at the end of initialize function add:

$(window).on('beforeunload', function(){
    $.cookieStorage.set('mage-messages', '');
});
@ivanweiler
Copy link

Same behavior here (message won't go away), also with success messages on default M2 2.1.7 with sample data, tested on Chrome and Firefox.

You click "Add to Cart" on product page, submit (not ajax on default 2.1.7), you end up back on product page + success message. When you navigate away from product page, or refresh product page, you'll get same message again. That is, if messages.js is executed before review ajax comes back as @epson121 explained, which happens most of the time.

For the same reason, sometimes if you click Add to Cart multiple times, success messages are stacking :)

screenshot at 2017-06-30 12-29-03

@1408sheva
Copy link
Contributor

HI @epson121. I cannot reproduce this issue. Please add more details to your description of the steps you followed when identifying this issue. Screenshots, video or logs would be helpful, too.
My video to reproduce https://youtu.be/OH35yqneD50

@sabarivenkatesankrish
Copy link

Hi all, I am also facing the same issue in Magento 2.1.7. Here is the video link for reproducing this issue. https://www.useloom.com/share/0c7a9812101c44a3b61f259fb0a3f39c

@1408sheva
Copy link
Contributor

Hi, @sabarivenkatesankrish. Unfortunately, I could not reproduce the issue as you described it.

@sabarivenkatesankrish
Copy link

sabarivenkatesankrish commented Jul 18, 2017

Hi, @1408sheva. I just installed Magento 2.1.7 package from repo.magento.com through the composer. I have also installed sample data. Apart from this, I did nothing. I have disabled the cache for ensuring the cache issue. I changed the session storage to "db" instead "files". But Still this exist. As of my knowledge it might not be a cache related issue. It could be a session related issue. I am not sure that the problem with the package. It may be from my end. But I can't able find. Any suggestion would be appreciated.

@magento-engcom-team magento-engcom-team added Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed and removed Progress: needs update labels Sep 18, 2017
@magento-engcom-team
Copy link
Contributor

@epson121, thank you for your report.
We were not able to reproduce this issue by following the steps you provided. If you'd like to update it, please reopen the issue.

@magento-engcom-team magento-engcom-team added the Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch label Sep 20, 2017
@dgpoo
Copy link

dgpoo commented Jan 4, 2018

I have resolve isssue from below referance link:
https://community.magento.com/t5/Technical-Issues/Error-Success-message-not-showing-on-one-page-in-custom-module/td-p/72823

I was using

<script type="text/x-magento-init">

for the javascript validation.
I changed it to

`<script type="text/javascript">`

@LuoLily
Copy link

LuoLily commented Aug 27, 2018

Need to flush and enable cache.

@Eddcapone
Copy link

I still have this bug in 2.4.2 Enterprise

@codecodeio
Copy link

I also still have the issue in Magento 2.4.2-p1 Enterprise. The solution provided by @talalus worked for me.
#5301 (comment)

@NguyenXuanNam
Copy link

I also still have the issue in Magento 2.4.2-p1 Enterprise. The solution provided by @talalus worked for me. #5301 (comment)

i'm already added this line before that's why it works fine in desktop, but I don't know why it didn't work on mobile devices(not emulator)

@Minirock
Copy link

This seems to be still valid in 2.4 commerce...any updates ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Catalog Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed
Projects
None yet
Development

No branches or pull requests