Skip to content

Commit 33962e0

Browse files
committedAug 16, 2023
fix(theme): prevent sidebar re-render unless there is actual change
closes #2796
1 parent 6960ec1 commit 33962e0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed
 

‎src/client/theme-default/composables/sidebar.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,19 @@ export function useSidebar() {
3535

3636
const isOpen = ref(false)
3737

38-
const sidebar = computed(() => {
38+
const _sidebar = computed(() => {
3939
const sidebarConfig = theme.value.sidebar
4040
const relativePath = page.value.relativePath
4141
return sidebarConfig ? getSidebar(sidebarConfig, relativePath) : []
4242
})
4343

44+
const sidebar = ref(_sidebar.value)
45+
46+
watch(_sidebar, (next, prev) => {
47+
if (JSON.stringify(next) !== JSON.stringify(prev))
48+
sidebar.value = _sidebar.value
49+
})
50+
4451
const hasSidebar = computed(() => {
4552
return (
4653
frontmatter.value.sidebar !== false &&

0 commit comments

Comments
 (0)
Please sign in to comment.