Skip to content

Commit 88e188b

Browse files
committed
perf(ui): defer vue-data-ui styles until chart mount
1 parent 3186091 commit 88e188b

File tree

5 files changed

+74
-11
lines changed

5 files changed

+74
-11
lines changed

app/components/Compare/FacetBarChart.vue

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import {
1414
copyAltTextForCompareFacetBarChart,
1515
} from '~/utils/charts'
1616
17-
import('vue-data-ui/style.css')
18-
1917
const props = defineProps<{
2018
values: (FacetValue | null | undefined)[]
2119
packages: string[]
@@ -24,6 +22,7 @@ const props = defineProps<{
2422
facetLoading?: boolean
2523
}>()
2624
25+
const { stylesLoaded } = useVueDataUiStyles()
2726
const colorMode = useColorMode()
2827
const resolvedMode = shallowRef<'light' | 'dark'>('light')
2928
const rootEl = shallowRef<HTMLElement | null>(null)
@@ -278,7 +277,13 @@ const config = computed<VueUiHorizontalBarConfig>(() => {
278277
<template>
279278
<div class="font-mono facet-bar">
280279
<ClientOnly v-if="dataset.length">
281-
<VueUiHorizontalBar :key="chartKey" :dataset :config class="[direction:ltr]">
280+
<VueUiHorizontalBar
281+
v-if="stylesLoaded"
282+
:key="chartKey"
283+
:dataset
284+
:config
285+
class="[direction:ltr]"
286+
>
282287
<template #hint="{ isVisible }">
283288
<p v-if="isVisible" class="text-accent text-xs pt-2" aria-hidden="true">
284289
{{ $t('compare.packages.bar_chart_nav_hint') }}
@@ -338,6 +343,15 @@ const config = computed<VueUiHorizontalBarConfig>(() => {
338343
/>
339344
</template>
340345
</VueUiHorizontalBar>
346+
<template v-else>
347+
<div class="flex flex-col gap-2 justify-center items-center mb-2">
348+
<SkeletonInline class="h-4 w-16" />
349+
<SkeletonInline class="h-4 w-28" />
350+
</div>
351+
<div class="flex flex-col gap-1">
352+
<SkeletonInline class="h-7 w-full" v-for="pkg in packages" :key="pkg" />
353+
</div>
354+
</template>
341355

342356
<template #fallback>
343357
<div class="flex flex-col gap-2 justify-center items-center mb-2">

app/components/Package/TrendsChart.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import {
2626
import { applyBlocklistCorrection, getAnomaliesForPackages } from '~/utils/download-anomalies'
2727
import { copyAltTextForTrendLineChart, sanitise, loadFile, applyEllipsis } from '~/utils/charts'
2828
29-
import('vue-data-ui/style.css')
30-
3129
const props = withDefaults(
3230
defineProps<{
3331
// For single package downloads history
@@ -61,6 +59,7 @@ const { locale } = useI18n()
6159
const { accentColors, selectedAccentColor } = useAccentColor()
6260
const { settings } = useSettings()
6361
const { copy, copied } = useClipboard()
62+
const { stylesLoaded } = useVueDataUiStyles()
6463
6564
const colorMode = useColorMode()
6665
const resolvedMode = shallowRef<'light' | 'dark'>('light')
@@ -1877,6 +1876,7 @@ watch(selectedMetric, value => {
18771876
<ClientOnly v-if="chartData.dataset">
18781877
<div :data-pending="pending" :data-minimap-visible="maxDatapoints > 6">
18791878
<VueUiXy
1879+
v-if="stylesLoaded"
18801880
:dataset="normalisedDataset"
18811881
:config="chartConfig"
18821882
:class="{
@@ -2120,6 +2120,7 @@ watch(selectedMetric, value => {
21202120
/>
21212121
</template>
21222122
</VueUiXy>
2123+
<div v-else class="min-h-[260px]" />
21232124
</div>
21242125

21252126
<template #fallback>

app/components/Package/VersionDistribution.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ import {
1111
import TooltipApp from '~/components/Tooltip/App.vue'
1212
import { copyAltTextForVersionsBarChart, sanitise, loadFile, applyEllipsis } from '~/utils/charts'
1313
14-
import('vue-data-ui/style.css')
15-
1614
const props = defineProps<{
1715
packageName: string
1816
inModal?: boolean
1917
}>()
2018
2119
const { accentColors, selectedAccentColor } = useAccentColor()
2220
const { copy, copied } = useClipboard()
21+
const { stylesLoaded } = useVueDataUiStyles()
2322
2423
const colorMode = useColorMode()
2524
const resolvedMode = shallowRef<'light' | 'dark'>('light')
@@ -455,7 +454,12 @@ const chartConfig = computed<VueUiXyConfig>(() => {
455454
<!-- Chart content -->
456455
<ClientOnly v-if="xyDataset.length > 0 && !error">
457456
<div class="chart-container w-full" :key="groupingMode">
458-
<VueUiXy :dataset="xyDataset" :config="chartConfig" class="[direction:ltr]">
457+
<VueUiXy
458+
v-if="stylesLoaded"
459+
:dataset="xyDataset"
460+
:config="chartConfig"
461+
class="[direction:ltr]"
462+
>
459463
<!-- Keyboard navigation hint -->
460464
<template #hint="{ isVisible }">
461465
<p v-if="isVisible" class="text-accent text-xs -mt-6 text-center" aria-hidden="true">
@@ -634,6 +638,7 @@ const chartConfig = computed<VueUiXyConfig>(() => {
634638
/>
635639
</template>
636640
</VueUiXy>
641+
<div v-else />
637642
</div>
638643

639644
<template #fallback>

app/components/Package/WeeklyDownloadStats.vue

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import type { RepoRef } from '#shared/utils/git-providers'
99
import type { VueUiSparklineConfig, VueUiSparklineDatasetItem } from 'vue-data-ui'
1010
import { onKeyDown } from '@vueuse/core'
1111
12-
import('vue-data-ui/style.css')
13-
1412
const props = defineProps<{
1513
packageName: string
1614
createdIso: string | null
@@ -20,6 +18,7 @@ const props = defineProps<{
2018
const router = useRouter()
2119
const route = useRoute()
2220
const { settings } = useSettings()
21+
const { stylesLoaded } = useVueDataUiStyles()
2322
2423
const chartModal = useModal('chart-modal')
2524
const hasChartModalTransitioned = shallowRef(false)
@@ -424,7 +423,7 @@ const config = computed<VueUiSparklineConfig>(() => {
424423
<div class="w-full h-[76px] egg-pulse-target" :class="{ 'egg-pulse': eggPulse }">
425424
<template v-if="isLoadingWeeklyDownloads || hasWeeklyDownloads">
426425
<ClientOnly>
427-
<VueUiSparkline class="w-full max-w-xs" :dataset :config>
426+
<VueUiSparkline v-if="stylesLoaded" class="w-full max-w-xs" :dataset :config>
428427
<!-- Keyboard navigation hint -->
429428
<template #hint="{ isVisible }">
430429
<p v-if="isVisible" class="text-accent text-xs text-center mt-2" aria-hidden="true">
@@ -437,6 +436,21 @@ const config = computed<VueUiSparklineConfig>(() => {
437436
<div />
438437
</template>
439438
</VueUiSparkline>
439+
<template v-else>
440+
<div class="max-w-xs">
441+
<div class="h-6 flex items-center ps-3">
442+
<SkeletonInline class="h-3 w-36" />
443+
</div>
444+
<div class="aspect-[500/80] flex items-center">
445+
<div class="w-[42%] flex items-center ps-0.5">
446+
<SkeletonInline class="h-7 w-24" />
447+
</div>
448+
<div class="flex-1 flex items-end pe-3">
449+
<SkeletonInline class="h-px w-full" />
450+
</div>
451+
</div>
452+
</div>
453+
</template>
440454
<template #fallback>
441455
<!-- Skeleton matching VueUiSparkline layout (title 24px + SVG aspect 500:80) -->
442456
<div class="max-w-xs">
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const vueDataUiStylesLoaded = shallowRef(false)
2+
let vueDataUiStylesPromise: Promise<void> | null = null
3+
4+
async function loadVueDataUiStyles() {
5+
if (vueDataUiStylesLoaded.value) {
6+
return
7+
}
8+
9+
if (!vueDataUiStylesPromise) {
10+
vueDataUiStylesPromise = import('vue-data-ui/style.css').then(() => {
11+
vueDataUiStylesLoaded.value = true
12+
})
13+
}
14+
15+
await vueDataUiStylesPromise
16+
}
17+
18+
export function useVueDataUiStyles() {
19+
if (import.meta.client) {
20+
onMounted(() => {
21+
void loadVueDataUiStyles()
22+
})
23+
}
24+
25+
return {
26+
stylesLoaded: readonly(vueDataUiStylesLoaded),
27+
ensureStylesLoaded: loadVueDataUiStyles,
28+
}
29+
}

0 commit comments

Comments
 (0)