Skip to content

Commit cec4d6c

Browse files
committed
improve condition, should work now
1 parent f2b9bb2 commit cec4d6c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/components/react/ImageBlurPreloader.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ const ImageBlurPreloader: FC<Props> = ({
3838
prevMainAttributes.srcSet === mainAttributes.srcSet
3939
);
4040

41-
const _isDelayedBlur = useDelayed(isMainImageChanged, BLUR_IMAGE_DELAY);
41+
// use isLoadingBlur to measure delay
42+
const isDelayedBlur = useDelayed(isLoadingBlur, BLUR_IMAGE_DELAY);
4243

4344
// reset isLoading on main image change
4445
useEffect(() => {
@@ -92,10 +93,13 @@ const ImageBlurPreloader: FC<Props> = ({
9293
className={cn(
9394
'object-cover absolute top-0 left-0 size-full',
9495
// important:
95-
// _!isLoadingBlur - don't hide main image until next blur image is loaded
96-
// isMainImageChanged - don't show main image while it's transitioning - solves flickering
97-
// isDelayedBlur - fixed blur delay
98-
!isLoadingBlur && (isLoadingMain || isMainImageChanged) ? 'opacity-0' : 'opacity-100',
96+
// must test remote, real world
97+
// (!isLoadingBlur || isMainImageChanged) - must go together, blur is not ready, keep old main image
98+
(!isLoadingBlur || isMainImageChanged) &&
99+
// (isLoadingMain || isDelayedBlur) - go together, show blur image
100+
(isLoadingMain || isDelayedBlur)
101+
? 'opacity-0'
102+
: 'opacity-100',
99103
className
100104
)}
101105
/>

0 commit comments

Comments
 (0)