web-animations / web-animations-js

JavaScript implementation of the Web Animations API
http://web-animations.github.io
Apache License 2.0
3.77k stars 408 forks source link

Loading web-animations-next multiple times causes ._animation null errors #88

Open bedeoverend opened 8 years ago

bedeoverend commented 8 years ago

It seems when loading in web-animations-next more than once, various errors start to get thrown e.g. this._animation.cancel() where this._animation is null.

See this jsbin for repro - if you comment out one of the script tags, it'll work. It's not affected if you uncomment the web-animations.js tags, or if they're included twice.

My guess is it's something to do with overloading the animate function on the element proto - though I really can't be sure. For example, in web-animations-bonus-cancel-events.js or perhaps keyframe-effect-constructor.js or web-animations-bonus-object-form-keyframes.js (though last one unlikely given it appears to just be normalizing inputs).

Anyone got any idea what's going on here?

ewilligers commented 8 years ago

Perhaps web-animations-next should begin with something like if (window.GroupEffect) return;

bedeoverend commented 8 years ago

@ewilligers I like that idea - though preferrably each feature would check for the existence of itself, so web-animations-next might add 3 or so pieces of functionality, each should check for existence of it before continuing to polyfill. That way protected against itself loading multiple times, and incase its been loaded into a browser that natively implements perhaps some, but not all of the polyfilled features.

madeleineostoja commented 8 years ago

Overwriting any future native implementation is intentional though (https://github.com/web-animations/web-animations-js/issues/71).

So you'd need to check specifically for the existence of web-animation-next