Skip to content

fix(docs): exclude unlisted category links from DocBreadcrumbs structured data#11842

Open
akshatsinha0 wants to merge 1 commit intofacebook:mainfrom
akshatsinha0:fix/docs-breadcrumbs-unlisted-structured-data
Open

fix(docs): exclude unlisted category links from DocBreadcrumbs structured data#11842
akshatsinha0 wants to merge 1 commit intofacebook:mainfrom
akshatsinha0:fix/docs-breadcrumbs-unlisted-structured-data

Conversation

@akshatsinha0
Copy link
Copy Markdown
Contributor

@akshatsinha0 akshatsinha0 commented Mar 26, 2026

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests.
  • If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

When a docs category has an unlisted generated-index page (linkUnlisted: true), its href is kept on the sidebar item intentionally so the active sidebar highlight still works. That href was leaking into the DocBreadcrumbs JSON-LD structured data and being emitted to Googlebot even though the link is invisible to human visitors.

The suppression in DocBreadcrumbs/index.tsx only applies to the rendered <a> element:

// DocBreadcrumbs/index.tsx
const href =
  item.type === 'category' && item.linkUnlisted
    ? undefined
    : item.href;

This does not mutate the breadcrumbs array. The raw array is passed unchanged to <DocBreadcrumbsStructuredData breadcrumbs={breadcrumbs} />, so structuredDataUtils.ts receives the item with href set and the existing .filter((b) => b.href) passes it through. The result is a BreadcrumbList ListItem pointing at an unlisted URL in the page's <script type="application/ld+json">.

Fix: extend the filter in structuredDataUtils.ts to also exclude category items where linkUnlisted is true:

.filter(
  (breadcrumb) =>
    breadcrumb.href &&
    !(breadcrumb.type === 'category' && breadcrumb.linkUnlisted),
)

Test Plan

Unit tests added in packages/docusaurus-plugin-content-docs/src/client/__tests__/structuredDataUtils.test.tsx (AI assistance was taken here):

  • Verifies breadcrumbs with href are included in itemListElement.
  • Verifies breadcrumbs without href are excluded.
  • Verifies a category with linkUnlisted: true and a non-null href is excluded from itemListElement.
  • Verifies a category with linkUnlisted: false and a non-null href is included normally.

Run: yarn test packages/docusaurus-plugin-content-docs/src/client/__tests__/structuredDataUtils.test.tsx

Test links

Deploy preview: https://deploy-preview-11842--docusaurus-2.netlify.app/

Related issues/PRs

No related issues found.

@meta-cla meta-cla bot added the CLA Signed Signed Facebook CLA label Mar 26, 2026
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 26, 2026

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit dbe5ae1
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/69c4f6b1c1c8370008b08d30
😎 Deploy Preview https://deploy-preview-11842--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@akshatsinha0 akshatsinha0 force-pushed the fix/docs-breadcrumbs-unlisted-structured-data branch from 9b1d4ee to dbe5ae1 Compare March 26, 2026 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant