Skip to content

VTEX IS PLP: breadcrumb empty on category pages when selectedFacets are pre-configured #458

Description

@JonasJesus42

Package / version

@decocms/apps-vtex — confirmed on 7.34.3 and latest 7.34.4.
File: src/loaders/intelligentSearch/productListingPage.ts

Summary

On a category PLP whose CMS block pre-configures selectedFacets, the returned breadcrumb.itemListElement is always [], so no breadcrumb renders. The deco-cx/apps (Fresh) original resolves the breadcrumb for the same block config — this is a regression in the port.

Root cause

pageTypes is only populated inside a branch gated on facets.length === 0:

let pageTypes: PageType[] = [];
if (
  facets.length === 0 &&   // <-- gate
  !query &&
  __pagePath && __pagePath !== "/" && __pagePath !== "/*" &&
  isValidPLPPath(__pagePath)
) {
  const allPageTypes = await pageTypesFromPath(__pagePath);
  pageTypes = getValidPageTypes(allPageTypes);
  facets = filtersFromPageTypes(pageTypes);
}

The breadcrumb is then built from pageTypes:

const breadcrumbItems = pageTypesToBreadcrumb(pageTypes);
return {
  breadcrumb: { "@type": "BreadcrumbList", itemListElement: breadcrumbItems, numberOfItems: breadcrumbItems.length },
  ...
};

Category blocks pre-configure facets (e.g. [{key:"category-1",value:"joias"},{key:"category-2",value:"aneis"},{key:"category-3",value:"meia alianca"}]), so facets.length > 0, the branch is skipped, pageTypes = [], and the breadcrumb comes back empty.

Reproduction

  1. Configure a SearchResult block with pre-set category selectedFacets (the standard CMS category-page shape).
  2. Load the page.
  3. page.breadcrumb.itemListElement is [] → breadcrumb does not render.

Proposed fix

Decouple the pageTypes resolution (needed for the breadcrumb) from the facet derivation (which correctly must not override pre-configured facets):

let pageTypes: PageType[] = [];
if (
  !query &&
  __pagePath && __pagePath !== "/" && __pagePath !== "/*" &&
  isValidPLPPath(__pagePath)
) {
  const allPageTypes = await pageTypesFromPath(__pagePath);
  pageTypes = getValidPageTypes(allPageTypes);
  if (facets.length === 0) {
    facets = filtersFromPageTypes(pageTypes); // only when the CMS block didn't set them
  }
}

pageTypesFromPath is already memoized (cachedPageType), so the extra call on pre-configured category paths is cheap.

Current workaround (site-level)

We wrap the loader and re-fetch pageTypesFromPath post-hoc when breadcrumb.itemListElement is empty and all selectedFacets are category-N. Would happily delete it once the upstream fix ships.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions