fix: scroll to top on survey slide change via useEffect

requestAnimationFrame was still too early. Use a useEffect on
currentSlide so the scroll fires after React commits the new
slide to the DOM. Skips initial render to avoid scroll on load.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Michael Chihlas
2026-03-07 18:31:03 -05:00
parent 9c7859a889
commit b6eaacb9f9

View File

@@ -188,11 +188,18 @@ export default function SurveyPage() {
const goSlide = (idx: number) => {
setCurrentSlide(idx)
requestAnimationFrame(() => {
window.scrollTo({ top: 0, behavior: 'smooth' })
})
}
// Scroll to top whenever the active slide changes
const isFirstRender = useRef(true)
useEffect(() => {
if (isFirstRender.current) {
isFirstRender.current = false
return
}
window.scrollTo({ top: 0, behavior: 'smooth' })
}, [currentSlide])
const handleSubmit = async () => {
setIsSubmitting(true)
setSubmitError('')