Skip to content

Commit 0d52a4d

Browse files
Merge pull request #33 from godaddy/fix-timing-bug
Fix timing issue with current image loading
2 parents c6dc5e5 + 3f5e4b8 commit 0d52a4d

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.5.1 - Sept 2019
2+
3+
***(Bug Fix)*** Fix issue that can cause the slideshow to never render
4+
15
# 1.5.0 - Sept 2019
26

37
* ***(FEATURE)*** Add support for `maxRenderedSlides` prop

src/index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ export default class Carousel extends Component {
196196
const startIndex = currentSlide - Math.floor(imagesToPrefetch / 2);
197197
const endIndex = startIndex + imagesToPrefetch;
198198
const pendingImages = [];
199+
const currentImage = slides[currentSlide].props.src;
199200

200201
for (let index = startIndex; index < endIndex; index++) {
201202
const slide = nth(slides, index % slides.length);
@@ -214,6 +215,10 @@ export default class Carousel extends Component {
214215
loadedImages: merge({}, this.state.loadedImages, {
215216
[image]: { width: img.width || 'auto', height: img.height || 'auto' }
216217
})
218+
}, () => {
219+
if (image === currentImage) {
220+
this.handleInitialLoad();
221+
}
217222
});
218223
}
219224
};
@@ -462,7 +467,7 @@ export default class Carousel extends Component {
462467
renderSlides() {
463468
const { children, infinite, cellPadding, slideWidth, slideHeight, transition, transitionDuration,
464469
style, easing, lazyLoad } = this.props;
465-
const { slideDimensions, currentSlide, loading, loadedImages } = this.state;
470+
const { slideDimensions, currentSlide, loadedImages } = this.state;
466471
this._allImagesLoaded = true;
467472
let childrenToRender = Children.map(children, (child, index) => {
468473
const key = `slide-${index}`;
@@ -505,12 +510,9 @@ export default class Carousel extends Component {
505510

506511
// Only render the actual slide content if lazy loading is disabled, the image is already loaded, or we
507512
// are within the configured proximity to the selected slide index.
508-
if (!lazyLoad || (imgSrc && loadedImages[imgSrc]) || slidesToRender.indexOf(index) > -1) {
509-
// If the slide contains an image, set explicit width/height and add load listener
513+
if (!lazyLoad || (imgSrc ? !!loadedImages[imgSrc] : slidesToRender.indexOf(index) > -1)) {
514+
// If the slide contains an image, set explicit width/height
510515
if (imgSrc && loadedImages[imgSrc]) {
511-
if (index === currentSlide && loading) {
512-
child = cloneElement(child, { onLoad: this.handleInitialLoad });
513-
}
514516
const { width, height } = loadedImages[imgSrc];
515517
slideStyle.height = slideStyle.height || height;
516518
slideStyle.width = slideStyle.width || width;
@@ -631,7 +633,6 @@ export default class Carousel extends Component {
631633
*/
632634
calcLeftOffset() {
633635
const { loading, direction } = this.state;
634-
635636
if (loading || !this._track || !this._viewport) {
636637
clearTimeout(this._retryTimer);
637638
if (this._isMounted) {

0 commit comments

Comments
 (0)