1.Magento 2.3.1 with all cache types enabled
Just opened category is marked as active in top menu
Both categories in top menu are marked as active
Hi @lyusya-nnn. Thank you for your report.
To help us process this issue please make sure that you provided the following information:
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
@magento-engcom-team give me 2.3-develop instance
- upcoming 2.3.x release
For more details, please, review the Magento Contributor Assistant documentation.
@lyusya-nnn do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?
Hi @rammohan-krish. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
Issue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid
appears.[x] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description
label to the issue by yourself.
[x] 3. Add Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.
[x] 4. Verify that the issue is reproducible on 2.3-develop
branchDetails
- Add the comment @magento-engcom-team give me 2.3-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.3-develop
branch, please, add the label Reproduced on 2.3.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!
[x] 5. Verify that the issue is reproducible on 2.2-develop
branch. Details
- Add the comment @magento-engcom-team give me 2.2-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.2-develop
branch, please add the label Reproduced on 2.2.x
[ ] 6. Add label Issue: Confirmed
once verification is complete.
[ ] 7. Make sure that automatic system confirms that report has been added to the backlog.
@magento-engcom-team give me 2.3-develop instance
Hi @rammohan-krish. Thank you for your request. I'm working on Magento 2.3-develop instance for you
Hi @rammohan-krish, here is your Magento instance.
Admin access: https://i-22407-2-3-develop.instances.magento-community.engineering/admin
Login: admin
Password: 123123q
Instance will be terminated in up to 3 hours.
@magento-engcom-team give me 2.2-develop instance
Hi @rammohan-krish. Thank you for your request. I'm working on Magento 2.2-develop instance for you
Hi @rammohan-krish, here is your Magento instance.
Admin access: https://i-22407-2-2-develop.instances.magento-community.engineering/admin
Login: admin
Password: 123123q
Instance will be terminated in up to 3 hours.
:white_check_mark: Confirmed by @rammohan-krish
Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-99263
, MAGETWO-99264
were created
Issue Available: @rammohan-krish, _You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself._
If somebody needs the fix for this issue you can create a plugin for Magento\Theme\Block\Html\Topmenu, so in di.xml you will have something like this:
<type name="Magento\Theme\Block\Html\Topmenu">
<plugin name="catalogTopmenuCache" type="MagentoOverwrite\Catalog\Plugin\Block\Topmenu" />
</type>
And your plugin will look like this:
<?php
namespace MagentoOverwrite\Catalog\Plugin\Block;
use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\Layer\Resolver;
/**
* Class Topmenu
*
*/
class Topmenu
{
/**
* @var Resolver
*/
private $layerResolver;
/**
* Topmenu constructor.
* @param Resolver $layerResolver
*/
public function __construct(
Resolver $layerResolver
) {
$this->layerResolver = $layerResolver;
}
/**
* Get current Category from catalog layer
*
* @return \Magento\Catalog\Model\Category
*/
private function getCurrentCategory()
{
$catalogLayer = $this->layerResolver->get();
if (!$catalogLayer) {
return null;
}
return $catalogLayer->getCurrentCategory();
}
/**
* Add category id to cache tag
*
* @param \Magento\Theme\Block\Html\Topmenu $subject
* @param array $result
* @return array
*/
public function afterGetCacheKeyInfo(\Magento\Theme\Block\Html\Topmenu $subject, $result)
{
$category = $this->getCurrentCategory();
if (!$category || !$category->getId()) {
return $result;
}
$result[] = Category::CACHE_TAG . '_' . $category->getId();
return $result;
}
}
It is coming because \Magento\Theme\Block\Html\Topmenu has a cache life time. If we return 0 in getCacheLifetime()
it works fine. But is it best possible solution?
Also when clicking on any Footer link one category is marked as active.
Hi @sanjaychouhan-webkul. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:
Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.[ ] 2. Verify that the issue is reproducible on 2.3-develop
branchDetails
- Add the comment @magento-engcom-team give me 2.3-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.3-develop
branch, please, add the label Reproduced on 2.3.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!
[ ] 3. Verify that the issue is reproducible on 2.2-develop
branch. Details
- Add the comment @magento-engcom-team give me 2.2-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.2-develop
branch, please add the label Reproduced on 2.2.x
[ ] 4. If the issue is not relevant or is not reproducible any more, feel free to close it.
It can be a temporary solution.
Set cache_lifetime
as 1
for the catalog.topnav
block.
{YOUR_THEME_DIR}/Magento_Theme/layout/default.xml
<referenceContainer name="page.top">
<referenceBlock name="catalog.topnav">
<arguments>
<argument name="cache_lifetime" xsi:type="number">1</argument>
</arguments>
</referenceBlock>
</referenceContainer>
I am working on this #dmcdindia1
Hi @gauravagarwal1001. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:
Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.[ ] 2. Verify that the issue is reproducible on 2.3-develop
branchDetails
- Add the comment @magento-engcom-team give me 2.3-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.3-develop
branch, please, add the label Reproduced on 2.3.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!
[ ] 3. Verify that the issue is reproducible on 2.2-develop
branch. Details
- Add the comment @magento-engcom-team give me 2.2-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.2-develop
branch, please add the label Reproduced on 2.2.x
[ ] 4. If the issue is not relevant or is not reproducible any more, feel free to close it.
The main problem is not the cache lifetime - the cached content is the problem:
In some cases a menu with active elements is cached just because of 'deprecated' block functions.
Have a look at:
Magento\Theme\Block\Html\Topmenu::_getMenuItemClasses(\Magento\Framework\Data\Tree\Node $item)
{
...
}
This function provides item's css classes.
Just remove these lines with the help of a plugin or something like that. There is no need to add these markup classes via php since it's done via js.
if ($item->getIsActive()) {
$classes[] = 'active';
} elseif ($item->getHasActive()) {
$classes[] = 'has-active';
}
The main problem is not the cache lifetime - the cached content is the problem:
In some cases a menu with active elements is cached just because of 'deprecated' block functions.Have a look at:
Magento\Theme\Block\Html\Topmenu::_getMenuItemClasses(\Magento\Framework\Data\Tree\Node $item) { ... }
This function provides item's css classes.
Just remove these lines with the help of a plugin or something like that. There is no need to add these markup classes via php since it's done via js.if ($item->getIsActive()) { $classes[] = 'active'; } elseif ($item->getHasActive()) { $classes[] = 'has-active'; }
The problem with doing it this way is that it's down to the javascript to mark as active, so there is a slight, sometimes visible delay, from when the page loads to when the menu is marked active. making the site appear slow.
The problem with doing it this way is that it's down to the javascript to mark as active, so there is a slight, sometimes visible delay, from when the page loads to when the menu is marked active. making the site appear slow.
Is this really a problem?
The problem with doing it this way is that it's down to the javascript to mark as active, so there is a slight, sometimes visible delay, from when the page loads to when the menu is marked active. making the site appear slow.
Is this really a problem?
It was for me, the solution from mega667, by setting the cache_lifetime
to 1, is a cleaner and more effective solution.
So any updates on this one? This issue is couple of months old now. Is this fixed in 2.3.2?
looks like it was fixed here before this issue was even opened, lol - https://github.com/magento/magento2/commit/bf8af1e7d3781db0921ed530e4f51e6d54ae56e1
but unfortunately there appears to have been a great deal of bikeshedding over test descriptions (until 2 days before this issue was opened!) so it was only merged 6 days ago: https://github.com/magento/magento2/commit/bc0b41245c5e55ecf27496e9ce1204ac6cf02a81
so i suppose you will have to stick with @lyusya-nnn solution until, i dunno... presumably november or something
:roll_eyes: embarrassing
Hi @rammohan-krish,
Could you double check if this issue was already fixed?
Thx
@ihor-sviziev sure
@magento-engcom-team give me 2.3-develop instance
Hi @rammohan-krish. Thank you for your request. I'm working on Magento 2.3-develop instance for you
Hi @rammohan-krish, here is your Magento instance.
Admin access: https://i-22407-2-3-develop.instances.magento-community.engineering/admin
Login: admin
Password: 123123q
Instance will be terminated in up to 3 hours.
Issue not reproduced on the 2.3-develop instance
@magento-engcom-team give me 2.2-develop instance
Hi @rammohan-krish. Thank you for your request. I'm working on Magento 2.2-develop instance for you
Hi @rammohan-krish, here is your Magento instance.
Admin access: https://i-22407-2-2-develop.instances.magento-community.engineering/admin
Login: admin
Password: 123123q
Instance will be terminated in up to 3 hours.
Issue reproduced on the 2.2-develop instance
please refer to the following screenshot:
Hello, @ihor-sviziev issue reproducing on the 2.2-develop instance.
I am seeing this issue in both 2.2 and 2.3 is this going to be fixed in the next releases?
Hi @rammohan-krish,
2.2-develop
branch already closed - we should not wait for fixing this issue in 2.2 release line.
Looks like fix for this issue was reverted in https://github.com/magento/magento2/commit/5a997fdc2e987c1371c66014be89734798deddd1.
Could you check if this issue is reproducing on 2.3-develop? If it's not reproducing - let's close it.
Hi @ihor-sviziev,
I know this isn't exactly what you asked for in terms of 2.3 develop, but I can confirm the issue is still present in 2.3.2 (see screenshot).
Yes, I saw your comment, but after 10 days after your comment there
appeared commit that reverted these changes, that is strange
That’s why I asked to recheck it again
On Thu, Aug 15, 2019 at 18:30 maaarghk notifications@github.com wrote:
22407 (comment)
https://github.com/magento/magento2/issues/22407#issuecomment-507742424
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/magento/magento2/issues/22407?email_source=notifications&email_token=AAOJOUPVQ6NFR2WMVN3HOGDQEVZDHA5CNFSM4HG4IN6KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4MEGPI#issuecomment-521683773,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAOJOUMUA4AYHHUYDKHXULLQEVZDHANCNFSM4HG4IN6A
.
An update would still be great for this. Currently encountering this on a live site (even with default template), but it's quite random for me sadly
Looks like it was finally fixed in https://github.com/magento/magento2/commit/bd5b7c584de95da97200be47d6f63fd9eda372f7
All related changes you can find here: https://github.com/magento/magento2/commit/84b7d391bed8874fb818b9fef0106bf7ff246249
@engcom-Alfa could you confirm that this issue is not reproducing anymore?
@ihor-sviziev Ok, I will check
@ihor-sviziev We are not able to reproduce this issue on fresh 2.3-develop instance. The problem has been resolved in bd5b7c5.
Thanks!
For those who are not able to update Magento to the latest version at this moment and need a quick fix: https://github.com/oroskodias/m2-fix-cache-topmenu
Thank you @lyusya-nnn !
You need to add a cache key that is unique per search query.
Create a plugin for the topmenu block in di.xml
:
<type name="Magento\Theme\Block\Html\Topmenu">
<plugin name="topmenu_searchbar" type="Vendor\Package\Plugin\Block\Topmenu" />
</type>
Then use the getAfterCacheKeyInfo()
method:
<?php
namespace Vendor\Package\Plugin\Block;
class Topmenu
{
/**
* @var \Magento\Search\Helper\Data
*/
private $searchHelper;
public function __construct(
\Magento\Search\Helper\Data $searchHelper
) {
$this->searchHelper = $searchHelper;
}
/**
* Since the search bar was moved into the topnav, we need to add a key for the search term
* so it doesn't get cached.
*/
public function afterGetCacheKeyInfo(\Magento\Theme\Block\Html\Topmenu $subject, $result)
{
$result[] = $subject->getUrl('*/*/*', ['_current' => true, 'q' => $this->searchHelper->getEscapedQueryText()]);
return $result;
}
}
So, when is it planned, the solution to be merged and released? I'm still getting this double active category bug.
Same here, upgraded to 2.3.3 thinking this issue would be fixed. It is not.
Actually this issue was fixed in the 2.3.4 Commerce release :
Magento now highlights only the most recently selected category as expected on storefront pages that contain multiple categories. Previously, all selected category menus remained highlighted.
Hi, @oroskodias !
Your plugin (https://github.com/oroskodias/m2-fix-cache-topmenu) works perfect for menu items on category, but not for menu items added by other extensions.
For example:
https://marketplace.magento.com/mageplaza-magento-2-blog-extension.html
Regards,
JOINSO
that would be a mageplaza_blog bug, it should also plugin afterGetCacheKeyInfo and add its own thing
Most helpful comment
If somebody needs the fix for this issue you can create a plugin for Magento\Theme\Block\Html\Topmenu, so in di.xml you will have something like this:
And your plugin will look like this: