Skip to content

Commit

Permalink
fix(enhanced-readabilities): wait for nextTick before cleaning the ho…
Browse files Browse the repository at this point in the history
…vering block (#118)

Signed-off-by: Neko Ayaka <neko@ayaka.moe>
  • Loading branch information
nekomeowww authored Mar 25, 2024
1 parent f5c510e commit f74c9f7
Showing 1 changed file with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { inject, onMounted, reactive, ref, watch } from 'vue'
import { inject, nextTick, onMounted, reactive, ref, watch } from 'vue'
import {
useElementBounding,
useElementByPoint,
Expand Down Expand Up @@ -33,29 +33,6 @@ const elementVisibility = useElementVisibility(highlightedElement)
useEventListener('scroll', bounding.update, true)
onMounted(() => {
if (!document)
return
if (!document.body)
return
document.body.style.setProperty('--vp-nolebase-enhanced-readabilities-spotlight-under-bg-color', options?.spotlight?.hoverBlockColor || `rgb(240 197 52 / 10%)`)
vpDocElement.value = document.querySelector('.VPDoc main .vp-doc') as HTMLDivElement
})
watch(route, () => {
vpDocElement.value = document.querySelector('.VPDoc main .vp-doc') as HTMLDivElement
shouldRecalculate.value = true
boxStyles.value = { display: 'none' }
bounding.update()
watchHandler()
shouldRecalculate.value = false
})
function computeBoxStyles(bounding: {
height: number
left: number
Expand Down Expand Up @@ -130,6 +107,33 @@ function watchHandler() {
}
}
onMounted(() => {
if (!document)
return
if (!document.body)
return
document.body.style.setProperty('--vp-nolebase-enhanced-readabilities-spotlight-under-bg-color', options?.spotlight?.hoverBlockColor || `rgb(240 197 52 / 10%)`)
vpDocElement.value = document.querySelector('.VPDoc main .vp-doc') as HTMLDivElement
})
watch(route, async () => {
// Wait for the next tick to ensure the DOM is updated since the route change
// may trigger a page reload.
await nextTick()
vpDocElement.value = document.querySelector('.VPDoc main .vp-doc') as HTMLDivElement
shouldRecalculate.value = true
boxStyles.value = { display: 'none' }
bounding.update()
watchHandler()
shouldRecalculate.value = false
})
watch([x, y], () => {
if (props.enabled)
watchHandler()
Expand Down

0 comments on commit f74c9f7

Please sign in to comment.