From 8bbe8aad947f3b016d0b3092383a2139c0246634 Mon Sep 17 00:00:00 2001 From: Mike Plummer Date: Fri, 10 Jun 2022 11:38:55 -0500 Subject: [PATCH 1/5] fix: SpecsList scrolling performance fixes * Debounce virtualized list scroll monitor to avoid interrupting smooth scroll * Fix 'scroll to top' watcher to only trigger when content of specs list changes rather than reference --- packages/app/src/specs/SpecsList.vue | 14 +++++++++++++- .../src/composables/useVirtualList.ts | 6 +++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/app/src/specs/SpecsList.vue b/packages/app/src/specs/SpecsList.vue index edb17b1f014a..18431c229d90 100644 --- a/packages/app/src/specs/SpecsList.vue +++ b/packages/app/src/specs/SpecsList.vue @@ -394,7 +394,7 @@ useResizeObserver(containerProps.ref, (entries) => { // If you are scrolled down the virtual list and list changes, // reset scroll position to top of list -watch(() => treeSpecList.value, () => scrollTo(0)) +watch(() => hashCode(treeSpecList.value.map((spec) => spec.id)), () => scrollTo(0)) function getIdIfDirectory (row) { if (row.data.isLeaf && row.data) { @@ -431,6 +431,18 @@ function refreshPage () { location.reload() } +/** + * Generate a quasi-hash value to decompose an array of strings into a single numeric value that can be used to + * see whether it has changed from previous value(s). + */ +function hashCode (values: string[]): number { + return values.reduce((a, b) => { + a = ((a << 5) - a) + b.charCodeAt(0) + + return a & a + }, 0) +} +