Skip to content

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

@olwimo

Description

@olwimo

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions