Skip to content

Commit 64ca35f

Browse files
committed
fix
1 parent a27cdee commit 64ca35f

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

packages/svelte/src/compiler/phases/2-analyze/visitors/Attribute.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @import { ArrowFunctionExpression, Expression, FunctionDeclaration, FunctionExpression } from 'estree' */
22
/** @import { AST, DelegatedEvent, SvelteNode } from '#compiler' */
33
/** @import { Context } from '../types' */
4-
import { is_capture_event, is_delegated } from '../../../../utils.js';
4+
import { cannot_be_set_statically, is_capture_event, is_delegated } from '../../../../utils.js';
55
import {
66
get_attribute_chunks,
77
get_attribute_expression,
@@ -16,14 +16,28 @@ import { mark_subtree_dynamic } from './shared/fragment.js';
1616
export function Attribute(node, context) {
1717
context.next();
1818

19-
// special case
20-
if (node.name === 'value') {
21-
const parent = /** @type {SvelteNode} */ (context.path.at(-1));
22-
if (parent.type === 'RegularElement' && parent.name === 'option') {
19+
const parent = /** @type {SvelteNode} */ (context.path.at(-1));
20+
21+
if (parent.type === 'RegularElement') {
22+
// special case <option value="" />
23+
if (node.name === 'value' && parent.name === 'option') {
24+
mark_subtree_dynamic(context.path);
25+
}
26+
27+
// special case <img loading="lazy" />
28+
if (node.name === 'loading' && parent.name === 'img') {
2329
mark_subtree_dynamic(context.path);
2430
}
2531
}
2632

33+
if (is_event_attribute(node)) {
34+
mark_subtree_dynamic(context.path);
35+
}
36+
37+
if (cannot_be_set_statically(node.name)) {
38+
mark_subtree_dynamic(context.path);
39+
}
40+
2741
if (node.value !== true) {
2842
for (const chunk of get_attribute_chunks(node.value)) {
2943
if (chunk.type !== 'ExpressionTag') continue;

packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @import { AST } from '#compiler' */
22
/** @import { Context } from '../types' */
3-
import { cannot_be_set_statically, is_mathml, is_svg, is_void } from '../../../../utils.js';
3+
import { is_mathml, is_svg, is_void } from '../../../../utils.js';
44
import {
55
is_tag_valid_with_ancestor,
66
is_tag_valid_with_parent
@@ -75,14 +75,6 @@ export function RegularElement(node, context) {
7575
node.attributes.push(create_attribute('value', child.start, child.end, [child]));
7676
}
7777

78-
if (
79-
node.attributes.some(
80-
(attribute) => attribute.type === 'Attribute' && cannot_be_set_statically(attribute.name)
81-
)
82-
) {
83-
mark_subtree_dynamic(context.path);
84-
}
85-
8678
const binding = context.state.scope.get(node.name);
8779
if (
8880
binding !== null &&

packages/svelte/tests/snapshot/samples/skip-static-subtree/_expected/client/index.svelte.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ export default function Skip_static_subtree($$anchor, $$props) {
4242
$.reset(select);
4343

4444
var img = $.sibling(select, 2);
45+
var div_2 = $.sibling(img, 2);
46+
var img_1 = $.child(div_2);
4547

46-
$.next(2);
48+
$.reset(div_2);
4749
$.template_effect(() => $.set_text(text, $$props.title));
4850
$.handle_lazy_img(img);
51+
$.handle_lazy_img(img_1);
4952
$.append($$anchor, fragment);
5053
}

0 commit comments

Comments
 (0)