Skip to content

Commit e4f19b5

Browse files
authored
fix: remove large downloads chart re-render (npmx-dev#713)
1 parent 0b157cf commit e4f19b5

4 files changed

Lines changed: 16 additions & 34 deletions

File tree

app/components/Package/DownloadAnalytics.vue

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,9 @@ const rootEl = shallowRef<HTMLElement | null>(null)
2020
2121
const { width } = useElementSize(rootEl)
2222
23-
const chartKey = ref(0)
24-
25-
let chartRemountTimeoutId: ReturnType<typeof setTimeout> | null = null
26-
2723
onMounted(() => {
2824
rootEl.value = document.documentElement
2925
resolvedMode.value = colorMode.value === 'dark' ? 'dark' : 'light'
30-
31-
// If the chart is painted too early, built-in auto-sizing does not adapt to the final container size
32-
chartRemountTimeoutId = setTimeout(() => {
33-
chartKey.value += 1
34-
chartRemountTimeoutId = null
35-
}, 1)
36-
})
37-
38-
onBeforeUnmount(() => {
39-
if (chartRemountTimeoutId !== null) {
40-
clearTimeout(chartRemountTimeoutId)
41-
chartRemountTimeoutId = null
42-
}
4326
})
4427
4528
const { colors } = useCssVariables(
@@ -718,12 +701,7 @@ const config = computed(() => {
718701
</div>
719702

720703
<ClientOnly v-if="inModal && chartData.dataset">
721-
<VueUiXy
722-
:dataset="chartData.dataset"
723-
:config="config"
724-
class="[direction:ltr]"
725-
:key="chartKey"
726-
>
704+
<VueUiXy :dataset="chartData.dataset" :config="config" class="[direction:ltr]">
727705
<template #menuIcon="{ isOpen }">
728706
<span v-if="isOpen" class="i-carbon:close w-6 h-6" aria-hidden="true" />
729707
<span v-else class="i-carbon:overflow-menu-vertical w-6 h-6" aria-hidden="true" />
@@ -836,8 +814,10 @@ const config = computed(() => {
836814
}
837815
838816
/* Override default placement of the refresh button to have it to the minimap's side */
839-
#download-analytics .vue-data-ui-refresh-button {
840-
top: -0.6rem !important;
841-
left: calc(100% + 2rem) !important;
817+
@media screen and (min-width: 767px) {
818+
#download-analytics .vue-data-ui-refresh-button {
819+
top: -0.6rem !important;
820+
left: calc(100% + 2rem) !important;
821+
}
842822
}
843823
</style>

app/components/Package/WeeklyDownloadStats.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ const props = defineProps<{
1111
const chartModal = useModal('chart-modal')
1212
1313
const isChartModalOpen = shallowRef(false)
14-
function openChartModal() {
14+
async function openChartModal() {
1515
isChartModalOpen.value = true
1616
// ensure the component renders before opening the dialog
17-
nextTick(() => chartModal.open())
17+
await nextTick()
18+
await nextTick()
19+
chartModal.open()
1820
}
1921
2022
const { fetchPackageDownloadEvolution } = useCharts()

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"vite-plugin-pwa": "1.2.0",
9292
"vite-plus": "0.0.0-833c515fa25cef20905a7f9affb156dfa6f151ab",
9393
"vue": "3.5.27",
94-
"vue-data-ui": "3.14.1"
94+
"vue-data-ui": "3.14.2"
9595
},
9696
"devDependencies": {
9797
"@npm/types": "2.1.0",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)