Magento 2 – Fix Customer Notifications Not Disappearing

customermagento2

I am facing a problem, when customer enters incorrect username/password, error message appears below the navigation bar which does not disappear even after refreshing the page. When the customer navigates to another page, that message shows on that page too. Another thing, when the customer enters multiple times incorrect username/password then this error message list increases.

My cache is enabled and mode is default. What to do now?

Best Answer

Update messages.js in vendor/magento/module-theme/view/frontend/web/js/view.

define([
    'jquery',
    'uiComponent',
    'underscore',
    'Magento_Customer/js/customer-data',
    'jquery/jquery-storageapi'
], function ($, Component, _, customerData) {
    'use strict';

return Component.extend({
    defaults: {
        cookieMessages: [],
        messages: []
    },

    /** @inheritdoc */
    initialize: function () {
        this._super();

        this.cookieMessages = $.cookieStorage.get('mage-messages');
        this.messages = customerData.get('messages').extend({
            disposableCustomerData: 'messages'
        });

        if (!_.isEmpty(this.messages().messages)) {
            customerData.set('messages', {});
        }
        setTimeout(function(){
             $.cookieStorage.set('mage-messages', '');
        },3000);
    }
}); });
Related Topic