Skip to content

Commit 994182a

Browse files
committed
fix(rolldown): avoid invalid comparison percentages
1 parent b69c7d0 commit 994182a

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

packages/rolldown/src/app/components/display/ComparisonMetric.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ const props = defineProps<{
77
}>()
88
99
const isNotChanged = computed(() => props.previous === props.current)
10-
const normalizedPercent = computed(() => Math.abs((props.current - props.previous) / props.previous * 100).toFixed(isNotChanged.value ? 0 : 2))
10+
const normalizedPercent = computed(() => {
11+
if (isNotChanged.value)
12+
return '0'
13+
if (props.previous === 0)
14+
return '100.00'
15+
16+
return Math.abs((props.current - props.previous) / props.previous * 100).toFixed(2)
17+
})
1118
const trendSymbol = computed(() => isNotChanged.value ? '' : (props.current > props.previous ? '+' : '-'))
1219
const comparisonColorClass = computed(() => isNotChanged.value ? 'text-gray-500' : (props.current > props.previous ? 'text-green-500' : 'text-red-500'))
1320
</script>

0 commit comments

Comments
 (0)