Skip to content

Commit 0fd2fee

Browse files
authored
Merge pull request #25 from imagekit-developer/feature/lazy-load-tests
Code Coverage for lazyload and LQIP features
2 parents 77845df + b4f8a8c commit 0fd2fee

File tree

5 files changed

+365
-32
lines changed

5 files changed

+365
-32
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "imagekitio-react",
3-
"version": "1.0.8",
3+
"version": "1.0.9",
44
"description": "React SDK for ImageKit.io which implements client-side upload and URL generation for use inside a react application.",
55
"scripts": {
66
"build": "rm -rf dist*;rollup -c",
@@ -25,6 +25,9 @@
2525
"verbose": true,
2626
"setupFilesAfterEnv": [
2727
"<rootDir>/src/test/setupTests.js"
28+
],
29+
"coveragePathIgnorePatterns": [
30+
"<rootDir>/src/test/mocks"
2831
]
2932
},
3033
"author": "ImageKit",

src/components/IKImage/index.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ class IKImage extends ImageKitComponent {
117117
triggerOriginalImageLoad() {
118118
var img = new Image();
119119
img.onload = () => {
120-
this.setState({ originalSrcLoaded: true });
121-
this.updateImageUrl();
120+
this.setState({ originalSrcLoaded: true }, () => {
121+
this.updateImageUrl();
122+
});
122123
}
123124
img.src = this.state.originalSrc;
124125
}
@@ -136,10 +137,11 @@ class IKImage extends ImageKitComponent {
136137
const imageObserver = new IntersectionObserver(entries => {
137138
const el = entries[0];
138139
if (el && el.isIntersecting) {
139-
this.setState({ intersected: true });
140-
if (lqip && lqip.active) this.triggerOriginalImageLoad();
141-
imageObserver.disconnect();
142-
this.updateImageUrl();
140+
this.setState({ intersected: true }, () => {
141+
if (lqip && lqip.active) this.triggerOriginalImageLoad();
142+
imageObserver.disconnect();
143+
this.updateImageUrl();
144+
});
143145
}
144146
}, {
145147
rootMargin: `${rootMargin} 0px ${rootMargin} 0px`
@@ -150,9 +152,10 @@ class IKImage extends ImageKitComponent {
150152
})
151153
} else {
152154
// Load original image right away
153-
this.setState({ intersected: true });
154-
if (lqip && lqip.active) this.triggerOriginalImageLoad();
155-
this.updateImageUrl();
155+
this.setState({ intersected: true }, () => {
156+
if (lqip && lqip.active) this.triggerOriginalImageLoad();
157+
this.updateImageUrl();
158+
});
156159
}
157160
}
158161

0 commit comments

Comments
 (0)