Skip to content

Commit d207666

Browse files
fix: consider img with loading attribute not static (#14237)
* fix: consider img with loading attribute not static * chore: add comment for `is_static_element` * chore: better comment Co-authored-by: Ben McCann <[email protected]> --------- Co-authored-by: Ben McCann <[email protected]>
1 parent 1e5a385 commit d207666

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

.changeset/nice-chicken-wonder.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: consider img with loading attribute not static

packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/fragment.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ function is_static_element(node) {
150150
return false;
151151
}
152152

153+
// We need to apply src and loading after appending the img to the DOM for lazy loading to work
154+
if (node.name === 'img' && attribute.name === 'loading') {
155+
return false;
156+
}
157+
153158
if (node.name.includes('-')) {
154159
return false; // we're setting all attributes on custom elements through properties
155160
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: `<h1></h1><img src="..." loading="lazy" />`
5+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<h1></h1>
2+
<img src="..." loading="lazy">

0 commit comments

Comments
 (0)