Magento2: Including "/" in CMS page identifier breaks ESI block rendering when Varnish enabled

Created on 22 Aug 2017  路  6Comments  路  Source: magento/magento2

Preconditions

  1. Ubuntu 16.04 ( on 14.04 same results )
  2. php7.0-fpm
  3. Varnish 4

Steps to reproduce

  1. Set-up Varnish and enable all caches
  2. Add items to top navigation ( I think anything that will be added there will count )

Also, what can be done to imitate something in top menu ( and I think is easier to do ) is to change the vendor/magento/framework/View/Layout.php:_renderBlock() function to include:

        if ($name == 'store.menu') {
            return 'SOMETHING SHOULD BE THERE';
        }
  1. Create CMS page with identifier including "/". For example, "sternbilder/adler"
  2. Now, if you open that CMS page on front-end, the menu won't be seen. It will be seen on other pages, though.

Expected result

  1. Menu should be seen

Actual result

  1. So basically menu isn't showing.

What I found is following:

At "vendor/magento/module-page-cache/Observer/ProcessLayoutRenderElement.php:_wrapEsi() " function there is line:

"'handles' => json_encode($layout->getUpdate()->getHandles())"
And our page identifier becomes following layout handle: "cms_page_view_id_sternbilder/adler". Please note the "/" included. And it seems that because of that "/", something isn't working correctly.

For example, here is the non working version -> https://www.star-registration.com/page_cache/block/esi/blocks/[%22catalog.topnav%22]/handles/[%22default%22,%22cms_page_view%22,%22cms_page_view_id_sternbilder/adler%22]/

Now, if I will change that last "/" to "_" , the url becomes https://www.star-registration.com/page_cache/block/esi/blocks/[%22catalog.topnav%22]/handles/[%22default%22,%22cms_page_view%22,%22cms_page_view_id_sternbilder_adler%22]/ and the block is rendered.

Obviously, this is not a solution to change the CMS pages urls from "/" to "_", so please check this on your side.

For the time being, I have made a hotfix by changing the line mentioned above to:

"'handles' => json_encode(str_replace('/', '_', $layout->getUpdate()->getHandles()))"
Obviously, this is also not the best solution ( because it actually changes the page identifier/layout handle ), and correct way would be to find that function which renders the contents in those urls and see where it fails, but since this seems to be the core bug, I will better leave further investigations/fixes on you. Actually, I have found the place where it gets those blocks from url:

vendor/magento/module-page-cache/Controller/Block.php:_getBlocks() function

When we have that "/" in the url, it returns blocks as"["default","cms_page_view","cms_page_view_id_sternbilder"

Basically it breaks in the "/" part.

So I will leave you guys with this.

Let me know if you have any more questions.

Thanks.

Cannot Reproduce Clear Description Format is valid needs update bug report

All 6 comments

Really, no comments or anything? I think this is quite an important bug since a lot of people will include "/" in CMS page name...

@archonkulis Thank you for report. We cannot reproduce this issue as described on Magento 2.1.8. Please specify the exact version of Magento you installed.

@magento-engcom-team

The version is 2.1.6. Could you check if you can reproduce on that version? If yes, then I guess update will do the trick.

@archonkulis it does not work this way AFAIK. You need to check latest 2.1.x to see if the issue still persists according to your steps, otherwise it will be closed in ~2 weeks.

@archonkulis, 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.

I can confirm this is not working on Magento 2.1.12 too.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kirashet666 picture kirashet666  路  3Comments

fvillata picture fvillata  路  3Comments

denis-g picture denis-g  路  3Comments

MauroNigrele picture MauroNigrele  路  3Comments

andreaskoch picture andreaskoch  路  3Comments