File tree Expand file tree Collapse file tree 3 files changed +19
-2
lines changed
compiler/phases/3-transform/client/visitors Expand file tree Collapse file tree 3 files changed +19
-2
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " svelte " : patch
3
+ ---
4
+
5
+ fix: better support for lazy img elements
Original file line number Diff line number Diff line change @@ -1889,11 +1889,23 @@ export const template_visitors = {
1889
1889
let is_content_editable = false ;
1890
1890
let has_content_editable_binding = false ;
1891
1891
1892
- if ( is_custom_element ) {
1892
+ if (
1893
1893
// cloneNode is faster, but it does not instantiate the underlying class of the
1894
1894
// custom element until the template is connected to the dom, which would
1895
1895
// cause problems when setting properties on the custom element.
1896
1896
// Therefore we need to use importNode instead, which doesn't have this caveat.
1897
+ is_custom_element ||
1898
+ // If we have an <img loading="lazy"> occurance, we need to use importNode for FF
1899
+ // otherwise, the image won't be lazy. If we detect an attribute for "loading" then
1900
+ // just fallback to using importNode. Also if we have a spread attribute on the img,
1901
+ // then it might contain this property, so we also need to fallback there too.
1902
+ ( node . name === 'img' &&
1903
+ node . attributes . some (
1904
+ ( attribute ) =>
1905
+ attribute . type === 'SpreadAttribute' ||
1906
+ ( attribute . type === 'Attribute' && attribute . name === 'loading' )
1907
+ ) )
1908
+ ) {
1897
1909
metadata . context . template_needs_import_node = true ;
1898
1910
}
1899
1911
Original file line number Diff line number Diff line change @@ -251,7 +251,7 @@ export function text(anchor) {
251
251
return push_template_node ( node ) ;
252
252
}
253
253
254
- export const comment = template ( '<!>' , TEMPLATE_FRAGMENT ) ;
254
+ export const comment = template ( '<!>' , TEMPLATE_FRAGMENT | TEMPLATE_USE_IMPORT_NODE ) ;
255
255
256
256
/**
257
257
* Assign the created (or in hydration mode, traversed) dom elements to the current block
You can’t perform that action at this time.
0 commit comments