In a project I'm coding, I am using window.requestAnimationFrame in order to make an animation repeat each time a button is clicked. I'm very confused though because after I refresh the page, if I click the button two times, the second time the animation doesn't happen. It only works on the second time if I click something else on the page before clicking the button, but if I click it immediately after refreshing, it doesn't. Here's some of the code from the button when it is clicked, but if you need more code, I can provide it. Thanks in advance for the help!
submitNewPlunderForm.onclick = () => {
let users = JSON.parse(localStorage.users);
let username = newPlunderFormUsername.value;
if (users[username] === undefined) {
newPlunderFormUsername.style.border = "1.5px solid #eb3a34";
newPlunderFormUsername.style.boxShadow = "none";
newPlunderFormUsername.style.transition = "none";
window.requestAnimationFrame(function() {
newPlunderFormUsername.style.transition = "box-shadow 200ms";
newPlunderFormUsername.style.boxShadow = "0 0 5px #eb3a34";
});