Skip to content

Commit 76eedf1

Browse files
WIP fixing lazy image loading to remove blur halo and enforce decoding before animating image in
1 parent d443ad7 commit 76eedf1

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

packages/react-notion-x/src/components/lazy-image.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,18 @@ export const LazyImage: React.FC<{
5858
)}
5959
style={wrapperStyle}
6060
>
61-
<img
62-
src={previewImage.dataURIBase64}
63-
alt={alt}
64-
ref={ref}
65-
className='lazy-image-preview'
66-
style={style}
67-
width={previewImage.originalWidth}
68-
height={previewImage.originalHeight}
69-
decoding='async'
70-
/>
61+
<div className='lazy-image-preview-wrapper'>
62+
<img
63+
src={previewImage.dataURIBase64}
64+
alt={alt}
65+
ref={ref}
66+
className='lazy-image-preview'
67+
style={style}
68+
width={previewImage.originalWidth}
69+
height={previewImage.originalHeight}
70+
decoding='async'
71+
/>
72+
</div>
7173

7274
<img
7375
src={src}
@@ -81,7 +83,6 @@ export const LazyImage: React.FC<{
8183
width={previewImage.originalWidth}
8284
height={previewImage.originalHeight}
8385
decoding='async'
84-
loading='lazy'
8586
/>
8687
</div>
8788
)

packages/react-notion-x/src/styles.css

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,6 @@ svg.notion-page-icon {
19031903

19041904
.lazy-image-wrapper {
19051905
position: relative;
1906-
overflow: hidden;
19071906
}
19081907

19091908
.lazy-image-wrapper img {
@@ -1920,38 +1919,55 @@ svg.notion-page-icon {
19201919
transform: scale(1.1);
19211920

19221921
opacity: 1;
1923-
transition: opacity 400ms ease-in !important;
1924-
transition-delay: 100ms;
1925-
will-change: opacity;
1922+
transition: visibility 0ms ease 400ms !important;
1923+
/* will-change: visibility; */
19261924
}
19271925

19281926
.lazy-image-wrapper img.lazy-image-real {
19291927
position: relative;
19301928
}
19311929

19321930
.lazy-image-real {
1931+
/* background: var(--bg-color); */
19331932
opacity: 0;
1934-
transition: opacity 400ms ease-out !important;
1935-
will-change: opacity;
1933+
transition: opacity 400ms ease !important;
1934+
/* will-change: opacity; */
19361935
}
19371936

19381937
.lazy-image-real.medium-zoom-image {
19391938
transition: transform 0.3s cubic-bezier(0.2, 0, 0.2, 1),
19401939
opacity 400ms ease-out !important;
1941-
will-change: opacity, transform;
1940+
/* will-change: opacity, transform; */
19421941
}
19431942

19441943
.medium-zoom-image--opened {
19451944
object-fit: cover;
19461945
opacity: 1;
19471946
}
19481947

1948+
.lazy-image-preview-wrapper {
1949+
transform: translateZ(0);
1950+
/* will-change: opacity; */
1951+
position: absolute;
1952+
top: 0;
1953+
left: 0;
1954+
width: 100%;
1955+
height: 100%;
1956+
transition: opacity 100ms 400ms;
1957+
opacity: 1;
1958+
overflow: hidden;
1959+
}
1960+
19491961
/* NOTE: if we hide the preview image, there's a weird bug with react hydration where
19501962
the image will sometimes flicker to show the background during initial page load.
19511963
So I'm removing this `opacity: 0` for now, but it will cause issues if the real
19521964
image is transparent. */
1965+
.lazy-image-loaded .lazy-image-preview-wrapper {
1966+
/* opacity: 0; */
1967+
}
1968+
19531969
.lazy-image-loaded .lazy-image-preview {
1954-
opacity: 0;
1970+
/* visibility: hidden; */
19551971
}
19561972

19571973
.lazy-image-loaded .lazy-image-real {

0 commit comments

Comments
 (0)