-
-
Notifications
You must be signed in to change notification settings - Fork 676
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
callback_exit() is not being called on non-image elements #468
Comments
Hey @starfishpatkhoo, thanks for you thorough debugging. If we applied the fix you are suggesting, you would get a lot of I think the fix is to apply a status export const onExit = (element, entry, settings, instance) => {
if (hasEmptyStatus(element)) return; //Ignore the first pass, at landing
cancelLoading(element, entry, settings, instance);
safeCallback(settings.callback_exit, element, entry, instance);
}; Let me try this way. |
Hello @starfishpatkhoo , Would you be able to double check? |
@starfishpatkhoo please let me know if this worked for you. |
Sorry @verlok working on some other high priority issue a.t.m. .. I will be able to get back to this and the other one on tuesday.. apologies :) |
Works great, thanks @verlok! Yes, that's a good way to go about it to add a "entered" status, safer than checking the type of element. :) |
Hey @starfishpatkhoo , Thank you again for reporting the bug. |
I have been using IntersectionObserver for other purposes. Then I decided to add LazyLoad to lazyload the images. Since LazyLoad also uses IO, I thought I might as well switch all my own IO event handlers/hooks to use LazyLoad. Everything works fine, except for callback_exit(). As it turns out, the IO detection on leaving works fine, it is just that it happened that I was using this on some other elements that have nothing to do with images. And so onExit() would ignore the event.
To reproduce, just create a div and have LazyLoad watch it with callback_enter() and callback_exit().
You will see it enters, but never exits :)
The fix is below. But I'm pretty sure there is a more "proper" way to do this and I hesitate to submit a PR without knowing the true effect of such a change.
I understand that this was never really LazyLoad's intention, I just thought I would save some code and avoid duplication in my own project.
Version: 16.1
Browser: Chrome (but any IO enabled browser really)
EDIT: Issue also exists in Version 17.0
The text was updated successfully, but these errors were encountered: