-
Notifications
You must be signed in to change notification settings - Fork 523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Polyfill: callback is called synchronously #225
Comments
I am getting an issue where both in IE and FireFox, when the polyfill is added, it quickly freezes up the page and the browser goes into "not responding". Would this synchronous callback create this behavior? |
I haven't been able to test extensively so I didn't experience a freeze up of the page in my case with several IO targets being observed. Whenever I am using the polyfill I make sure I am wrapping my calls with So to wrap your individual invocations, here's a snippet you can use for the time-being: import { requestIdleCallback } from 'request-idle-callback'; // optional polyfill
const hasNativeSupport = 'IntersectionObserver' in window && window.IntersectionObserver.prototype.toString().contains('[object IntersectionObserver');
const ensureAsync = (callback) => hasNativeSupport ? callback : (...args) => requestIdleCallback(() => { callback(...args); });
export default ensureAsync; And here's a couple of Profile snapshots taken with Firefox's devtools - bare in mind it's me scrolling in the same page up and down without a given order, so it's far from accurate to measure - I did however obtain the best result 2-3 times in a row with requestIdleCallback: Without RIC
With IRC
|
Given Firefox's native implementation, I'm going to optimistically close this issue. mlisook/plastic-image#19 (comment) is also positive to see. If someone is still experiencing an issue, please comment and we can re-open. |
The intersection observer's callback should be called asynchronously according to spec.
https://wicg.github.io/IntersectionObserver/#update-intersection-observations-algo step 2.12
https://wicg.github.io/IntersectionObserver/#queue-an-intersectionobserverentry step 3
https://wicg.github.io/IntersectionObserver/#queue-intersection-observer-task step 3
The
this._callback
invocation should be done in arequestIdleCallback
orsetTimeout
call.The text was updated successfully, but these errors were encountered: