-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Closed
Labels
Component: Framework/CacheFixed in 2.2.xThe issue has been fixed in 2.2 release lineThe issue has been fixed in 2.2 release lineIssue: Format is validGate 1 Passed. Automatic verification of issue format passedGate 1 Passed. Automatic verification of issue format passedbug report
Description
Preconditions
- Create a block with $this->_isScopePrivate = true; in its constructor.
- Redefine its _toHtml function to return an empty string if the request is not AJAX and its content if the request is AJAX.
- Include this block in your page layout.
- You must have full page cache enabled
Steps to reproduce
- Go on the page where your block is supposed to show
Expected result
- The block is retrieved from an AJAX call to page_cache/block/render.
Actual result
- An empty block is shown and no AJAX call is performed
Note that once a POST request is performed on the site (for instance adding a product to the cart), the block will be rendered from the AJAX call without any issue.
This bug is caused because the cookie 'private_content_version' is not yet set. Because of this, no ajax call is performed in vendor/magento/module-page-cache/view/frontend/web/js/page-cache.js (lines 97-100).
This gets even more obvious when looking at the function process() of Magento\Framework\App\PageCache\Version. Its comment states 'Set cookie if it is not set.' whereas it is not the case, it is only set when a POST request is performed.
Here is a suggested fix (line 78) :
if ($this->request->isPost() || !$this->cookieManager->getCookie(self::COOKIE_NAME)) {
Metadata
Metadata
Assignees
Labels
Component: Framework/CacheFixed in 2.2.xThe issue has been fixed in 2.2 release lineThe issue has been fixed in 2.2 release lineIssue: Format is validGate 1 Passed. Automatic verification of issue format passedGate 1 Passed. Automatic verification of issue format passedbug report