Skip to content

fix(theme): fix getSidebar's buggy logic when supporting subtree-lift… #4842

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

chlsczx
Copy link

@chlsczx chlsczx commented Jul 15, 2025

fix(theme): fix getSidebar's buggy logic when supporting subtree-lift…

close #4841

Description

This PR resolves when sidebar config object owns a uplifting subtree node (by duplication), getSidebar will match the obviously wrong dir links, for example described in issue #4841, /api-examples.md will be matched to /a.

Not only when there is subtree lifting will the bug reproduce, and I'm also afraid when doing matching of /api-b/a.md, it will be matched to /api/, and I also proved this guess, the sidebar object is, can also see my repo's newest commit:

"sidebar": {
    "/api": [
      {
        "text": "jdjd",
        "link": "/api/jdjd.md",
        ".sort_base": "jdjd.md"
      }
    ],
    "/api-aaa": [
      {
        "text": "a copy",
        "link": "/api-aaa/a-copy",
        "collapsed": true,
        "items": [
          {
            "text": "Runtime API Examples",
            "link": "/api-aaa/a-copy/api-examples.md",
            ".sort_base": "api-examples.md"
          },
          {
            "text": "Markdown Extension Examples",
            "link": "/api-aaa/a-copy/markdown-examples.md",
            ".sort_base": "markdown-examples.md"
          }
        ],
        ".sort_base": "a-copy"
      },
      {
        "text": "📂 b-copy",
        "collapsed": true,
        "items": [
          {
            "text": "Markdown Extension Examples",
            "link": "/api-aaa/b-copy/markdown-examples.md",
            ".sort_base": "markdown-examples.md"
          },
          {
            "text": "Runtime API Examples",
            "link": "/api-aaa/b-copy/z_api-examples.md",
            ".sort_base": "z_api-examples.md"
          }
        ],
        ".sort_base": "b-copy"
      }
    ],
    "/": [
      {
        "text": "Runtime API Examples",
        "link": "/api-examples.md",
        ".sort_base": "api-examples.md"
      },
      {
        "text": "Markdown Extension Examples",
        "link": "/markdown-examples.md",
        ".sort_base": "markdown-examples.md"
      },
      {
        "text": "📂 api",
        "collapsed": true,
        "items": [
          {
            "text": "jdjd",
            "link": "/api/jdjd.md",
            ".sort_base": "jdjd.md"
          }
        ],
        ".sort_base": "api"
      },
      {
        "text": "a",
        "link": "/api-aaa",
        "collapsed": true,
        "items": [
          {
            "text": "a copy",
            "link": "/api-aaa/a-copy",
            "collapsed": true,
            "items": [
              {
                "text": "Runtime API Examples",
                "link": "/api-aaa/a-copy/api-examples.md",
                ".sort_base": "api-examples.md"
              },
              {
                "text": "Markdown Extension Examples",
                "link": "/api-aaa/a-copy/markdown-examples.md",
                ".sort_base": "markdown-examples.md"
              }
            ],
            ".sort_base": "a-copy"
          },
          {
            "text": "📂 b-copy",
            "collapsed": true,
            "items": [
              {
                "text": "Markdown Extension Examples",
                "link": "/api-aaa/b-copy/markdown-examples.md",
                ".sort_base": "markdown-examples.md"
              },
              {
                "text": "Runtime API Examples",
                "link": "/api-aaa/b-copy/z_api-examples.md",
                ".sort_base": "z_api-examples.md"
              }
            ],
            ".sort_base": "b-copy"
          }
        ],
        ".sort_base": "api-aaa"
      }
    ]
  }

And my PR also fixed this problem.

Linked Issues

fixes #4841

Additional Context


Tip

The author of this PR can publish a preview release by commenting /publish below.

Copy link

pkg-pr-new bot commented Jul 23, 2025

npm i https://pkg.pr.new/vitepress@4842

commit: 3de77e5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

getSidebar's matching logic is buggy: Does not support non-strictly hierarchical sidebar config objects (with subtree lifting via duplication)
2 participants