Hey, First of all thanks for your great work with this great tool!
I'm gonna try to keep it short so bear with me if this ends up a long post. So my dev stack is Vue + Vite + Inertia + Laravel and I've used gsap here and there in few projects and I never had any issues with it so far ?.
But I just started working on a new demo website for a client where I'm using gsap almost everywhere.
And the problem is I'm seeing some weird behavior which I can summarize in 2 points:
Some animations that are supposed to start by ScrollTrigger, won't work. This happens only sometimes and it happens randomly and I cant pinpoint it to an exact component. For instance an element that has initial opacity of 0 and should change to opacity of 100 when it's in the viewport, it does not work. Sometimes this throws an error saying Cannot read properties of undefined (reading 'pin') and sometimes it doesn't even throw this error. But here is how the error looks like :And below image is the code related
Some timeline animations act weirdly when I navigate away from the page and come back to it. Like after the initial playback, when you navigate to a different page and go back to try to see the component with the timeline animation again, it start from a certain point of the timeline as if it was cached somewhere, I even noticed some of the element styles from the first playback are still applied ( Even though I double checked the DOM element does not exist when I navigate to a different page, and I also checked Vue Devtools to make sure the component isn't there either. But still somehow )
I'm not sure why these problems are happening. Maybe it's my "heavy" usage of GSAP, which I doubt because I'm sure there are tons of websites out there that totally surpass my usage and are probably doing fine. Or maybe the problem is that GSAP does not play well with SPA apps. Or maybe It's my code.
I know you're gonna ask for a replicate demo so you can look into, but trust me I cannot even replicate the problem myself because it happens randomly under unknown circumstances. Also I have a custom setup which I think will be a hell of a job to duplicate in an online code sandbox tool.
But I can DM you the URL of the demo that I'm working on ( sorry can't share it here for privacy reasons )
Here are the things that I've tried :
I've tried adding gsap to the optimizeDeps.include of my vite.config.ts file
I've tried killing the gsap timeline instance during component unmount :
onBeforeUnmount(() => {
productsTimeline?.clear()
productsTimeline?.kill()
productsTimeline = null
})
I've tried different combinations of to , fromto and from but no luck
I've tried using ScrollTrigger.refresh() in places where I thought there should be one, like after initializing a Swiper instance :
products_swiper.value = new Swiper('#products-swiper', {
on: {
init: () => {
ScrollTrigger.refresh()
}
}
}
A bunch of other things I don't quite remember ( like using an id on ScrollTrigger, etc... )
And this would be an example how I use gsap in my Vue components :
import { gsap, ScrollTrigger } from '@/js/utils/gsap'
onMounted(() => {
gsap.fromTo('#why-section .gsap-why-title', {
scale: 1.2,
autoAlpha: 0,
}, {
scrollTrigger: {
trigger: '#why-section .gsap-why-title',
once: true,
start: 'top center+=300px',
end: 'bottom bottom',
},
scale: 1,
autoAlpha: 1,
duration: 1,
ease: 'power3.out',
delay: 0.5,
})
})
// And in my '@/js/utils/gsap' file I have :
import gsap from 'gsap'
import ScrollTrigger from 'gsap/ScrollTrigger'
gsap.registerPlugin(ScrollTrigger)
export { gsap, ScrollTrigger }
Any ideas ?
Thanks in advance!