@@ -196,6 +196,7 @@ export default class Carousel extends Component {
196
196
const startIndex = currentSlide - Math . floor ( imagesToPrefetch / 2 ) ;
197
197
const endIndex = startIndex + imagesToPrefetch ;
198
198
const pendingImages = [ ] ;
199
+ const currentImage = slides [ currentSlide ] . props . src ;
199
200
200
201
for ( let index = startIndex ; index < endIndex ; index ++ ) {
201
202
const slide = nth ( slides , index % slides . length ) ;
@@ -214,6 +215,10 @@ export default class Carousel extends Component {
214
215
loadedImages : merge ( { } , this . state . loadedImages , {
215
216
[ image ] : { width : img . width || 'auto' , height : img . height || 'auto' }
216
217
} )
218
+ } , ( ) => {
219
+ if ( image === currentImage ) {
220
+ this . handleInitialLoad ( ) ;
221
+ }
217
222
} ) ;
218
223
}
219
224
} ;
@@ -462,7 +467,7 @@ export default class Carousel extends Component {
462
467
renderSlides ( ) {
463
468
const { children, infinite, cellPadding, slideWidth, slideHeight, transition, transitionDuration,
464
469
style, easing, lazyLoad } = this . props ;
465
- const { slideDimensions, currentSlide, loading , loadedImages } = this . state ;
470
+ const { slideDimensions, currentSlide, loadedImages } = this . state ;
466
471
this . _allImagesLoaded = true ;
467
472
let childrenToRender = Children . map ( children , ( child , index ) => {
468
473
const key = `slide-${ index } ` ;
@@ -505,12 +510,9 @@ export default class Carousel extends Component {
505
510
506
511
// Only render the actual slide content if lazy loading is disabled, the image is already loaded, or we
507
512
// 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
510
515
if ( imgSrc && loadedImages [ imgSrc ] ) {
511
- if ( index === currentSlide && loading ) {
512
- child = cloneElement ( child , { onLoad : this . handleInitialLoad } ) ;
513
- }
514
516
const { width, height } = loadedImages [ imgSrc ] ;
515
517
slideStyle . height = slideStyle . height || height ;
516
518
slideStyle . width = slideStyle . width || width ;
@@ -631,7 +633,6 @@ export default class Carousel extends Component {
631
633
*/
632
634
calcLeftOffset ( ) {
633
635
const { loading, direction } = this . state ;
634
-
635
636
if ( loading || ! this . _track || ! this . _viewport ) {
636
637
clearTimeout ( this . _retryTimer ) ;
637
638
if ( this . _isMounted ) {
0 commit comments