Huzaifa727 Posted August 5, 2023 Posted August 5, 2023 Hi I am having a problem using ScrollTrigger with React Router. I have two pages in my website Home and About. The animation on homepage works perfectly but when I navigate to About page I get this error. "Node.removeChild: The node to be removed is not a child of this node" If I visit About Page by direct url without using router then the Animation on About page works fine but If I navigate to Home page from About page then the same error happens again. I am new to Scrolltrigger and also react and I've been trying to solve this for days but I couldn't find any solution on the internet. That's why I posted here. Anyway below is the url to the StackBlitz code of my project. https://stackblitz.com/edit/stackblitz-starters-bldghh
Rodrigo Posted August 6, 2023 Posted August 6, 2023 Hi @Huzaifa727 and welcome to the GreenSock forums! I couldn't really tell you where is your problem without dissecting throw your code, but there must be some issue in the way you're setting up React Router. As you can see this example works as expected: https://stackblitz.com/edit/vitejs-vite-d73sck So this definitely is not something related with GSAP. Unfortunately I don't have time right now to go through your setup and find the issue, so hopefully the example above shed some light on your demo and setup so you can fix the issue. Happy Tweening!
GreenSock Posted August 6, 2023 Posted August 6, 2023 My guess is that it might have to do with the fact that ScrollTrigger has to inject a pin-spacer <div> around the element that's being pinned and React is complaining. To solve that, you can just use your own wrapper element instead, and feed it in as the pinSpacer: https://stackblitz.com/edit/stackblitz-starters-myr23m?file=src%2Fcomponents%2Fhome.js,src%2Fcomponents%2Fabout.js That way, nothing is getting added/removed during refreshes - all the DOM structure stays the same. Does that resolve things? 1
Huzaifa727 Posted August 6, 2023 Author Posted August 6, 2023 @Rodrigo I did something similar to your solution. In my Home and About components I had multiple elements that's why I was using React Fragments (<> </>) to wrap them. Instead of this I wrapped my elements into a <main> element and it is working now. Thanks a lot Sir! 1
Rodrigo Posted August 7, 2023 Posted August 7, 2023 Hi, That's great and also confirms what Jack hinted in his post. Thanks for sharing the solution with the community! ? Happy Tweening!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now