Programming/React

[ React ] gsap ScrollTrigger ์‚ฌ์šฉ์‹œ execute 'removeChild' on 'Node': The node to be removed is not a child of this node ์˜ค๋ฅ˜

seulye 2023. 11. 9. 14:43

 

- ์ƒํ™ฉ

https://webstoryboy.co.kr/1934

 

11. ํฌํŠธํด๋ฆฌ์˜ค ์‚ฌ์ดํŠธ ๋งŒ๋“ค๊ธฐ : React-Site : ์…‹ํŒ…ํ•˜๊ธฐ

Tutorial/portfolio ํฌํŠธํด๋ฆฌ์˜ค ์‚ฌ์ดํŠธ ๋งŒ๋“ค๊ธฐ - React by @webs 2023. 08. 01. 01 ํฌํŠธํด๋ฆฌ์˜ค ์‚ฌ์ดํŠธ ๋งŒ๋“ค๊ธฐ : ์…‹ํŒ…ํ•˜๊ธฐ ๋‚œ์ด๋„ ์ค‘๊ฐ„ ์†Œ์Šค ๋‹ค์šด๋กœ๋“œ ์™„์„ฑ ํ™”๋ฉด ์™„์„ฑ ์ฝ”๋“œ ์˜์ƒ ๋ณด๊ธฐ ์†Œ๊ฐœ ์•ˆ๋…•ํ•˜์„ธ์š”! ์›น์Šคํ† ๋ฆฌ

webstoryboy.co.kr

์ด ๋ธ”๋กœ๊ทธ๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ์‚ฌ์ดํŠธ๋ฅผ ๋งŒ๋“ค์—ˆ๋‹ค. ์ด ์‚ฌ์ดํŠธ์—์„œ๋Š” ํŽ˜์ด์ง€๊ฐ€ ํ•˜๋‚˜์˜€๋Š”๋ฐ, ๋‚˜๋Š” ๋ฉ”๋‰ด๋ณ„๋กœ ํŽ˜์ด์ง€๋ฅผ ๋งŒ๋“ค๊ณ  ์‹ถ์–ด์„œ ๋ผ์šฐํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‚˜๋ˆ„์—ˆ๋‹ค. 

 

 

๊ทธ๋Ÿฐ๋ฐ, ๊ณ„์† ๋ฉ”๋‰ด๋ฅผ ์˜ฎ๊ฒจ๊ฐˆ ๋•Œ 

 execute 'removeChild' on 'Node': The node to be removed is not a child of this node

์ด ์˜ค๋ฅ˜๊ฐ€ ๋–ด๋‹ค.. ๐Ÿ˜ข

 

์ € ์˜ค๋ฅ˜๋กœ ๊ฒ€์ƒ‰ํ•ด๋ณด์•˜์„ ๋•Œ, <> </> ํƒœ๊ทธ๋ฅผ <div></div>๋กœ ๋ฐ”๊พธ๋ผ๋Š” ํ•ด๊ฒฐ์ฑ…๋„ ์žˆ์—ˆ์–ด์„œ,

App.tsx ๋ฅผ ๊ทธ๋ ‡๊ฒŒ ๋ฐ”๊พธ์—ˆ์Œ์—๋„ ๊ณ„์† ์˜ค๋ฅ˜๊ฐ€ ๋‚ฌ๋‹ค. 

 

ํ˜น์‹œ๋‚˜ ํ•ด์„œ ํ™•์ธํ•ด๋ณด๋‹ˆ, ScrollTrigger์„ ์ ์šฉํ•œ ๋ฉ”๋‰ด๋ฅผ ๋‚˜๊ฐ€์„œ ๋‹ค๋ฅธ ๋ฉ”๋‰ด๋กœ ์ด๋™ํ•  ๋•Œ ๋ฐœ์ƒํ•˜๋Š” ๊ฒƒ์„ ๋ณด์•˜๋‹ค!

๊ทธ๋ž˜์„œ ScrollTrigger์ด๋ž‘ Router ํ‚ค์›Œ๋“œ๋กœ ์—ด์‹ฌํžˆ ๊ฒ€์ƒ‰์„ ํ•ด๋ณธ ๊ฒฐ๊ณผ!! 

 

https://gsap.com/community/forums/topic/25901-issue-with-scrolltrigger-pinning-in-gatsbyreact-site/#comment-139180

 

Issue with ScrollTrigger pinning in Gatsby/React site

Hello, I am experiencing this error: 'NotFoundErrror: Failed to Execute 'removeChild' on 'Node': The node to be removed is not a child of this node.' Specifically when using the 'pinning' attribute. Here is the code snippet being used in my component causi

gsap.com

 

gsap ํ™ˆํŽ˜์ด์ง€์—์„œ ์ด ๊ธ€์„ ๋ณด๊ฒŒ ๋˜์—ˆ๊ณ ... ๋‚˜์™€ ๊ฑฐ์˜ ์œ ์‚ฌํ•œ ์ฝ”๋“œ์ด์‹  ๋ถ„์˜ ๋Œ“๊ธ€์„ ๋ดค๋‹ค. 

์˜ค๋ฅ˜ ์›์ธ์€ ScrollTrigger๊ฐ€ ์ œ๋Œ€๋„ ๋ฐ˜ํ™˜๋˜์ง€ ์•Š์•„์„œ.. ๋กœ ๋ณด์˜€๋Š”๋ฐ, ๋ถ„๋ช… kill์ด ์žˆ์—ˆ๋Š”๋ށ ใ… _ใ…  

์•”ํŠผ 1์ฐจ์ ์œผ๋กœ ๋ฐ”๊ฟ”๋ณด์•˜๋‹ค. 

 

// ์›๋ž˜ ์ฝ”๋“œ
useEffect(() => {
    gsap.registerPlugin(ScrollTrigger);

    const horizontal = horizontalRef.current;
    const sections = sectionsRef.current;

    const scrollTween = gsap.to(sections, {
      xPercent: -120 * (sections.length - 1),
      ease: "none",
      scrollTrigger: {
        trigger: horizontal,
        start: "top 56px",
        end: () => "+=" + horizontal.offsetWidth,
        pin: true,
        scrub: 1,
        invalidateOnRefresh: true,
        anticipatePin: 1,
      },
    });

    return () => {
      scrollTween.kill();
    };
  }, []);

 

 

// ๋ฐ”๊พผ ์ฝ”๋“œ
let ns: any;
    if (sections) {
      ns = Math.random().toString(36).substring(7);
      gsap.to(sections, {
        xPercent: -120 * (sections.length - 1),
        ease: "none",
        scrollTrigger: {
          trigger: horizontal,
          start: "top 56px",
          end: () => "+=" + horizontal.offsetWidth,
          pin: true,
          scrub: 1,
          invalidateOnRefresh: true,
          anticipatePin: 1,
        },
      });
    } else {
      return;
    }

    return () => {
      const sectionTrigger = ScrollTrigger.getById(`${ns}-title`);
      if (sectionTrigger) {
        sectionTrigger.kill();
      }
    };

 

ํ•˜์ง€๋งŒ... ์ด๊ฒƒ๋„ ๋˜์ง€ ์•Š์•˜๋‹ค...

 

 

๊ทธ๋Ÿฌ๋‹ค๊ฐ€... ScrollTrigger์ด ์žˆ๋Š” ์†Œ์Šค์—์„œ <div>๋กœ ๊ฐ์‹ธ๋ณด๋ผ๋Š” ๋Œ“๊ธ€์„ ๋ณด๊ณ  ํ•ด๋ดค๋”๋‹ˆ...

/* ์ˆ˜์ • ์ „ */
<section id="popular" ref={horizontalRef}>
	์ƒ๋žต...
</section>

/* ์ˆ˜์ • ํ›„ */
<div>
<section id="popular" ref={horizontalRef}>
	์ƒ๋žต...
</section>
</div>

 

๋๋‹ค!!!!!!!!!!!!!!!