From 455f911aae8aceb6d20bfc2e06597c4ee2956bf0 Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Sun, 20 Oct 2024 18:37:15 +0900 Subject: [PATCH] comment --- packages/frontend/src/boot/main-boot.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/frontend/src/boot/main-boot.ts b/packages/frontend/src/boot/main-boot.ts index 8847ebcc0f..cfe4e124be 100644 --- a/packages/frontend/src/boot/main-boot.ts +++ b/packages/frontend/src/boot/main-boot.ts @@ -248,8 +248,11 @@ export async function mainBoot() { } window.addEventListener('visibilitychange', () => { + const now = Date.now(); + if (document.visibilityState === 'visible') { - if ((Date.now() - lastVisibilityChangedAt) < 1000 * 10) { + // タブを高速で切り替えたら取得処理が何度も走るのを防ぐ + if ((now - lastVisibilityChangedAt) < 1000 * 10) { justPlainLuckyTimer = window.setTimeout(claimPlainLucky, 1000 * 10); } else { claimPlainLucky(); @@ -259,7 +262,7 @@ export async function mainBoot() { justPlainLuckyTimer = null; } - lastVisibilityChangedAt = Date.now(); + lastVisibilityChangedAt = now; }, { passive: true }); claimPlainLucky();