@@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from 'react';
2
2
import Image from 'next/image' ;
3
3
import { getImgSRC , processReactNode , generateAlt } from 'cloudimage-responsive-utils' ;
4
4
5
- import { computeImageStyles , getWrapperClassname , computeImageSize } from './utils/compute' ;
5
+ import { computeImageStyles , getWrapperClassName , computeImageSize } from './utils/compute' ;
6
6
import { parseParams , parseImageSrc } from './utils/parse' ;
7
7
import { WRAPPER_STYLES } from './styles.constants' ;
8
8
@@ -16,7 +16,7 @@ function Img(props) {
16
16
customDomain, domain, token, apiVersion,
17
17
doNotReplaceURL : imagesDoNotReplaceURL , baseURL, params : imagesParams ,
18
18
quality : imagesQuality , layout : imagesLayout , objectFit : imagesObjectFit ,
19
- lowPreviewQuality : imagesLowPreviewQuality , transitionDuration : imagesTransitonDuration ,
19
+ lowPreviewQuality : imagesLowPreviewQuality , transitionDuration : imagesTransitionDuration ,
20
20
ssr : imagesSsr , objectPosition : imagesObjectPosition , lazyload : imagesLazyload ,
21
21
} = config ;
22
22
@@ -25,7 +25,7 @@ function Img(props) {
25
25
layout = imagesLayout , objectFit = imagesObjectFit ,
26
26
lowPreviewQuality = imagesLowPreviewQuality , onImgLoad,
27
27
width, height, doNotReplaceURL = imagesDoNotReplaceURL ,
28
- className, alt, transitionDuration = imagesTransitonDuration ,
28
+ className, alt, transitionDuration = imagesTransitionDuration ,
29
29
style = { } , ssr = imagesSsr , children, background, objectPosition = imagesObjectPosition ,
30
30
lazyload = imagesLazyload ,
31
31
} = props ;
@@ -35,6 +35,7 @@ function Img(props) {
35
35
const [ cloudImgSrcSet , setCloudImgSrcSet ] = useState ( '' ) ;
36
36
37
37
const wrapperRef = useRef ( ) ;
38
+ const previousSrc = useRef ( ) ;
38
39
39
40
let previousWidth ;
40
41
const cName = customDomain ? domain : `${ token } .${ domain } ` ;
@@ -59,6 +60,7 @@ function Img(props) {
59
60
60
61
const onImageLoad = ( event ) => {
61
62
setLoaded ( true ) ;
63
+ previousSrc . current = src ;
62
64
63
65
if ( typeof onImgLoad === 'function' ) {
64
66
onImgLoad ( event ) ;
@@ -104,27 +106,30 @@ function Img(props) {
104
106
}
105
107
} ;
106
108
107
- const wrapperClassname = background
108
- ? classes . ciBackgroundWrapper : classes [ getWrapperClassname ( layout ) ] ;
109
+ const wrapperClassName = background
110
+ ? classes . ciBackgroundWrapper : classes [ getWrapperClassName ( layout ) ] ;
109
111
110
112
useEffect ( ( ) => {
111
113
if ( ssr ) return ;
112
114
113
115
previousWidth = window . innerWidth ;
116
+ setLoaded ( false ) ;
114
117
115
118
processImage ( ) ;
119
+
116
120
window . addEventListener ( 'resize' , handleWindowResize ) ;
117
121
118
122
return ( ) => {
119
123
window . removeEventListener ( 'resize' , handleWindowResize ) ;
120
124
} ;
121
- } , [ ] ) ;
125
+ } , [ src ] ) ;
126
+
122
127
123
128
return (
124
129
< div
125
130
ref = { wrapperRef }
126
131
style = { { ...WRAPPER_STYLES , ...style } }
127
- className = { `${ wrapperClassname } ${ className ? ` ${ className } ` : '' } ` }
132
+ className = { `${ wrapperClassName } ${ className ? ` ${ className } ` : '' } ` }
128
133
>
129
134
< Image
130
135
src = { src }
@@ -157,7 +162,7 @@ function Img(props) {
157
162
srcSet = { cloudImgSrcSet }
158
163
alt = { _alt }
159
164
onLoad = { onImageLoad }
160
- style = { computeImageStyles ( loaded , transitionDuration , objectFit , objectPosition ) }
165
+ style = { computeImageStyles ( loaded , transitionDuration , objectFit , objectPosition , ! previousSrc . current ) }
161
166
className = { classes . ciSsgImage }
162
167
loading = { lazyload ? 'lazy' : 'eager' }
163
168
/>
0 commit comments