decocms / decocms/blocks

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

Open Beginner friendly
#458 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
5
Forks
2
Avg merge
20h 12m
Merged PRs (30d)
36

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/loaders/intelligentSearch/productListingPage.ts and inspect how pageTypesFromPath, facets, and pageTypesToBreadcrumb are used. Reproduce the category PLP with pre-configured selectedFacets, then verify pageTypes resolves for the breadcrumb without overriding those facets. Done means breadcrumb.itemListElement contains the expected category entries and the existing facet behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
web-dev
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.