Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ion.macaria created an issue. See original summary.

ion.macaria’s picture

Issue summary: View changes
ion.macaria’s picture

Title: Breadcrumb disappears when starting with front-page after cache rebuild (for anonymous user). » Breadcrumbs disappears when starting with front-page after cache rebuild (for anonymous user).
markhalliwell’s picture

Status: Active » Postponed (maintainer needs more info)

I'm confused. The version for this issue is 7.x-3.13, but you also reference an 8.x issue and say "breadcrumbs-block" (which implies 8.x).

What exactly is the issue here?

ion.macaria’s picture

Version: 7.x-3.13 » 8.x-3.3
ion.macaria’s picture

Sorry, it's 8.x-3.3.

ion.macaria’s picture

Status: Postponed (maintainer needs more info) » Active
Jill L’s picture

I'm also experiencing this after upgrading to Drupal 8.3.2

markhalliwell’s picture

Status: Active » Postponed (maintainer needs more info)

@ion.macaria, you still really haven't given much information. Some clear steps to reproduce would be helpful here.

ion.macaria’s picture

Sorry @markcarver, i thought unclear was only version.
This is an example by steps:
1. Install Drupal version 8.3.1 and Bootstrap 8.x-3.2 - 8.x-3.3
2. Create a less subtheme from Bootstrap
3. Go to /admin/appearance/settings/--our-subtheme--
4. Bootstrap Settings -> Breadcrumbs -> Activate --Breadcrumb visibility(Visible)--, Activate --Show 'Home' breadcrumb link-- and --Show current page title at end--.
After that:
5. Go to /admin/config/development/performance and Clear all caches (or press "drush cr" in console)
6. Open new incognito browser window(anonymous user), and go from the start to front page (do not forget to put breadcrumbs-block on some region which is visible on all pages)
7. Breadcrumbs will be cached and invisible on all pages like on front-page.

ion.macaria’s picture

Status: Postponed (maintainer needs more info) » Active
Majdi’s picture

I can confirm that but I think this has nothing to do with bootstrap, if you set any page as front page under site settings, you wont be able to see the breadcrumb anymore and you can have this behavior with any theme, I think it's related to core.

ion.macaria’s picture

Project: Bootstrap » Core development
Version: 8.x-3.3 »
rroels’s picture

I am experiencing the same issue in Drupal 8.3.7. The whole breadcrumbs block is simply not shown on the frontpage, everywhere else it works fine. I'm using a custom template so it's not a template setting. I even tried adding "<front>" and "*" to the breadcrumb block's page restriction tab but that changes nothing.

Something that is also interesting to note is that the "MYTEMPLATE_preprocess_breadcrumb( )" function in my custom template is never called for the frontpage. It works fine everywhere else. I thought I could hack together a fix by overwriting the $variables['breadcrumb'] variable for the frontpage there, but the function isn't even called.

This seems like an internal issue/bug to me.

markhalliwell’s picture

Project: Core development » Drupal core
Version: » 8.4.x-dev
Component: Code » cache system
Status: Active » Postponed (maintainer needs more info)
Related issues: +#2829588: Provide a "url.path.is_front" cache context to allow contributed themes to move global "is_front" variable back

This sounds like, perhaps, a caching issue but may have already been solved by #2829588: Provide a "url.path.is_front" cache context to allow contributed themes to move global "is_front" variable back.

In fact, this allowed Bootstrap to add back the global "is_front" template variable #2829585: Add the "is_front" variable back to all templates.

I'm still not convinced that this is an actual issue as I have not seen this happen personally (it would be a pretty obvious bug).

That being said, most "front pages" of websites rarely have breadcrumbs of any kind.

If anything, it may be a byproduct of the increasing learning curve for Drupal, one which now includes render caching and contexts.

I think for this issue to move forward as an actual bug, someone will need to pin point where this bug is via code/patch.

Thus, postponing for now (and moving to proper IQ).

jbitdrop’s picture

As @markcarver has already stated, I would also rather see this issue here as a basis for a possible feature request and before this as a conceptual decision to discuss, because breadcrumbs are mostly not awaited on frontpage. And this has a possible chance to become "works as designed". Despite of that I wonder where or when I ever have seen a breadcrumb on frontpage or do I miss something here from the issue summary?

skyhawk669’s picture

The issue here isn't about whether the breadcrumbs are displayed on the front page or not, I think most of us agree that they have no place on a front page.

The problem @ionmacaria is describing, which I'm having as well, is that if you visit the site main page as an anonymous user, then go to another (sub) page where the breadcrumbs should appear, they do not. If that sub page (or any other) is visited directly after cache being cleared (without visiting the front page first), then the breadcrumbs appear correctly as they should.

In my case they don't disappear on all sub pages, but only on first level sub pages (http://www.example.com/subpage, http://www.example.com/subpage2, etc.). Also, for me, this happens not only for anonymous users, but also any logged in user besides administrator.

Like @ionmacaria mentioned, the only workaround is to go into the breadcrumbs block configuration and hide for listed pages and include the front page there (even though the breadcrumbs wouldn't show up anyway), then this issue disappears.

As far as I can see, this isn't dependent on the theme used, I saw the same issue on Seven and Bartik as well...

There must be some bug somewhere in the breadcrumb logic in core.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

gallegosj’s picture

I'm experiencing this exact issue and it's been driving me insane. @skyhawk669 #17 described it perfectly. If I clear my site cache and then log out I'm returned to the home page. Breadcrumbs don't get loaded to the new cache build since I'm starting on the home page as an anonymous user, so they're not showing up on sub pages either.

donapis’s picture

i'm also having the same problem.

Akansh Pandey’s picture

Issue lies in \core\modules\system\src\PathBasedBreadcrumbBuilder.php file.

Here they have written :
// Do not display a breadcrumb on the frontpage.
if ($this->pathMatcher->isFrontPage()) {
return $breadcrumb;
}

When I exclude these lines, my breadcrumb preprocess works in desired way.
I would suggest you to override this file.

I hope this suggestion is helpful to you.

sarikak’s picture

@Akansh Pandey

Thanks a lot.
I was searching for this one.You saved my day.

tce’s picture

I'm seeing this also. If I clear caches and I crawl the site using software, visiting pages then shows the missing breadcrumb.

- Using Drupal version 8.5.3
- I don't have breadcrumbs on my front page
- Breadcrumbs are on my Commerce product pages

The solution in shown in #21 only seems to work on my local copy of the site (with all caching turned on) but not on production for some reason.

I'm actually using my own breadcrumb builder for product page, code is:

/**
 * Class BreadcrumbBuilderProducts.
 */
class BreadcrumbBuilderProducts implements BreadcrumbBuilderInterface {

  /**
   * {@inheritdoc}
   */
  public function applies(RouteMatchInterface $route_match) {
    $route = $route_match->getRouteName();
    switch ($route) {
      case 'entity.commerce_product.canonical';
        return TRUE;
        break;
    }
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function build(RouteMatchInterface $route_match) {
    /** @var \Drupal\commerce_product\Entity\Product $product */
    if ($product = $route_match->getParameter('commerce_product')) {
      $breadcrumb = new Breadcrumb();
      $links[] = Link::createFromRoute(t('Home'), '<front>');
      $character_node = Node::load($product->field_character_id->getString());
      $links[] = Link::createFromRoute(t('Character'), 'character_node.main_menu_character');
      $links[] = Link::createFromRoute($character_node->getTitle(), 'entity.node.canonical', array('node' => $character_node->id()));
      $breadcrumb->setLinks($links);
      return $breadcrumb;
    }
  }

}

Breadcrumbs work fine for product pages when logged in. Also works fine clearing the cache and straight away visiting the product page. It doesn't work if I clear the site, crawl the site, then visit the product page.

jbitdrop’s picture

I think we should first clear what this issue is about, edit the summary, finalize the roadmap and start providing ideas for patches. Otherwise this issue will keep being postponed.

pixelpreview@gmail.com’s picture

I have the same problem with drupal 8.5, breadcrumb disappears after clear cache when we are redirect to the home
all pages loose the breadcrumb

rondog469’s picture

I am using 8.5.6 and having this issue as well. On my homepage, I don't have breadcrumbs. If I clear cache on the front page and then visit a subpage, the breadcrumbs are gone. If I clear cache on a subpage, the crumbs work fine.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jeramy’s picture

I was having the same problem as described by the OP ion.macaria, and in #17 by skyhawk669. Following the instructions in #17 worked for me on each site I had experiencing this issue.

Drupal version : 8.6.1

I went Home>Administration>Structure>Block Layout and clicked 'Configure' on my Breadcrumbs block. Under the Pages tab, I set 'Hide for the listed pages' and added <front> to the 'Pages' textbox. I changed this on each of my sites experiencing this issue and it worked in each case.

tce’s picture

Wow, just followed the instructions in #28 and it appears to work. Will keep an eye on it. Thanks jeramy.

Update: some breadcrumbs are still missing using solution #28

huzooka’s picture

Version: 8.6.x-dev » 8.7.x-dev
Component: cache system » system.module
Assigned: Unassigned » huzooka
Status: Postponed (maintainer needs more info) » Active

Found a test case when this fails (and I have fix as well).

Steps to reproduce

  1. Install Drupal core, enable user, node, path and obviously block modules (it is important not to have view enabled or if it is, ensure that views.view.frontpage is disabled)
  2. Place breadcrumb block to the active theme's block layout. Don't set up any visibility condition, leave everything default.
  3. Create a node type and two nodes. Node 'A' will be used for front page. Node 'B' should have a path alias, let's say it will be /breadcrumb-test
  4. Set page.front in system.site to node/[NODE_A-ID]
  5. Log out and rebuild caches. (It's enough to invalidate the render cache btw.)
  6. Visit front page.
  7. Visit the aliased path of node 'B': /breadcrumb-test

Expected
You can see the breadcrum containing the 'Home' link.

Current behavior
Breadcrumb is missing.

Explanation

IMHO the issue caused by the faulty usage of the cache contexts in PathBasedBreadcrumbBuilder. When we have a breadcrumb render cached for the front page, it's only cache context will be the url.path.parent. This happens because of the next condition @150.

In this case, PathBasedBreadcrumbBuilder will return a renderable array with only the cache context url.path.parent. And that context is the same even if we have only one level in our path (/breadcrumb-test) or nothing (on the front page, obviously). And this renderable array will rendered as an empty element.
So, because of that the cache context is the same for both <front> and for /anything-else, Cache API correctly determines that it shouldn't create an another rendered instance for this breadcrumb.

If the first page visit (with cold cache) gets any other node page, the condition @150 wont be true, the breadcrumb will have markup (a home link at least).

The solution is to add url.path.is_front cache context to PathBasedBreadcrumbBuilder@147. This will produce only one more render cache instance from breadcrumb, which is acceptable imho.

huzooka’s picture

Test-only patch.

Status: Needs review » Needs work
huzooka’s picture

huzooka’s picture

Worths a mention that I was unable to use AssertBreadcrumbTrait. It does not care about that the 'Home' crumb is printed on the page or not :(.

Status: Needs review » Needs work
cestmoi’s picture

I experienced this bug after updating from 8.5.6 to 8.6.1
Breadcrumbs do not show link for current node if it's a parent page. When it's a child page breadcrumb shows links for parent pages. Sometimes breadcrumb shows the word "Node" with a link instead of the current node title.

I disabled the core Frontpage view and I do have a custom Frontpage view in place.
I tried all fixes mentioned above and nothing worked.

I tested on a fresh install on simplytest.me and the breadcrumb menu only showed the "Home" link no more and regardless of the type or level of node I am on.

huzooka’s picture

@cestmoi

I'm sure that if you apply #33, it will be fixed.

Failed tests (Node translation ui and breadcrumb kernel unit test) are complaining about the unexpected url.path.is_front cache contexts.

It's obvious that this fix can't be committed to core; but we'll see the further tasks (solution) only after a review (ideally from a core maintainer).

huzooka’s picture

Assigned: Unassigned » huzooka
cestmoi’s picture

@huzooka
Thank you but unfortunately it didn't make any change for me !

Still no breadcrumb for any page that is a top level parent page while it shows links for parent/s page/s when the current node is a child page. That's still better than what I had on a fresh test on simplytest.me where nothing is shown but the "Home" link no matter what node you're at. I reported this as a bug here as I'm not sure if it's directly related to the bug reported here.

huzooka’s picture

@cestmoi

You need to alter the breadcrumb in your case. Core does not outputs the active route's title, that's why it adds `url.path.parent` by default. Here's the motivation/explanation: https://www.drupal.org/node/2713593

I wont assume that your use case will be considered as a bug.

In your case I would replace the class of the system.breadcrumb.default service with a custom class which extends the original PathBasedBreadcrumbBuilder and customize it's build method, so here:

    // Add the url.path.parent cache context. This code ignores the last path
    // part so the result only depends on the path parents.
    $breadcrumb->addCacheContexts(['url.path.parent']);

You should add url.path instead of url.path.parent.

Note that you'll get lot more context of your breadcrumb in this case.

huzooka’s picture

Expected test fails reduced to two assertions:

Drupal\Tests\system\Unit\Breadcrumbs\PathBasedBreadcrumbBuilderTest::testBuildOnFrontpage and Drupal\Tests\system\Unit\Breadcrumbs\PathBasedBreadcrumbBuilderTest::testBuildWithOnePathElement both will fail.

Test-only patch was only renamed.

cestmoi’s picture

Status: Needs review » Needs work

@huzooka

I applied your suggestion and still no change whatsoever !

Idk if it's me doing something wrong or missing something.

1. I edited the function in core\modules\system\src\PathBasedBreadcrumbBuilder.php so it became :

    // Add the url.path.parent cache context. This code ignores the last path
    // part so the result only depends on the path parents.
    $breadcrumb->addCacheContexts(['url.path']);

2. I rebuilt cache drush cr
3. Tested. No change ! :-/

I wont assume that your use case will be considered as a bug.

So it's a core by-design to only have the link for the parent nodes and no links if current page is a top parent node :-?

In such case then it's working as designed in my case (except for the occasional "Node" replacing the actual node Title).

But the case I reported from my test on simplytest.me where breadcrumb only has a "Home" link no matter what page you're on is a bug. No ?!

huzooka’s picture

My advice is that at least provide a 'steps to reproduce' to #3001425: breadcrumb not showing current page title when it's a top parent node, after updating to 8.6.0.

Tis issue is about Breadcrumbs disappears when starting with front-page after cache rebuild.

catch’s picture

+++ b/core/modules/system/src/PathBasedBreadcrumbBuilder.php
@@ -146,6 +146,15 @@ public function build(RouteMatchInterface $route_match) {
+
+    // Check the number of path elements and add 'url.path.is_front' cache
+    // context if it's less or equal than 1.
+    if (count($path_elements) <= 1) {
+      $breadcrumb->addCacheContexts(['url.path.is_front']);
+    }

This should always add the url.path.is_front cache context unconditionally.

catch’s picture

Priority: Normal » Major

Bumping to major since this is a site-visitor facing bug.

huzooka’s picture

Assigned: Unassigned » huzooka
huzooka’s picture

Let's add the passing patch :)

I dont add a test-only one since it would be the same as the one in #33.

catch’s picture

Status: Needs review » Reviewed & tested by the community

Looks right to me now, thanks!

jeramy’s picture

The patch worked for me as well. Thank you!

catch’s picture

Version: 8.7.x-dev » 8.6.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 1506516dc3 to 8.7.x and 59bcf5befc to 8.6.x. Thanks!

  • catch committed 1506516 on 8.7.x
    Issue #2875276 by huzooka, ion.macaria, cestmoi, catch: Breadcrumbs...

  • catch committed 59bcf5b on 8.6.x
    Issue #2875276 by huzooka, ion.macaria, cestmoi, catch: Breadcrumbs...

Status: Fixed » Closed (fixed)

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