Skip to content
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

[BUG] sidebar : switching pages collapsed sidebar items NOT expand #3613

Open
4 tasks done
Zhengqbbb opened this issue Feb 28, 2024 · 4 comments
Open
4 tasks done

[BUG] sidebar : switching pages collapsed sidebar items NOT expand #3613

Zhengqbbb opened this issue Feb 28, 2024 · 4 comments
Labels
bug Something isn't working stale theme Related to the theme

Comments

@Zhengqbbb
Copy link
Contributor

Describe the bug

switching pages collapsed sidebar items NOT expand

Reproduction

https://stackblitz.com/edit/vite-bvmtz6?file=docs%2F.vitepress%2Fconfig.ts

Arc.mp4

Expected behavior

auto expand collapsed sidebar items when switching pages

System Info

https://stackblitz.com/edit/vite-bvmtz6?file=docs%2F.vitepress%2Fconfig.ts

Additional context

It should be caused by recent changes, and the previous version was normal.

Validations

@Zhengqbbb Zhengqbbb added the bug: pending triage Maybe a bug, waiting for confirmation label Feb 28, 2024
@Shyam-Chen
Copy link

    sidebar: {
      '/foo': [
        {
          text: 'hello',
          collapsed: true,
          items: [
            {
              text: 'a',
              link: '/foo/a',
            },
            {
              text: 'b',
              link: '/foo/b',
            },
          ],
        },
      ],
      '/bar': [
        {
-         text: 'hello',
+         text: 'hello 2',
          collapsed: true,
          items: [
            {
              text: 'a',
              link: '/bar/a',
            },
            {
              text: 'b',
              link: '/bar/b',
            },
          ],
        },
      ],
    },

@Zhengqbbb
Copy link
Contributor Author

Zhengqbbb commented Feb 29, 2024

@Shyam-Chen

-         text: 'hello',
+         text: 'hello 2',

What you want to express is that :key causes a problem with rendering, I know this.
But it is also possible that the sidebar structure is the same, but the content is different

@Zhengqbbb
Copy link
Contributor Author

I tried to use the sidebar match value to add to the outermost SidebarItem :key
Ensure basic caching feature and update when sidebar match changes
But I don't know if this is possible or have better way

export function getSidebarMatchPath(
  sidebar: DefaultTheme.Sidebar | undefined,
  _path: string
): string {
  if (Array.isArray(sidebar) || sidebar == null) return ''
  const path = ensureStartingSlash(_path)
  return Object.keys(sidebar).find((key) => {
    return path.startsWith(ensureStartingSlash(key))
  }) || ''
}
- <div v-for="item in sidebarGroups" :key="item.text" class="group">
+ <div v-for="item in sidebarGroups" :key="sidebarMatchPath + item.text" class="group">

@Zhengqbbb
Copy link
Contributor Author

Zhengqbbb commented Mar 7, 2024

Can I offer help, such as testing or PR ? or have any other think?
Because I haven't seen the label change for this ISSUE yet. 👀

@brc-dd brc-dd added bug Something isn't working theme Related to the theme and removed bug: pending triage Maybe a bug, waiting for confirmation labels Mar 7, 2024
@github-actions github-actions bot added the stale label Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale theme Related to the theme
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants