Workaround Safari bug for patch count update

This commit is contained in:
Jared Schoeny 2025-12-12 01:57:27 -10:00
parent fe4ecf5e09
commit 0c9c79f969

View File

@ -221,13 +221,16 @@ const HackActions: React.FC<HackActionsProps> = ({
deviceId = crypto.randomUUID();
localStorage.setItem(key, deviceId);
}
const deviceIdObscured = deviceId.split("-");
const result = await updatePatchDownloadCount(patchId, deviceIdObscured);
if (!result.ok) {
console.error(result.error);
} else if (result.didIncrease) {
window.dispatchEvent(new CustomEvent<DownloadEventDetail>("hack:patch-applied", { detail: { slug: hackSlug } }));
}
// Defer update to next tick to avoid Safari cancelling the request
setTimeout(async () => {
const deviceIdObscured = deviceId.split("-");
const result = await updatePatchDownloadCount(patchId, deviceIdObscured);
if (!result.ok) {
console.error(result.error);
} else if (result.didIncrease) {
window.dispatchEvent(new CustomEvent<DownloadEventDetail>("hack:patch-applied", { detail: { slug: hackSlug } }));
}
}, 0);
}
} catch {}
} catch (e: any) {