2

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?

  • 1
    Haven't figured it out completely yet, but the message_box_display is only a display/hide mechanism. On add to cart for example there is an additional ajax call to example.com/customer/section/load/… which populates what changes including messages. So it would allow to cache the page with javascript retrieving the customer specific data. Will leave the answer to someone with more indepth JavaScript knowledge. – Kristof at Fooman Nov 28 '15 at 21:49
  • @Fooman 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. – Anton Kril Nov 29 '15 at 0:32
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.