From 98b8124577d8e50830f22b220dd0f5758b6036c6 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 4 Dec 2024 09:15:02 +0100 Subject: [PATCH] perf: remove setTimeOut insteaduse requestAnimationFrame --- src/pages/Order/Card/OrderCatalog.vue | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/pages/Order/Card/OrderCatalog.vue b/src/pages/Order/Card/OrderCatalog.vue index f3121fb6d..948970cc3 100644 --- a/src/pages/Order/Card/OrderCatalog.vue +++ b/src/pages/Order/Card/OrderCatalog.vue @@ -78,17 +78,16 @@ watch( { immediate: true } ); const onItemSaved = (updatedItem) => { - scrollToItem(updatedItem.items[0].itemFk); + requestAnimationFrame(() => { + scrollToItem(updatedItem.items[0].itemFk); + }); }; const scrollToItem = async (id) => { - await nextTick(); - setTimeout(() => { - const element = itemRefs.value[id]?.$el; - if (element) { - element.scrollIntoView({ behavior: 'smooth', block: 'center' }); - } - }, 100); + const element = itemRefs.value[id]?.$el; + if (element) { + element.scrollIntoView({ behavior: 'smooth', block: 'center' }); + } }; provide('onItemSaved', onItemSaved);