Skip to content

Commit

Permalink
fix: added deep watch to Scrollspy composable to correctly update act…
Browse files Browse the repository at this point in the history
…iveHeadings (#701)

Even though visibleHeadings are correctly updated using Intersection Observer API, watching visibleHeadings does not get executed when visibleHeadings change. Changing to deep watcher fixes this
  • Loading branch information
Zerro97 authored Dec 1, 2022
1 parent 1237388 commit ab5e8d4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion composables/useScrollspy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const useScrollspy = () => {

watch(visibleHeadings, (val, oldVal) => {
if (val.length === 0) { activeHeadings.value = oldVal } else { activeHeadings.value = val }
})
}, { deep: true })

// Create intersection observer
onBeforeMount(() => (observer.value = new IntersectionObserver(observerCallback)))
Expand Down

1 comment on commit ab5e8d4

@vercel
Copy link

@vercel vercel bot commented on ab5e8d4 Dec 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.