Skip to content

Commit d99bc67

Browse files
authored
fix: timeout chart re-render (#629)
1 parent fea10d0 commit d99bc67

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

app/components/PackageDownloadAnalytics.vue

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,24 @@ const { width } = useElementSize(rootEl)
2121
2222
const chartKey = ref(0)
2323
24-
function nextAnimationFrame(): Promise<void> {
25-
return new Promise(resolve => {
26-
requestAnimationFrame(() => resolve())
27-
})
28-
}
24+
let chartRemountTimeoutId: ReturnType<typeof setTimeout> | null = null
2925
30-
onMounted(async () => {
26+
onMounted(() => {
3127
rootEl.value = document.documentElement
3228
resolvedMode.value = colorMode.value === 'dark' ? 'dark' : 'light'
3329
3430
// If the chart is painted too early, built-in auto-sizing does not adapt to the final container size
35-
await nextAnimationFrame()
36-
await nextAnimationFrame()
37-
await nextAnimationFrame()
38-
chartKey.value += 1
31+
chartRemountTimeoutId = setTimeout(() => {
32+
chartKey.value += 1
33+
chartRemountTimeoutId = null
34+
}, 10)
35+
})
36+
37+
onBeforeUnmount(() => {
38+
if (chartRemountTimeoutId !== null) {
39+
clearTimeout(chartRemountTimeoutId)
40+
chartRemountTimeoutId = null
41+
}
3942
})
4043
4144
const { colors } = useCssVariables(

0 commit comments

Comments
 (0)