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 = {
18891889 let is_content_editable = false ;
18901890 let has_content_editable_binding = false ;
18911891
1892- if ( is_custom_element ) {
1892+ if (
18931893 // cloneNode is faster, but it does not instantiate the underlying class of the
18941894 // custom element until the template is connected to the dom, which would
18951895 // cause problems when setting properties on the custom element.
18961896 // 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+ ) {
18971909 metadata . context . template_needs_import_node = true ;
18981910 }
18991911
Original file line number Diff line number Diff line change @@ -251,7 +251,7 @@ export function text(anchor) {
251251 return push_template_node ( node ) ;
252252}
253253
254- export const comment = template ( '<!>' , TEMPLATE_FRAGMENT ) ;
254+ export const comment = template ( '<!>' , TEMPLATE_FRAGMENT | TEMPLATE_USE_IMPORT_NODE ) ;
255255
256256/**
257257 * 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