Skip to content

Commit e7900ca

Browse files
fix(ux): retry scroll with requestAnimationFrame until DOM ready
Replaces fixed 300ms setTimeout with rAF loop that retries until #treinos-pessoais anchor exists in DOM. Eliminates race condition on slow devices / slow RSC renders. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent e49ed5f commit e7900ca

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/app/aluno/meus-treinos/meus-treinos-client.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,15 @@ export default function MeusTreinosClient({
6363
notify,
6464
onSuccess: () => {
6565
router.refresh();
66-
setTimeout(() => {
67-
document
68-
.getElementById('treinos-pessoais')
69-
?.scrollIntoView({ behavior: 'smooth', block: 'start' });
70-
}, 300);
66+
const scrollToTreinos = () => {
67+
const el = document.getElementById('treinos-pessoais');
68+
if (el) {
69+
el.scrollIntoView({ behavior: 'smooth', block: 'start' });
70+
return;
71+
}
72+
requestAnimationFrame(scrollToTreinos);
73+
};
74+
requestAnimationFrame(scrollToTreinos);
7175
},
7276
});
7377

0 commit comments

Comments
 (0)