Skip to content

Commit 1c078b7

Browse files
tanhauhautaylorzane
authored andcommitted
valid XHTML syntax in innerHTML for static elements (sveltejs#5317)
1 parent 792e172 commit 1c078b7

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* Fix using `<svelte:component>` in `{:catch}` ([#5259](https://github.com/sveltejs/svelte/issues/5259))
1212
* Fix setting one-way bound `<input>` `value` to `undefined` when it has spread attributes ([#5270](https://github.com/sveltejs/svelte/issues/5270))
1313
* Fix deep two-way bindings inside an `{#each}` involving a store ([#5286](https://github.com/sveltejs/svelte/issues/5286))
14+
* Use valid XHTML for elements that are optimised and inserted with `.innerHTML` ([#5315](https://github.com/sveltejs/svelte/issues/5315))
1415
* Fix reactivity of `$$props` in slot fallback content ([#5367](https://github.com/sveltejs/svelte/issues/5367))
1516

1617
## 3.24.1

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -997,12 +997,14 @@ function to_html(wrappers: Array<ElementWrapper | TextWrapper | MustacheTagWrapp
997997
state.quasi.value.raw += `"`;
998998
});
999999

1000-
state.quasi.value.raw += '>';
1001-
10021000
if (!wrapper.void) {
1001+
state.quasi.value.raw += '>';
1002+
10031003
to_html(wrapper.fragment.nodes as Array<ElementWrapper | TextWrapper>, block, literal, state);
10041004

10051005
state.quasi.value.raw += `</${wrapper.node.name}>`;
1006+
} else {
1007+
state.quasi.value.raw += '/>';
10061008
}
10071009
}
10081010
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* generated by Svelte vX.Y.Z */
2+
import {
3+
SvelteComponent,
4+
detach,
5+
element,
6+
init,
7+
insert,
8+
noop,
9+
safe_not_equal
10+
} from "svelte/internal";
11+
12+
function create_fragment(ctx) {
13+
let div;
14+
15+
return {
16+
c() {
17+
div = element("div");
18+
div.innerHTML = `<img alt="Star" width="100" height="100" src="http://mdn.mozillademos.org/files/12676/star.svg"/>`;
19+
},
20+
m(target, anchor) {
21+
insert(target, div, anchor);
22+
},
23+
p: noop,
24+
i: noop,
25+
o: noop,
26+
d(detaching) {
27+
if (detaching) detach(div);
28+
}
29+
};
30+
}
31+
32+
class Component extends SvelteComponent {
33+
constructor(options) {
34+
super();
35+
init(this, options, null, create_fragment, safe_not_equal, {});
36+
}
37+
}
38+
39+
export default Component;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>
2+
<img alt="Star" width="100" height="100" src="http://mdn.mozillademos.org/files/12676/star.svg" />
3+
</div>

0 commit comments

Comments
 (0)