Jump to content
Search Community

'Maximum call stack size exceeded' when using responsive display I get RangeError: Maximum call stack size exceeded' error

Semih test
Moderator Tag

Recommended Posts

Hi,

 

I'm not seeing that error in your demo and I created a new React app in my local machine with your exact same code and also can't see the error.

 

There must be something else in your config that is causing this and I just can't see it 🤷‍♂️

 

Happy Tweeing!

Link to comment
Share on other sites

2 hours ago, Rodrigo said:

Hi,

 

I'm not seeing that error in your demo and I created a new React app in my local machine with your exact same code and also can't see the error.

 

There must be something else in your config that is causing this and I just can't see it 🤷‍♂️

 

Happy Tweeing!

Sorry, I posted the wrong gsap code. I changed the code. I encounter this problem when I add the responsive feature to the Gsap code. First set it to 1100px and then reduce the screen size. you can see the error...

 

https://stackblitz.com/edit/react-clkzur?file=src%2FApp.js,src%2Fstyle.css

Link to comment
Share on other sites

I noticed two problems: 

  1. You're returning a revert function from the matchMedia() entry that's reverting the instance itself. So you're creating an infinite loop. When a matchMedia() doesn't match anymore, it'll revert that instance and part of that process involves calling any revert functions that were returned inside the matchMedia() functions. So it starts reverting the instance, calls your returned function which in return calls revert() on the entire instance again which goes through that process, over and over. You put your mm.revert() in the wrong spot - it belongs OUTSIDE that matchMedia() function. 
  2. You forgot to define an empty dependency Array on your useLayoutEffect(). 
useLayoutEffect(() => {
    let mm = gsap.matchMedia();
    gsap.registerPlugin(ScrollTrigger);
    mm.add('(min-width: 1100px)', () => {
      const textElements = gsap.utils.toArray('.deneme');

      textElements.forEach((text) => {
        gsap.to(text, {
          backgroundSize: '60%',
          ease: 'none',
          scrollTrigger: {
            trigger: text,
            start: 'top 50%',
            end: 'bottom',
            // markers:true,
            scrub: true,
          },
        });
      });
    });
    return () => mm.revert(); // <-- this goes outside the matchMedia.add() function
  }, []); // <-- important!

I hope that helps. 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...