Skip to content

Commit 419546f

Browse files
fix: don't skip custom elements with attributes (#12939)
* fix: don't skip custom elements with attributes fixes #12934 * still need this --------- Co-authored-by: Rich Harris <[email protected]>
1 parent 9c2ca69 commit 419546f

File tree

6 files changed

+25
-4
lines changed

6 files changed

+25
-4
lines changed

.changeset/wild-moose-destroy.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: don't skip custom elements with attributes

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import {
77
} from '../../../../html-tree-validation.js';
88
import * as e from '../../../errors.js';
99
import * as w from '../../../warnings.js';
10-
import { create_attribute } from '../../nodes.js';
10+
import { create_attribute, is_custom_element_node } from '../../nodes.js';
1111
import { regex_starts_with_newline } from '../../patterns.js';
1212
import { check_element } from './shared/a11y.js';
1313
import { validate_element } from './shared/element.js';
14+
import { mark_subtree_dynamic } from './shared/fragment.js';
1415

1516
/**
1617
* @param {RegularElement} node
@@ -88,6 +89,11 @@ export function RegularElement(node, context) {
8889
node.metadata.svg = is_svg(node.name);
8990
node.metadata.mathml = is_mathml(node.name);
9091

92+
if (is_custom_element_node(node) && node.attributes.length > 0) {
93+
// we're setting all attributes on custom elements through properties
94+
mark_subtree_dynamic(context.path);
95+
}
96+
9197
if (context.state.parent_element) {
9298
let past_parent = false;
9399
let only_warn = false;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @import { Expression } from 'estree' */
22
/** @import { ExpressionTag, SvelteNode, Text } from '#compiler' */
3-
/** @import { ComponentClientTransformState, ComponentContext } from '../../types' */
3+
/** @import { ComponentContext } from '../../types' */
44
import { is_event_attribute, is_text_attribute } from '../../../../../utils/ast.js';
55
import * as b from '../../../../../utils/builders.js';
66
import { build_template_literal, build_update } from './utils.js';

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "svelte/internal/disclose-version";
22
import * as $ from "svelte/internal/client";
33

4-
var root = $.template(`<header><nav><a href="/">Home</a> <a href="/away">Away</a></nav></header> <main><h1> </h1> <div class="static"><p>we don't need to traverse these nodes</p></div> <p>or</p> <p>these</p> <p>ones</p> <!></main>`, 1);
4+
var root = $.template(`<header><nav><a href="/">Home</a> <a href="/away">Away</a></nav></header> <main><h1> </h1> <div class="static"><p>we don't need to traverse these nodes</p></div> <p>or</p> <p>these</p> <p>ones</p> <!></main> <cant-skip><custom-elements></custom-elements></cant-skip>`, 3);
55

66
export default function Skip_static_subtree($$anchor, $$props) {
77
var fragment = root();
@@ -15,6 +15,12 @@ export default function Skip_static_subtree($$anchor, $$props) {
1515

1616
$.html(node, () => $$props.content, false, false);
1717
$.reset(main);
18+
19+
var cant_skip = $.sibling(main, 2);
20+
var custom_elements = $.child(cant_skip);
21+
22+
$.set_custom_element_data(custom_elements, "with", "attributes");
23+
$.reset(cant_skip);
1824
$.template_effect(() => $.set_text(text, $$props.title));
1925
$.append($$anchor, fragment);
2026
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import * as $ from "svelte/internal/server";
33
export default function Skip_static_subtree($$payload, $$props) {
44
let { title, content } = $$props;
55

6-
$$payload.out += `<header><nav><a href="/">Home</a> <a href="/away">Away</a></nav></header> <main><h1>${$.escape(title)}</h1> <div class="static"><p>we don't need to traverse these nodes</p></div> <p>or</p> <p>these</p> <p>ones</p> ${$.html(content)}</main>`;
6+
$$payload.out += `<header><nav><a href="/">Home</a> <a href="/away">Away</a></nav></header> <main><h1>${$.escape(title)}</h1> <div class="static"><p>we don't need to traverse these nodes</p></div> <p>or</p> <p>these</p> <p>ones</p> ${$.html(content)}</main> <cant-skip><custom-elements with="attributes"></custom-elements></cant-skip>`;
77
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@
1919
<p>ones</p>
2020
{@html content}
2121
</main>
22+
23+
<cant-skip>
24+
<custom-elements with="attributes"></custom-elements>
25+
</cant-skip>

0 commit comments

Comments
 (0)