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

Guard against missing currentGallery element #124

Merged
merged 2 commits into from
Oct 25, 2016
Merged

Conversation

rgalanakis
Copy link
Contributor

When an image is loaded,
it can preload the next/previous image with a callback.
It's possible that between when the decision to preload is made
and the loadImage call for preloading happens,
the current gallery has been modified and the index to preload
is missing, causing the preload callback to error.


I can't say exactly why this is occurring, but each day we get at least one error on this line, with a stacktrace coming from preloadNext or preloadPrev, and this change appears to fix it. I decided to not invoke the callback in the case the chosen item is missing from the current gallery, since that's what you do on line 474 (if imagesElements[index] is undefined). But since I can't create a reliable repro, I could use your judgement here.

When an image is loaded,
it can preload the next/previous image with a callback.
It's possible that between when the decision to preload is made
and the `loadImage` call for preloading happens,
the current gallery has been modified and the index to preload
is missing, causing the preload callback to error.
@feimosi
Copy link
Owner

feimosi commented Sep 7, 2016

Thanks for reporting that. I'm currently unavailable, so I'm gonna need more time to investigate it.

// but by the time the load happens, the element is gone.
if (typeof galleryItem === 'undefined') {
return;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rename the variable to galleryImage and move the whole to the top to become:

var imageContainer = imagesElements[index];
var galleryImage = currentGallery[index];

// Return if the index exceeds prepared images in the overlay
// or if the current gallery has been changed / closed
if (imageContainer === undefined || galleryImage === undefined) {
    return;
}

I've also updated the comment. Let me know what do you think.

@feimosi
Copy link
Owner

feimosi commented Oct 23, 2016

Your reasoning makes perfect sense and that may be the case. See my review and thanks for the contribution!

@rgalanakis
Copy link
Contributor Author

Ok, updated.

@feimosi
Copy link
Owner

feimosi commented Oct 25, 2016

Perfect, thanks!

@feimosi feimosi merged commit 5278cb3 into feimosi:dev Oct 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants