Skip to content

Commit fc4797c

Browse files
authored
[fix] only use optimized 'src' handling for 'html' namespace (#6580)
1 parent eee5e45 commit fc4797c

File tree

8 files changed

+171
-3
lines changed

8 files changed

+171
-3
lines changed

src/compiler/compile/render_dom/wrappers/Element/Attribute.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ export default class AttributeWrapper extends BaseAttributeWrapper {
8686
this.is_select_value_attribute = this.name === 'value' && this.parent.node.name === 'select';
8787
this.is_input_value = this.name === 'value' && this.parent.node.name === 'input';
8888
}
89-
90-
this.is_src = this.name === 'src'; // TODO retire this exception in favour of https://github.com/sveltejs/svelte/issues/3750
89+
90+
// TODO retire this exception in favour of https://github.com/sveltejs/svelte/issues/3750
91+
this.is_src = this.name === 'src' && (!this.parent.node.namespace || this.parent.node.namespace === namespaces.html);
9192
this.should_cache = should_cache(this);
9293
}
9394

src/runtime/internal/dom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export function get_root_for_style(node: Node): ShadowRoot | Document {
148148
if (!node) return document;
149149

150150
const root = node.getRootNode ? node.getRootNode() : node.ownerDocument;
151-
if ((root as ShadowRoot).host) {
151+
if (root && (root as ShadowRoot).host) {
152152
return root as ShadowRoot;
153153
}
154154
return node.ownerDocument;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
options: {
3+
hydratable: true
4+
}
5+
};
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/* generated by Svelte vX.Y.Z */
2+
import {
3+
SvelteComponent,
4+
append_hydration,
5+
attr,
6+
children,
7+
claim_element,
8+
detach,
9+
init,
10+
insert_hydration,
11+
noop,
12+
safe_not_equal
13+
} from "svelte/internal";
14+
15+
function create_fragment(ctx) {
16+
let svg;
17+
let img;
18+
19+
return {
20+
c() {
21+
svg = document.createElementNS("https://svelte.dev/docs#svelte_options", "svg");
22+
img = document.createElementNS("https://svelte.dev/docs#svelte_options", "img");
23+
this.h();
24+
},
25+
l(nodes) {
26+
svg = claim_element(nodes, "svg", {});
27+
var svg_nodes = children(svg);
28+
img = claim_element(svg_nodes, "img", { alt: true, src: true });
29+
svg_nodes.forEach(detach);
30+
this.h();
31+
},
32+
h() {
33+
attr(img, "alt", "potato");
34+
attr(img, "src", /*url*/ ctx[0]);
35+
},
36+
m(target, anchor) {
37+
insert_hydration(target, svg, anchor);
38+
append_hydration(svg, img);
39+
},
40+
p(ctx, [dirty]) {
41+
if (dirty & /*url*/ 1) {
42+
attr(img, "src", /*url*/ ctx[0]);
43+
}
44+
},
45+
i: noop,
46+
o: noop,
47+
d(detaching) {
48+
if (detaching) detach(svg);
49+
}
50+
};
51+
}
52+
53+
function instance($$self, $$props, $$invalidate) {
54+
let { url } = $$props;
55+
56+
$$self.$$set = $$props => {
57+
if ('url' in $$props) $$invalidate(0, url = $$props.url);
58+
};
59+
60+
return [url];
61+
}
62+
63+
class Component extends SvelteComponent {
64+
constructor(options) {
65+
super();
66+
init(this, options, instance, create_fragment, safe_not_equal, { url: 0 });
67+
}
68+
}
69+
70+
export default Component;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<svelte:options namespace="foreign" />
2+
3+
<script>
4+
export let url;
5+
</script>
6+
7+
<svg>
8+
<img alt="potato" src={url}>
9+
</svg>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
options: {
3+
hydratable: true
4+
}
5+
};
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* generated by Svelte vX.Y.Z */
2+
import {
3+
SvelteComponent,
4+
append_hydration,
5+
attr,
6+
children,
7+
claim_element,
8+
detach,
9+
init,
10+
insert_hydration,
11+
noop,
12+
safe_not_equal,
13+
svg_element
14+
} from "svelte/internal";
15+
16+
function create_fragment(ctx) {
17+
let svg;
18+
let img;
19+
20+
return {
21+
c() {
22+
svg = svg_element("svg");
23+
img = svg_element("img");
24+
this.h();
25+
},
26+
l(nodes) {
27+
svg = claim_element(nodes, "svg", {}, 1);
28+
var svg_nodes = children(svg);
29+
img = claim_element(svg_nodes, "img", { alt: true, src: true }, 1);
30+
svg_nodes.forEach(detach);
31+
this.h();
32+
},
33+
h() {
34+
attr(img, "alt", "potato");
35+
attr(img, "src", /*url*/ ctx[0]);
36+
},
37+
m(target, anchor) {
38+
insert_hydration(target, svg, anchor);
39+
append_hydration(svg, img);
40+
},
41+
p(ctx, [dirty]) {
42+
if (dirty & /*url*/ 1) {
43+
attr(img, "src", /*url*/ ctx[0]);
44+
}
45+
},
46+
i: noop,
47+
o: noop,
48+
d(detaching) {
49+
if (detaching) detach(svg);
50+
}
51+
};
52+
}
53+
54+
function instance($$self, $$props, $$invalidate) {
55+
let { url } = $$props;
56+
57+
$$self.$$set = $$props => {
58+
if ('url' in $$props) $$invalidate(0, url = $$props.url);
59+
};
60+
61+
return [url];
62+
}
63+
64+
class Component extends SvelteComponent {
65+
constructor(options) {
66+
super();
67+
init(this, options, instance, create_fragment, safe_not_equal, { url: 0 });
68+
}
69+
}
70+
71+
export default Component;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
export let url;
3+
</script>
4+
5+
<svg>
6+
<img alt="potato" src={url}>
7+
</svg>

0 commit comments

Comments
 (0)