Skip to content

Commit 81bd131

Browse files
committed
feat: add <svelte:html> element
closes #8663
1 parent b145035 commit 81bd131

File tree

36 files changed

+232
-10
lines changed

36 files changed

+232
-10
lines changed

.changeset/lemon-paws-work.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': minor
3+
---
4+
5+
feat: add `<svelte:html>` element
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: <svelte:html>
3+
---
4+
5+
```svelte
6+
<svelte:html attribute={value} onevent={handler} />
7+
```
8+
9+
Similarly to `<svelte:body>`, this element allows you to add properties and listeners to events on `document.documentElement`. This is useful for attributes such as `lang` which influence how the browser interprets the content.
10+
11+
As with `<svelte:window>`, `<svelte:document>` and `<svelte:body>`, this element may only appear the top level of your component and must never be inside a block or element.

documentation/docs/98-reference/.generated/compile-errors.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,12 @@ Invalid component definition — must be an `{expression}`
798798
`<svelte:head>` cannot have attributes nor directives
799799
```
800800

801+
### svelte_html_illegal_attribute
802+
803+
```
804+
`<svelte:html>` can only have regular attributes
805+
```
806+
801807
### svelte_meta_duplicate
802808

803809
```

packages/svelte/elements.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,6 +1998,7 @@ export interface SvelteHTMLElements {
19981998
'svelte:window': SvelteWindowAttributes;
19991999
'svelte:document': SvelteDocumentAttributes;
20002000
'svelte:body': HTMLAttributes<HTMLElement>;
2001+
'svelte:html': HTMLAttributes<HTMLElement>;
20012002
'svelte:fragment': { slot?: string };
20022003
'svelte:options': {
20032004
customElement?:

packages/svelte/messages/compile-errors/template.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ HTML restricts where certain elements can appear. In case of a violation the bro
306306

307307
> `<svelte:head>` cannot have attributes nor directives
308308
309+
## svelte_html_illegal_attribute
310+
311+
> `<svelte:html>` can only have regular attributes
312+
309313
## svelte_meta_duplicate
310314

311315
> A component can only have one `<%name%>` element

packages/svelte/src/compiler/errors.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,15 @@ export function svelte_head_illegal_attribute(node) {
12821282
e(node, "svelte_head_illegal_attribute", "`<svelte:head>` cannot have attributes nor directives");
12831283
}
12841284

1285+
/**
1286+
* `<svelte:html>` can only have regular attributes
1287+
* @param {null | number | NodeLike} node
1288+
* @returns {never}
1289+
*/
1290+
export function svelte_html_illegal_attribute(node) {
1291+
e(node, "svelte_html_illegal_attribute", "`<svelte:html>` can only have regular attributes");
1292+
}
1293+
12851294
/**
12861295
* A component can only have one `<%name%>` element
12871296
* @param {null | number | NodeLike} node

packages/svelte/src/compiler/phases/1-parse/state/element.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const root_only_meta_tags = new Map([
3333
['svelte:head', 'SvelteHead'],
3434
['svelte:options', 'SvelteOptions'],
3535
['svelte:window', 'SvelteWindow'],
36+
['svelte:html', 'SvelteHTML'],
3637
['svelte:document', 'SvelteDocument'],
3738
['svelte:body', 'SvelteBody']
3839
]);

0 commit comments

Comments
 (0)