Skip to content

Commit 59cf58a

Browse files
authored
add loading=lazy to RawImg for better perf (#4046)
1 parent a8ca134 commit 59cf58a

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

.changeset/angry-ladybugs-jam.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@builder.io/react": patch
3+
"@builder.io/sdk-angular": patch
4+
"@builder.io/sdk-react-nextjs": patch
5+
"@builder.io/sdk-qwik": patch
6+
"@builder.io/sdk-react": patch
7+
"@builder.io/sdk-solid": patch
8+
"@builder.io/sdk-svelte": patch
9+
"@builder.io/sdk-vue": patch
10+
---
11+
12+
Add loading=lazy to RawImg component for better perf

packages/react/src/blocks/raw/Img.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ class ImgComponent extends React.Component<ImgProps> {
3232
const attributes = this.props.attributes || {};
3333
const srcset = this.getSrcSet();
3434
return (
35-
<img {...this.props.attributes} src={this.props.image || attributes.src} srcSet={srcset} />
35+
<img
36+
loading="lazy"
37+
{...this.props.attributes}
38+
src={this.props.image || attributes.src}
39+
srcSet={srcset}
40+
/>
3641
);
3742
}
3843
}

packages/sdks/src/blocks/img/img.lite.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export default function ImgComponent(props: ImgProps) {
5151

5252
return (
5353
<img
54+
loading="lazy"
5455
style={{
5556
objectFit: props.backgroundSize || 'cover',
5657
objectPosition: props.backgroundPosition || 'center',

0 commit comments

Comments
 (0)