avoid computing tooltip position every frame
All checks were successful
Lint / pnpm_install (pull_request) Successful in 2m59s
Test (frontend) / vitest (22.x) (pull_request) Successful in 2m56s
Test (production install and build) / production (22.x) (pull_request) Successful in 2m16s
Lint / lint (backend) (pull_request) Successful in 2m26s
Lint / lint (frontend) (pull_request) Successful in 9m0s
Lint / lint (misskey-js) (pull_request) Successful in 1m59s
Lint / lint (sw) (pull_request) Successful in 2m13s
Lint / typecheck (backend) (pull_request) Successful in 2m41s
Lint / typecheck (misskey-js) (pull_request) Successful in 1m57s

this fixes an issue causing misskey to constantly recompute tooltip
position when any kind of chart is being displayed (such as the one
on user profile page, or any page for unauthenticated users)
This commit is contained in:
sugar 2025-02-02 17:33:33 +01:00
parent 8165088886
commit 71606c5507

View file

@ -23,7 +23,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { nextTick, onMounted, onUnmounted, shallowRef } from 'vue'; import { nextTick, onMounted, onUnmounted, shallowRef, watch } from 'vue';
import * as os from '@/os.js'; import * as os from '@/os.js';
import { calcPopupPosition } from '@/scripts/popup-position.js'; import { calcPopupPosition } from '@/scripts/popup-position.js';
import { defaultStore } from '@/store.js'; import { defaultStore } from '@/store.js';
@ -70,7 +70,7 @@ function setPosition() {
el.value.style.top = data.top + 'px'; el.value.style.top = data.top + 'px';
} }
let loopHandler; let loopHandler: number | undefined;
onMounted(() => { onMounted(() => {
nextTick(() => { nextTick(() => {
@ -81,12 +81,23 @@ onMounted(() => {
loopHandler = window.requestAnimationFrame(loop); loopHandler = window.requestAnimationFrame(loop);
}; };
loop(); watch(() => props.showing, show => {
if (show) {
if (!loopHandler) {
loop();
}
} else if (loopHandler) {
window.cancelAnimationFrame(loopHandler);
loopHandler = undefined;
}
});
}); });
}); });
onUnmounted(() => { onUnmounted(() => {
window.cancelAnimationFrame(loopHandler); if (loopHandler) {
window.cancelAnimationFrame(loopHandler);
}
}); });
</script> </script>