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

Bug - Race condition on slow networks in Image.onload handler set in changeImage #629

Open
olwimo opened this issue Apr 19, 2018 · 0 comments

Comments

@olwimo
Copy link

olwimo commented Apr 19, 2018

Lightbox.prototype.start resets this.album every time a new album is opened. It always ends by calling Lightbox.prototype.changeImage, which sets an Image.onload handler that accesses this.album[imageNumber] after the image is loaded (async). If the network is slow, it is possible for the user to close the album and open a new one before the image is loaded. If the new album opened by the user has less images in it than the index of the first image clicked, this.album[imageNumber] will be undefined, and the attempts to access its properties will result in an error. If the index is within the length of the new album it won't crash, it'll just show the "old" image in the new lightbox (which I guess is not expected/wrong behavior).

I've created an example on jsfiddle, https://jsfiddle.net/olwimo/h633q2re/
I've created a PR with a proposed fix, #628

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants