fix(docs): exclude unlisted category links from DocBreadcrumbs structured data#11842
Open
akshatsinha0 wants to merge 1 commit intofacebook:mainfrom
Open
Conversation
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
9b1d4ee to
dbe5ae1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pre-flight checklist
Motivation
When a docs category has an unlisted generated-index page (
linkUnlisted: true), itshrefis kept on the sidebar item intentionally so the active sidebar highlight still works. Thathrefwas leaking into theDocBreadcrumbsJSON-LD structured data and being emitted to Googlebot even though the link is invisible to human visitors.The suppression in
DocBreadcrumbs/index.tsxonly applies to the rendered<a>element:This does not mutate the
breadcrumbsarray. The raw array is passed unchanged to<DocBreadcrumbsStructuredData breadcrumbs={breadcrumbs} />, sostructuredDataUtils.tsreceives the item withhrefset and the existing.filter((b) => b.href)passes it through. The result is aBreadcrumbListListItempointing at an unlisted URL in the page's<script type="application/ld+json">.Fix: extend the filter in
structuredDataUtils.tsto also exclude category items wherelinkUnlistedistrue:Test Plan
Unit tests added in
packages/docusaurus-plugin-content-docs/src/client/__tests__/structuredDataUtils.test.tsx(AI assistance was taken here):hrefare included initemListElement.hrefare excluded.linkUnlisted: trueand a non-nullhrefis excluded fromitemListElement.linkUnlisted: falseand a non-nullhrefis included normally.Run:
yarn test packages/docusaurus-plugin-content-docs/src/client/__tests__/structuredDataUtils.test.tsxTest links
Deploy preview: https://deploy-preview-11842--docusaurus-2.netlify.app/
Related issues/PRs
No related issues found.