Skip to content

fix(docs): prefer category indexes over document references (AI-assisted) - #13103

Open
spdeepak97 wants to merge 1 commit into
meta:mainfrom
spdeepak97:fix/doc-card-list-category-index
Open

spdeepak97 wants to merge 1 commit into
meta:mainfrom
spdeepak97:fix/doc-card-list-category-index

Conversation

@spdeepak97

@spdeepak97 spdeepak97 commented Nov 22, 2026 •

Copy link
Copy Markdown

Motivation

When Tutorial Basics contains a document entry pointing to the Tutorial Extras overview, <DocCardList /> on that overview can render Tutorial Basics cards. The breadcrumb search stops at the earlier document reference before reaching the category whose index URL matches the current page.

Search the entire sidebar for matching category indexes first, then fall back to the existing document lookup. This preserves the full parent trail for nested categories. If several categories share an index URL, the first match in depth-first sidebar order wins. Ordinary document pages retain the existing lookup and root-level fallback.

Related to #10475. The plain-link case is already handled by current main; this fixes the remaining document-entry variation.

Changes

  • Add a category-first pass to getSidebarBreadcrumbs.
  • Add rendered DocCardList tests with Tutorial Basics referencing the Tutorial Extras overview through a plain link, a document link, and duplicate document links. Assert the exact Extras card titles and destinations.
  • Cover nested category breadcrumbs, category ordering with duplicate index URLs, duplicate ordinary document references, and root-level documents.
  • Resolve the Vitest @theme alias to the absolute theme source path so the component test can load the real card components.

Test plan

Validated against main at 809ffffd5c8436e7458b9a2c494ce3fe7f8ef0bc, with Node 26.13.0 and pnpm 12.3.4.

  1. Run the new tests with the original docsUtils.tsx: 4 failed, 47 passed. The failures include the two rendered-card document-reference cases and nested category lookup/breadcrumb checks.
  2. Restore the fix and run the focused tests: 51 passed.
  3. Run the complete suite: 209 test files passed; 3,271 tests passed, 1 skipped.
  4. Test TypeScript checking, ESLint on the three changed TSX files, formatting on all changed files, and git diff --check passed.

Commands:

pnpm vitest run packages/docusaurus-plugin-content-docs/src/client/__tests__/docsUtils.test.tsx packages/docusaurus-plugin-content-docs/src/__tests__/docCardList.test.tsx
GIT_DISCOVERY_ACROSS_FILESYSTEM=1 pnpm test
pnpm typecheck:tests

The Git discovery environment setting is needed for the existing untracked-directory Git error snapshot in this container: without it, Git adds a filesystem-boundary message and that unrelated snapshot fails. No snapshot or Git utility code was changed.

Checklist

  • Read the contributing guidelines.
  • Added regression tests for the changed behavior.
  • Included before-and-after test results.

This contribution was prepared with AI assistance for implementation and test execution.

Summary by CodeRabbit

  • Bug Fixes
    • Documentation category index pages now take precedence over document links elsewhere in the sidebar when determining breadcrumbs and sidebar siblings.
    • Breadcrumbs retain the first matching document trail when no category owns the current page.
    • Tutorial Extras overview cards now exclude unrelated documents referenced through the Tutorial Basics sidebar.

@meta-cla

meta-cla Bot commented Nov 22, 2026

Copy link
Copy Markdown

Hi @spdeepak97!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The sidebar breadcrumb helper now searches for a matching category before matching a document link. Tests cover category and sibling selection, document trails, and overview cards. The Vitest theme alias now resolves to the theme source directory.

Changes: Docs sidebar behavior

Layer / File(s) Summary
Category-first sidebar matching and regression coverage
packages/docusaurus-plugin-content-docs/src/client/docsUtils.tsx, packages/docusaurus-plugin-content-docs/src/client/__tests__/docsUtils.test.tsx, packages/docusaurus-plugin-content-docs/src/__tests__/docCardList.test.tsx, vitest.config.ts
The helper searches for a matching category before searching for a document link. Tests cover duplicate category indexes, document trails, nested indexes, sibling selection, and overview cards. The Vitest theme alias points to the theme source directory.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested labels: pr: bug fix

Merge Risk: Minimal · up to c7f7a

This change makes category overview pages resolve to the correct category in sidebar breadcrumbs and card lists. It adds regression tests for the affected cases. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the fix (prefer category indexes over document references) and the area (docs). This matches the main change: getSidebarBreadcrumbs now searches for matching category indexes before fa…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the fix (prefer category indexes over document references) and the area (docs). This matches the main change: getSidebarBreadcrumbs now searches for matching category indexes before falling back to document links, which resolves DocCardList rendering cards from the wrong category. The title is specific and concise, and the "(AI-assisted)" suffix is extra noise but does not make it inaccurate.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 997cbdcc-d6c2-440d-ae5a-a914bb81d2a2
Commits

Reviewing files that changed from the base of the PR and between 809ffff and c7f7aea.

Files selected for processing: 4

  • packages/docusaurus-plugin-content-docs/src/__tests__/docCardList.test.tsx
  • packages/docusaurus-plugin-content-docs/src/client/__tests__/docsUtils.test.tsx
  • packages/docusaurus-plugin-content-docs/src/client/docsUtils.tsx
  • vitest.config.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@netlify

netlify Bot commented Nov 22, 2026

Copy link
Copy Markdown

✅ [V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit c7f7aea
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/6b03218fb59022b4a41d2d8f
😎 Deploy Preview https://deploy-preview-13103--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant