Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatePicker takes all CPU #1489

Open
PascalArdex opened this issue Jul 25, 2024 · 0 comments
Open

DatePicker takes all CPU #1489

PascalArdex opened this issue Jul 25, 2024 · 0 comments

Comments

@PascalArdex
Copy link

We are using v-calendar for a while and have good results with it

Now we noticed a performance issue wit the DatePicker component
We just open the DatePicker in its most basic usage

This is the full code of our wrapper component

<template>
  <BasePopover class="w-full" :popper="{ placement: 'bottom-start' }">
    <BaseInput v-bind="$attrs" :model-value="formatedDate" class="!w-full"></BaseInput>
    <template #panel="{ close }">
      <DatePicker title-position="left" v-model="date" mode="date" @update:modelValue="close" />
    </template>
  </BasePopover>
</template>
<script setup lang="ts">
import { computed } from 'vue';
import 'v-calendar/style.css';
import { DatePicker } from 'v-calendar';
import { useDateFormat } from '@vueuse/core'
import { DateFormats } from '@/constants/date';


const props = defineProps({
  modelValue: {
    type: [String, Number, Date],
    default: '',
  },
  formatDate: {
    type: String,
    default: DateFormats.DEFAULT,
  }
});

const emit = defineEmits<{
  (event: 'update:modelValue', value: string | number | Date): void;
}>();

const date = computed({
  get: () => props.modelValue || '',
  set: (value) => {
    emit('update:modelValue', value);
  },
});

const formatedDate = computed(() => {
  if (!date.value) {
    return ''
  }
  return useDateFormat(date.value, props.formatDate).value || ''
})
</script>

This is Firefox profiler showing this component takes all the CPU
image

A deeper look does not teach me much more
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant