Skip to content

Commit 6234543

Browse files
authored
html anchor in head (#5071)
1 parent f739b47 commit 6234543

File tree

9 files changed

+84
-52
lines changed

9 files changed

+84
-52
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
* Support nullish coalescing (`??`) and optional chaining (`?.`) operators ([#1972](https://github.com/sveltejs/svelte/issues/1972))
66
* Support `import.meta` ([#4379](https://github.com/sveltejs/svelte/issues/4379))
7-
* Fix placement of `{@html}` when used at the root of a slot or the root of a component ([#5012](https://github.com/sveltejs/svelte/issues/5012))
7+
* Fix placement of `{@html}` when used at the root of a slot, at the root of a component, or in `<svelte:head>` ([#5012](https://github.com/sveltejs/svelte/issues/5012), [#5071](https://github.com/sveltejs/svelte/pull/5071))
88
* Fix handling of `import`ed value that is used as a store and is also mutated ([#5019](https://github.com/sveltejs/svelte/issues/5019))
99
* Do not display `a11y-missing-content` warning on elements with `contenteditable` bindings ([#5020](https://github.com/sveltejs/svelte/issues/5020))
1010
* Fix handling of `this` in inline function expressions in the template ([#5033](https://github.com/sveltejs/svelte/issues/5033))

src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default class RawMustacheTagWrapper extends Tag {
5151
content => x`${html_tag}.p(${content})`
5252
);
5353

54-
const update_anchor = in_head ? 'null' : needs_anchor ? html_anchor : this.next ? this.next.var : 'null';
54+
const update_anchor = needs_anchor ? html_anchor : this.next ? this.next.var : 'null';
5555

5656
block.chunks.hydrate.push(b`${html_tag} = new @HtmlTag(${update_anchor});`);
5757
block.chunks.mount.push(b`${html_tag}.m(${init}, ${parent_node || '#target'}, ${parent_node ? null : '#anchor'});`);
Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,3 @@
11
export default {
2-
html: `
3-
<button>Switch</button>
4-
<p>Another first line</p>
5-
<p>This line should be last.</p>
6-
`,
7-
async test({ assert, target, window }) {
8-
const btn = target.querySelector("button");
9-
const clickEvent = new window.MouseEvent("click");
10-
11-
await btn.dispatchEvent(clickEvent);
12-
13-
assert.htmlEqual(
14-
target.innerHTML,
15-
`
16-
<button>Switch</button>
17-
<p>First line</p>
18-
<p>This line should be last.</p>
19-
`
20-
);
21-
22-
await btn.dispatchEvent(clickEvent);
23-
24-
assert.htmlEqual(
25-
target.innerHTML,
26-
`
27-
<button>Switch</button>
28-
<p>Another first line</p>
29-
<p>This line should be last.</p>
30-
`
31-
);
32-
},
2+
html: `<p>x<span>baz</span></p>`
333
};
Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1 @@
1-
<script>
2-
import Component from './Component.svelte';
3-
4-
let content1 = `<p>First line</p>`;
5-
let content2 = `<p>Another first line</p>`
6-
7-
let show = false;
8-
$: content = show ? content1 : content2;
9-
</script>
10-
11-
<button on:click={() => show = !show}>
12-
Switch
13-
</button>
14-
15-
<Component>
16-
{@html content}
17-
</Component>
1+
<p>{@html 'x'}<span>baz</span></p>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default {
2+
async test({ assert, target, window }) {
3+
const btn = target.querySelector("button");
4+
const clickEvent = new window.MouseEvent("click");
5+
6+
assert.equal(window.document.head.innerHTML.includes('<style>body { color: blue; }</style><style>body { color: green; }</style>'), true);
7+
8+
await btn.dispatchEvent(clickEvent);
9+
10+
assert.equal(window.document.head.innerHTML.includes('<style>body { color: red; }</style><style>body { color: green; }</style>'), true);
11+
12+
await btn.dispatchEvent(clickEvent);
13+
14+
assert.equal(window.document.head.innerHTML.includes('<style>body { color: blue; }</style><style>body { color: green; }</style>'), true);
15+
},
16+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script>
2+
let content1 = `<style>body { color: red; }</style>`;
3+
let content2 = `<style>body { color: blue; }</style>`
4+
5+
let show = false;
6+
$: content = show ? content1 : content2;
7+
</script>
8+
9+
<button on:click={() => show = !show}>
10+
Switch
11+
</button>
12+
13+
<svelte:head>
14+
{@html content}
15+
<style>body { color: green; }</style>
16+
</svelte:head>
Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
11
export default {
2-
html: `<p>x<span>baz</span></p>`
2+
html: `
3+
<button>Switch</button>
4+
<p>Another first line</p>
5+
<p>This line should be last.</p>
6+
`,
7+
async test({ assert, target, window }) {
8+
const btn = target.querySelector("button");
9+
const clickEvent = new window.MouseEvent("click");
10+
11+
await btn.dispatchEvent(clickEvent);
12+
13+
assert.htmlEqual(
14+
target.innerHTML,
15+
`
16+
<button>Switch</button>
17+
<p>First line</p>
18+
<p>This line should be last.</p>
19+
`
20+
);
21+
22+
await btn.dispatchEvent(clickEvent);
23+
24+
assert.htmlEqual(
25+
target.innerHTML,
26+
`
27+
<button>Switch</button>
28+
<p>Another first line</p>
29+
<p>This line should be last.</p>
30+
`
31+
);
32+
},
333
};
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
<p>{@html 'x'}<span>baz</span></p>
1+
<script>
2+
import Component from './Component.svelte';
3+
4+
let content1 = `<p>First line</p>`;
5+
let content2 = `<p>Another first line</p>`
6+
7+
let show = false;
8+
$: content = show ? content1 : content2;
9+
</script>
10+
11+
<button on:click={() => show = !show}>
12+
Switch
13+
</button>
14+
15+
<Component>
16+
{@html content}
17+
</Component>

0 commit comments

Comments
 (0)