Hi there,

Since updating Drupal Core to 8.1.x (I updated from 8.0.whateveritwas straight to 8.1.3 so am not sure at what version the error ocurred) the current location on the breadcrumb trail has become confused and now names other content types and node names as the current location. Not sure why this would be? Let me know if examples are required.

Thanks!

Comments

Red2015 created an issue. See original summary.

Red2015’s picture

Issue summary: View changes
Red2015’s picture

Seems to be a cacheing issue. When I clear caches the current page and parent category seem to 'stick' with what page I was on when the cache was cleared.

NetNerdy’s picture

hi red2015...i had the same issue.

but...i have not this issue in projects after downloading and installing foundation and other modules by composer and drush - (composer NOT composer_manager)...i'm also creating the sub-theme by "drush fst ..."

edit: i'm using foundation 6.

i hope this helps something

samuel.mortenson’s picture

We don't make a lot of modifications with breadcrumbs, just to make sure have you tried setting Bartik as your default theme and seeing if the same issue occurs?

Red2015’s picture

Hi,

Thanks for the help. I have tried the Bartik theme and the issue does not occur here. Only on the foundation 5.

Thanks

dswier’s picture

This appears to be the same issue that is described in https://www.drupal.org/node/2483183#comment-11185583, comments 197 and 198. I was able to reproduce by visiting an article node, then creating a new article node and saving it. The new node then had the breadcrumb of the previous article I was viewing.

According to the thread I referenced:

You need to add the correct cacheability metadata in your preprocess, or better would be to implement a custom breadcrumb builder and do it there instead of preprocess.

I am honestly not sure what adding the correct cacheability metadata would entail, but I thought this information was relevant and worth sharing.

Red2015’s picture

Thanks for sharing dswier. As you say, it doesn't really open up very much what actually needs to happen, but glad to see others have picked on it!

borisson_’s picture

Title: Breadcrumb Confusion » Breadcrumb cache metadata is insufficient
Version: 8.x-5.0-beta2 » 8.x-6.x-dev
Status: Active » Needs review
StatusFileSize
new562 bytes

So, the problem here is that an additional item is added to the breadcrumb that is different per url but this block does not have per-block cache context. This can be fixed by adding the correct cache context.

wim leers’s picture

AFAICT you actually want the 'route' cache context, not the 'url' one.

wim leers’s picture

Issue tags: +D8 cacheability
wim leers’s picture

Title: Breadcrumb cache metadata is insufficient » Breadcrumb alteration cacheability metadata is insufficient
borisson_’s picture

So, for now this solution works, but we should change url to route context and see if that also still works. Ideally the entity's cache tags are added here as well.

Because the block no longer displays incorrect information when navigating between nodes, this should be sufficient for the needs I have on this project. I'll try to make time to add the entity cache tags in my own time tonight.

borisson_’s picture

StatusFileSize
new1.29 KB

This is an imperfect solution but it should be more correct, I think.

hongpong’s picture

@borisson_ I am seeing some breadcrumb issues right now and going to try patch 14, can you explain a little more about the imperfections of your patch? :) Thanks!

hongpong’s picture

StatusFileSize
new1.09 KB

Re rolled the patch, should apply to head now. I still get problems with the node titles not caching correctly, basic pages in particular the cache tag is just not right. I don't know too much about cacheability but perhaps someone with more experience knows the right thing to do here.

borisson_’s picture

#15: The problem with that patch is that this might not work for entities that don't set _entity on the route. I think most entities do that now, so this should work.

hongpong’s picture

StatusFileSize
new1.26 KB

Hmm it didn't work for me - I'm not familiar with this area so I'm just going to comment out everything in the preprocess function and try using https://www.drupal.org/project/easy_breadcrumb instead. That module has 8k+ sites in D8 so maybe it will be a viable replacement.

Patch disabling everything in zurb_foundation_preprocess_breadcrumb attached.

arosboro’s picture

I looked into this issue and various solutions and decided to follow a similar patch that bootstrap used in https://www.drupal.org/node/2722093.

I had initially thought to just use the cache tag 'url' however the other developer applied it as a context rather than a cache tag.

EDIT: Seeing now that this was the initial approach of the first patch, I may be motivated to change 'url' to 'route' if that is more correct.

kevinquillen’s picture

Should it be url.path? On sites where I am either theming or altering the breadcrumb, I add:

$breadcrumb->addCacheContexts(['url.path']);

or

$variables['#cache']['contexts'][] = 'url.path';

Both work for me.

On a project where I had to implement my own Breadcrumb Builder class, I had to add this (to trigger a change when the node changed):

$breadcrumb->addCacheableDependency($node);

Though I am not sure of the equivalent for the .theme file for that one.

Anonymous’s picture

Can verify that #16 is a good solution for the time being.

Also experience the same issue only with Zurb Foundation 8.x-6.x and my Sub Theme created from it.
When switching back to Bartik, the Breadcrumbs issue goes away.

philosurfer’s picture

#16 is not working..

creates the following error
Error: Call to a member function getCacheTags() on null in /app/web/themes/contrib/zurb_foundation/zurb_foundation.theme on line 32

philosurfer’s picture

[#19] is working for us..

added this under extra for the composer users:

"enable-patching": true,
              "patches": {
                  "drupal/zurb_foundation": {
                      "breadcrumb cache issue": "https://www.drupal.org/files/issues/zurb_foundation-caching_breadcrumbs-2752621-19.patch"
                  }
          },
anybody’s picture

Status: Needs review » Reviewed & tested by the community

Confirming RTBC for #19. There are also other themes with this problem, for example see #2817953: Breadcrumbs are cached

anybody’s picture

Title: Breadcrumb alteration cacheability metadata is insufficient » Breadcrumb alteration cacheability metadata is insufficient (missing cache context)

  • HongPong committed 3ca621f on 8.x-6.x authored by arosboro
    Issue #2752621 by borisson_, HongPong, arosboro: Breadcrumb alteration...
hongpong’s picture

Status: Reviewed & tested by the community » Fixed

Thanks everyone for looking into this. I think the #19 patch most closely solves the problem and doesn't make matters worse. Please re-open the issue if it doesn't work for you (or file a new issue if it is significantly different)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

anybody’s picture

@HongPong, thank you very much. Is there a plan for a new stable release? The patch doesn't apply on dev anymore and a new stable is missing, it would be great to have a new stable release because this issue leads to a mad hidden bug :)

Thank you!

anybody’s picture

Sorry for the trouble, the patch works with the latest alpha. But of course it's still a problem for users evaluating the theme without the patch.