Skip to content
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

item loop in _lazyLoadItems caches item length can cause exception #58

Closed
zspitzer opened this issue Aug 4, 2016 · 4 comments
Closed
Assignees
Labels

Comments

@zspitzer
Copy link
Contributor

zspitzer commented Aug 4, 2016

Because the length of the item array is being cached, it's possible for an exception to be triggered in _isInLoadableArea, "element is undefined" if a loader with a callback is used and the size of the item array is reduced by another round of _lazyLoadItems being executed which removes one or more items from the item array, whilst waiting for the loader to return.

https://github.com/eisbehr-/jquery.lazy/blob/master/jquery.lazy.js#L305

@dkern
Copy link
Owner

dkern commented Aug 4, 2016

Hi @zspitzer,

I'm actually not sure, how this could happen. Inside the for loop the object is given by items[i] to the inner function. This should mean, even if the object would be removed from the items array, it is still available to the inner loop. So _isInLoadableArea should still work. I have to test this somehow ...

Do you have an example where this happens to you? Can you create a fiddle?

And if you have such problem, do you already got a workaround?

Thank you so far!

@zspitzer
Copy link
Contributor Author

zspitzer commented Aug 4, 2016

I'm on holidays and thus dad duty at the moment , so i haven't had time to knock out a fiddle. The customer loader was async as it was doing some network calls , I think _lazyLoadItems might of been triggered again whilst waiting for the server to respond.

I encountered this with some content in a dashboard which involves nested instances of lazy loaders, I was previously having issues with the destroy and namespaces which you fixed recently and thought I'd try it out and encountered the exception.

but the fix is dead simple
for( var i = 0, l = items.length; i < l; i++ )
becomes
for( var i = 0; i < items.length; i++ )

@dkern
Copy link
Owner

dkern commented Aug 5, 2016

Ahh well, yes, of course. I was thinking that would work. But on JS it's working this way. 😉
I will make this little change within the next update ...

dkern added a commit that referenced this issue Aug 9, 2016
- fixed issue #58
- created gulp build script for all files
- fixed some bugs and warnings from jshint
- fixed some readme anchors
- changed some file headers to be consistent
@dkern
Copy link
Owner

dkern commented Aug 9, 2016

fixed as of 1.7.3

@dkern dkern closed this as completed Aug 9, 2016
@dkern dkern added the bug label Aug 22, 2016
@dkern dkern self-assigned this Aug 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants