Jump to content
Search Community

GSAP3 Undefined Target breaks process

themepunch test
Moderator Tag

Recommended Posts

Hi,

 

trying to tween any undefined element will break the rest of the code.  See Console log in my example:

 

gsap.fromTo(["#test",undefined], 0.5, { x: 100 }, { x: 0 }); 

 

will cause this: 

 

Uncaught TypeError: Cannot read property '_gsap' of undefined
    at W (gsap-latest-beta.min.js:10)
    at new Tween (gsap-latest-beta.min.js:10)
    at Object.fromTo (gsap-latest-beta.min.js:10)
    at pen.js:2

 

Of course we should try to avoid to run tweens etc. on undefined elements, however it always can happen that some selector etc. delivers undefined elements which is not tested by the sourrounding environment  before providing it to gsap.  Not to make a big thing about it, but in my opinion it would be great to make these checks inside Greensock to make it more stable ?

 

 

 

Quick solution would be from the User side to filter out null elements somehow like this:

 

gsap.fromTo(["#test",undefined].filter(function(el) { return el!=null}), 0.5, { x: 100 }, { x: 0 }); 

 

What do you think guys ?

 

Thanks,

 

Krisztian from ThemePunch  

See the Pen zYYbxBw by themepunch (@themepunch) on CodePen

Link to comment
Share on other sites

Hey themepunch and thanks for being a Business Green member!

 

37 minutes ago, themepunch said:

trying to tween any undefined element will break the rest of the code.

That's not exactly correct. If your target is only something that is undefined then GSAP will only throw a warning (GSAP target undefined not found.). You're getting an error because of your use of an array of targets of different types, one of which is undefined. So if you made two tweens for this instead of one with two targets then there'd be no error, just a warning.

 

Maybe @GreenSock can give us insight why it's an error and not a warning? I'd be in favor of using a warning in circumstances like this upon first thinking about it. 

Link to comment
Share on other sites

Thanks for the quick answer !

 

Yes, you are right, the definition is not correct, but as you also wrote, i think a warning would be more elegant in this case. 

The array filtering i show as "quick solution" above does the trick so far,  however it maybe not that performant as it could be handling this inside greensock.

 

Really appreciate your feedback so far ! 

 

And i forgot to say, I love the new version of GSAP ! It is simple the best ! Thank you for putting the amazing work into this fantastic engine ! 

 

Cheers,

 

Krisztian

 

  • Thanks 2
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...