@@ -50,7 +50,6 @@ class Image extends CloudinaryComponent {
5050 * @return attributes for the underlying <img> element.
5151 */
5252 getAttributes = ( additionalOptions = { } ) => {
53- const { isInView} = this . state ;
5453 const { placeholder} = additionalOptions ;
5554 const options = { ...this . getOptions ( ) , ...additionalOptions } ;
5655 const { nonCloudinaryProps} = extractCloudinaryProps ( options ) ;
@@ -69,7 +68,7 @@ class Image extends CloudinaryComponent {
6968 }
7069
7170 // Set data-src if lazy loading and not in view
72- if ( ! isInView && this . shouldLazyLoad ( options ) ) {
71+ if ( this . shouldLazyLoad ( ) ) {
7372 attributes [ 'data-src' ] = attributes . dataSrc || attributes . src ;
7473 delete attributes . src ;
7574 }
@@ -86,15 +85,16 @@ class Image extends CloudinaryComponent {
8685 * Update this image using cloudinary-core
8786 */
8887 update = ( ) => {
89- const { isInView} = this . state ;
90-
91- if ( this . isResponsive ( ) ) {
92- const removeListener = makeElementResponsive ( this . imgElement . current , this . getOptions ( ) ) ;
93- this . listenerRemovers . push ( removeListener ) ;
94- }
95-
96- if ( ! isInView && this . shouldLazyLoad ( this . getExtendedProps ( ) ) ) {
88+ // Handle lazy loading
89+ if ( this . shouldLazyLoad ( ) ) {
90+ // Will set this.state.isInView = true when in view
9791 Util . detectIntersection ( this . imgElement . current , this . onIntersect ) ;
92+ } else {
93+ // Handle responsive only if lazy loading wasn't requested or already handled
94+ if ( this . isResponsive ( ) ) {
95+ const removeListener = makeElementResponsive ( this . imgElement . current , this . getOptions ( ) ) ;
96+ this . listenerRemovers . push ( removeListener ) ;
97+ }
9898 }
9999 }
100100
@@ -115,8 +115,10 @@ class Image extends CloudinaryComponent {
115115 }
116116 } ;
117117
118- shouldLazyLoad = ( { loading} ) => {
119- return loading === "lazy" || loading === "auto" ;
118+ shouldLazyLoad = ( ) => {
119+ const { loading} = this . getExtendedProps ( ) ;
120+ const { isInView} = this . state ;
121+ return ! isInView && ( loading === "lazy" || loading === "auto" ) ;
120122 }
121123
122124 /**
0 commit comments