akrdesign Posted April 11, 2023 Share Posted April 11, 2023 This is my code https://github.com/akrdesign/gsap-pin-problem.git . I'm using Next.js and TypeScript. I have made three sections, one at the top, one in the center, and one at the bottom. I am trying to pin the center section and it's pinning too. You will see some navigation in the header, as soon as I switch from the home page to the About page, I get to see an error which is [NotFoundError: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.]. When I remove the pin from the scrollTrigger timeline then it runs perfectly. The section in which the problem is occurring will be found in the code on the home page inside the templates folder. I was trying to show the example on codesandbox but it could not be setup. That's why I have given the link of GitHub. Forgive me for this.?Also i provide code file gsap-pin-problem.zip Link to comment Share on other sites More sharing options...
GSAP Helper Posted April 11, 2023 Share Posted April 11, 2023 It's pretty tough to troubleshoot without a minimal demo - the issue could be caused by CSS, markup, a third party library, your browser, an external script that's totally unrelated to GSAP, etc. Would you please provide a very simple CodePen or CodeSandbox that demonstrates the issue? Please don't include your whole project. Just some colored <div> elements and the GSAP code is best (avoid frameworks if possible). See if you can recreate the issue with as few dependancies as possible. If not, incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, then at least we have a reduced test case which greatly increases your chances of getting a relevant answer. Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo: See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen If you're using something like React/Next/Vue/Nuxt or some other framework, you may find StackBlitz easier to use. We have a series of collections with different templates for you to get started on these different frameworks: React/Next/Vue/Nuxt. Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. Link to comment Share on other sites More sharing options...
akrdesign Posted April 11, 2023 Author Share Posted April 11, 2023 @GSAP Helper Thanks for replying!! You will see the problem with this link when you switch from home page to about page using navigation https://stackblitz.com/edit/nextjs-1vgseg?file=pages%2F_app.tsx,templates%2FHomePage%2Findex.ts,pages%2Findex.tsx,templates%2FHomePage%2FHomePage.tsx,pages%2Fabout-us.tsx,styles%2Fglobals.css Link to comment Share on other sites More sharing options...
Solution Rodrigo Posted April 11, 2023 Solution Share Posted April 11, 2023 Hi, This seems related to the useEffect hook in your home page template. Using the isomorphic layout effect helper seems to solve it: import { useIsomorphicLayoutEffect } from '../../helpers/isomorphicEffect'; const HomePage = () => { const triggerRef = useRef(null!); useIsomorphicLayoutEffect(() => { let ctx = gsap.context(() => { const tl = gsap.timeline({ paused: true, scrollTrigger: { trigger: triggerRef.current, start: 'top top', end: '1040 top', scrub: true, pin: true, }, }); }, triggerRef); return () => ctx.revert(); }); return (); }; Also there is no need to register GSAP plugins on every page, just do it once on your app's main entry page. In this case you're registering ScrollTrigger in the hook you created to setup Lenis, which is executed in your _app.tsx file should be enough to avoid tree shaking. Here is a fork of your example: https://stackblitz.com/edit/nextjs-bjn37v?file=pages%2F_app.tsx Hopefully this helps. Happy Tweening! 2 Link to comment Share on other sites More sharing options...
akrdesign Posted April 11, 2023 Author Share Posted April 11, 2023 @Rodrigo Thank you so much sir? 1 Link to comment Share on other sites More sharing options...
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