Question

In the shipping version of Magento 2, there's an afterDispatch plugin on the front controller

#File: vendor/magento/module-page-cache/Model/App/FrontController/MessageBox.php
public function afterDispatch(FrontController $subject, $result)
{
    if ($this->request->isPost() && $this->messageManager->hasMessages()) {
        $publicCookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata()
            ->setDuration(self::COOKIE_PERIOD)
            ->setPath('/')
            ->setHttpOnly(false);
        $this->cookieManager->setPublicCookie(self::COOKIE_NAME, 1, $publicCookieMetadata);
    }
    return $result;
}

The method appears to set an empty cookie named message_box_display. This cookie is only set if the request is a post and if there are any messages in the global-via-dependency-injection message manager.

What's the purpose of this "meta data" cookie? My guess would be it triggers a message box on cached pages (given the presence of the same cookie name in vendor/magento/module-page-cache/view/frontend/web/js/page-cache.js). However, this theory falls apart given the code calls createPublicCookieMetadata with no arguments (meaning no data for the "meta data cookie").

Are my assumptions incorrect? Does anyone know the purpose of this cookie in the larger framework?

Was it helpful?

Solution

Per @antonkril in the comments,

is right, this flag is just for display/hide. But it seems that it can be removed now, after the message rendering has been rebuilt with the new user data approach. I will forward this to the responsible team

it sounds like (?) message rendering has changed, and this plugin is no longer necessary.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top