-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
fix(docs): breadcrumb APIs only return category/docs items, ignoring links #11616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(docs): breadcrumb APIs only return category/docs items, ignoring links #11616
Conversation
…search When a sidebar link in one category points to a generated-index page URL from another category, the breadcrumb search would incorrectly return the link's parent category instead of the category that owns the URL. This fix uses a two-pass approach when searching for the current sidebar category: 1. First pass: Look for categories that directly own the URL (category.href) 2. Second pass: If not found, fall back to finding via links (for doc pages) This ensures generated-index pages display their correct category's items even when another category has a link pointing to the same URL. Closes facebook#11612
|
Hi @Chesars! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
✅ [V2]
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
|
Thanks for catching this bug. Your code seems to work, however I think it also makes sense to always favor category href over link href even for the regular breadcrumb case, so I reworked/simplified the logic and added an extra test for it. To be honest, I'm not even sure we need this 2-pass approach. Is there any good reason to show a link item in a breadcrumb? For now let's be conservative, but I think in #8008 and #6517 we may have added tests for something that shouldn't be supported in the first place? |
…at do not create any page
|
Yeah so it turns ouf that the 2-pass approach wouldn't completely solve the problem: this only works if your link targets a category, but there's another edge case to consider: linking to a doc. After looking at the history (#6517) at the time this was implemented, there was no way on the frontend to distinguish between a doc link (sidebar item type doc) from a regular link (sidebar item type link). Now that we coan make that distinction, we can simply ignore the items that are not associated to a doc, because I see no good reason for a non-doc link to appear in a breadcrumb. |
Pre-flight checklist
Motivation
Fixes #11612
When a sidebar link in one category points to a generated-index page URL from another category, Docusaurus incorrectly renders the page using items from the link's origin category instead of the target category's actual items.
Example:
/docs/category-b/category-bcontaining items (item1, item2, item3)/docs/category-bdisplays cards for item1, item2, item3(bug): The page displays cards for doc1, doc2 from Category A
getSidebarBreadcrumbs()does a depth-first search that returns on the first match. If Category A appears before Category B in the sidebar, it finds the link in Category A first and returns Category A as the "owner" of the URL.Solution
Use a two-pass approach when
onlyCategories: true(used byuseCurrentSidebarCategory()):category.href === pathname)This ensures generated-index pages display their correct category's items, while maintaining backwards compatibility for regular doc pages.
Test Plan
Added a regression test in
docsUtils.test.tsxthat verifies:hrefset to that URL (via generated-index)useCurrentSidebarCategory()returns Category B (the owner), not Category ARelated issues/PRs
Closes #11612