w3c / IntersectionObserver

Intersection Observer
https://www.w3.org/TR/intersection-observer/
Other
3.62k stars 526 forks source link

Polyfill do not add IntersecionRatio in window.IntersectionObserverEntry.prototype instead adding in Child instance (This) #418

Closed vipul-nema closed 2 years ago

vipul-nema commented 4 years ago

This polyfill first checks support present in the browser or not. In that check this is one condition 'intersectionRatio' in window.IntersectionObserverEntry.prototype

but once polyfill loaded, it is not adding intersectionRatio method in that prototype object instead it adds in "this" child (object). that by if multiple times polyfill come by different scripts, it again defined whole things. that may be error-prone.

mater1996 commented 4 years ago

IntersectionObserverEntry.prototype.intersectionRatio = undefined IntersectionObserverEntry.prototype.isIntersecting = undefined

add this to intersection-observer.js

miketaylr commented 2 years ago

How common is it to load the polyfill multiple times on the same page?

miketaylr commented 2 years ago

Thinking about this some more, I recommend we close this as an unsupported use case - I worry if we want to support multiple polyfills in the same page, we need to consider different versions as well. It seems like the better solution is to ensure you're only loading it once, for UAs without a native implementation.