From 2fc5bab2fbf3f5f1c83aedac86fa9dde67dd6894 Mon Sep 17 00:00:00 2001 From: Karl Erik Hofseth Date: Fri, 19 Aug 2022 16:25:11 +0200 Subject: [PATCH 1/8] Make inserted style tag non-empty --- src/runtime/internal/dom.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index d359513eb417..1a5c8102b3f5 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -156,6 +156,7 @@ export function get_root_for_style(node: Node): ShadowRoot | Document { export function append_empty_stylesheet(node: Node) { const style_element = element('style') as HTMLStyleElement; + style_element.textContent = '/* empty */'; append_stylesheet(get_root_for_style(node), style_element); return style_element.sheet as CSSStyleSheet; } From 8e33adf3334fd3c1d75bb5f41fab09104dace717 Mon Sep 17 00:00:00 2001 From: Karl Erik Hofseth Date: Fri, 19 Aug 2022 16:39:48 +0200 Subject: [PATCH 2/8] Don't replace existing style content, only empty --- src/runtime/internal/dom.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index 1a5c8102b3f5..7856ccc384e4 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -156,7 +156,7 @@ export function get_root_for_style(node: Node): ShadowRoot | Document { export function append_empty_stylesheet(node: Node) { const style_element = element('style') as HTMLStyleElement; - style_element.textContent = '/* empty */'; + style_element.textContent = style_element.textContent || '/* empty */'; append_stylesheet(get_root_for_style(node), style_element); return style_element.sheet as CSSStyleSheet; } From da5ddd40b42f5d5c6148f6430af211f09a4a5f0d Mon Sep 17 00:00:00 2001 From: Karl Erik Hofseth Date: Sat, 20 Aug 2022 10:12:39 +0200 Subject: [PATCH 3/8] Add comment explaining why this madness --- src/runtime/internal/dom.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index 7856ccc384e4..2c0b141fb59a 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -156,6 +156,11 @@ export function get_root_for_style(node: Node): ShadowRoot | Document { export function append_empty_stylesheet(node: Node) { const style_element = element('style') as HTMLStyleElement; + // For transitions to work without 'style-src: unsafe-inline' Content Security Policy, + // these empty tags need to be allowed with a hash as a workaround until we move to the Web Animations API. + // Using the hash for the empty string (for an empty tag) works in all browsers except Safari. + // So as a workaround for the workaround, when we append empty style tags we set their content to /* empty */. + // The hash 'sha256-9OlNO0DNEeaVzHL4RZwCLsBHA8WBQ8toBp/4F5XV2nc=' will then work even in Safari. style_element.textContent = style_element.textContent || '/* empty */'; append_stylesheet(get_root_for_style(node), style_element); return style_element.sheet as CSSStyleSheet; From e106eb55b30bd89898ad374dd2ee99f6d65609cf Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Thu, 4 May 2023 16:04:33 +0200 Subject: [PATCH 4/8] Update src/runtime/internal/dom.ts --- src/runtime/internal/dom.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index 2c0b141fb59a..8778638c8b4b 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -161,7 +161,7 @@ export function append_empty_stylesheet(node: Node) { // Using the hash for the empty string (for an empty tag) works in all browsers except Safari. // So as a workaround for the workaround, when we append empty style tags we set their content to /* empty */. // The hash 'sha256-9OlNO0DNEeaVzHL4RZwCLsBHA8WBQ8toBp/4F5XV2nc=' will then work even in Safari. - style_element.textContent = style_element.textContent || '/* empty */'; + style_element.textContent = '/* empty */'; append_stylesheet(get_root_for_style(node), style_element); return style_element.sheet as CSSStyleSheet; } From 1231d9a5f1a98d0d496f818914f1b8395dbb5ddf Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Thu, 4 May 2023 16:38:10 +0200 Subject: [PATCH 5/8] force merge --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d0ee54c0d2a..db61c31273a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Svelte changelog +hi + ## Unreleased * Fix hydration issue with using `{@html}` and components in `svelte:head` ([#4533](https://github.com/sveltejs/svelte/issues/4533), [#6463](https://github.com/sveltejs/svelte/issues/6463), [#7444](https://github.com/sveltejs/svelte/issues/7444)) From b65d94d388ea8d31f2e1f03c7565a89f6b2a50d2 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Thu, 4 May 2023 16:45:11 +0200 Subject: [PATCH 6/8] tests --- .../samples/style_manager-cleanup/_config.js | 4 ++-- .../input.svelte | 2 +- .../input.svelte | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/runtime-puppeteer/samples/style_manager-cleanup/_config.js b/test/runtime-puppeteer/samples/style_manager-cleanup/_config.js index b3a5a97e4596..47d7dee83f51 100644 --- a/test/runtime-puppeteer/samples/style_manager-cleanup/_config.js +++ b/test/runtime-puppeteer/samples/style_manager-cleanup/_config.js @@ -5,12 +5,12 @@ export default { test: async ({ component, assert, window, waitUntil }) => { assert.htmlEqual(window.document.head.innerHTML, ''); component.visible = true; - assert.htmlEqual(window.document.head.innerHTML, ''); + assert.htmlEqual(window.document.head.innerHTML, ''); await waitUntil(() => window.document.head.innerHTML === ''); assert.htmlEqual(window.document.head.innerHTML, ''); component.visible = false; - assert.htmlEqual(window.document.head.innerHTML, ''); + assert.htmlEqual(window.document.head.innerHTML, ''); await waitUntil(() => window.document.head.innerHTML === ''); assert.htmlEqual(window.document.head.innerHTML, ''); } diff --git a/test/validator/samples/general-siblings-combinator-in-custom-element-selects-slot-fallback/input.svelte b/test/validator/samples/general-siblings-combinator-in-custom-element-selects-slot-fallback/input.svelte index ffaeb2c09708..325841373f99 100644 --- a/test/validator/samples/general-siblings-combinator-in-custom-element-selects-slot-fallback/input.svelte +++ b/test/validator/samples/general-siblings-combinator-in-custom-element-selects-slot-fallback/input.svelte @@ -1,4 +1,4 @@ - +

Heading 1

Span 1 diff --git a/test/validator/samples/siblings-combinator-in-custom-element-selects-slot-fallback/input.svelte b/test/validator/samples/siblings-combinator-in-custom-element-selects-slot-fallback/input.svelte index 1d98415321d7..faf34125b141 100644 --- a/test/validator/samples/siblings-combinator-in-custom-element-selects-slot-fallback/input.svelte +++ b/test/validator/samples/siblings-combinator-in-custom-element-selects-slot-fallback/input.svelte @@ -1,4 +1,4 @@ - +

test

From 8e7eeada2a21ffe2eb59df2eb35dc88757435bc8 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Thu, 4 May 2023 16:58:03 +0200 Subject: [PATCH 7/8] drive by fixes --- src/compiler/compile/css/Selector.ts | 36 ++++++++----------- .../input.svelte | 8 ++--- .../warnings.json | 2 +- .../input.svelte | 8 ++--- .../warnings.json | 2 +- 5 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/compiler/compile/css/Selector.ts b/src/compiler/compile/css/Selector.ts index 705e341601e1..7c1652bb551e 100644 --- a/src/compiler/compile/css/Selector.ts +++ b/src/compiler/compile/css/Selector.ts @@ -471,28 +471,22 @@ function get_element_parent(node: Element): Element | null { } /** - * Finds the given node's previous sibling in the DOM - * - * Unless the component is a custom element (web component), which in this - * case, the element is actually real, the Svelte is just a - * placeholder and is not actually real. Any children nodes in - * are 'flattened' and considered as the same level as the 's siblings - * - * e.g. - *

Heading 1

- * - *

Heading 2

- *
- * - * is considered to look like: - *

Heading 1

- *

Heading 2

- */ + * Finds the given node's previous sibling in the DOM + * + * The Svelte is just a placeholder and is not actually real. Any children nodes + * in are 'flattened' and considered as the same level as the 's siblings + * + * e.g. + *

Heading 1

+ * + *

Heading 2

+ *
+ * + * is considered to look like: + *

Heading 1

+ *

Heading 2

+ */ function find_previous_sibling(node: INode): INode { - if (node.component.compile_options.customElement) { - return node.prev; - } - let current_node: INode = node; do { if (current_node.type === 'Slot') { diff --git a/test/validator/samples/general-siblings-combinator-in-custom-element-selects-slot-fallback/input.svelte b/test/validator/samples/general-siblings-combinator-in-custom-element-selects-slot-fallback/input.svelte index 325841373f99..455d1da1703d 100644 --- a/test/validator/samples/general-siblings-combinator-in-custom-element-selects-slot-fallback/input.svelte +++ b/test/validator/samples/general-siblings-combinator-in-custom-element-selects-slot-fallback/input.svelte @@ -8,13 +8,13 @@
diff --git a/test/validator/samples/general-siblings-combinator-in-custom-element-selects-slot-fallback/warnings.json b/test/validator/samples/general-siblings-combinator-in-custom-element-selects-slot-fallback/warnings.json index 0336660cafc7..936109f53811 100644 --- a/test/validator/samples/general-siblings-combinator-in-custom-element-selects-slot-fallback/warnings.json +++ b/test/validator/samples/general-siblings-combinator-in-custom-element-selects-slot-fallback/warnings.json @@ -1,7 +1,7 @@ [ { "code": "css-unused-selector", - "message": "Unused CSS selector \"h1 ~ p\"", + "message": "Unused CSS selector \"h1 ~ slot > p\"", "start": { "column": 1, "line": 12 diff --git a/test/validator/samples/siblings-combinator-in-custom-element-selects-slot-fallback/input.svelte b/test/validator/samples/siblings-combinator-in-custom-element-selects-slot-fallback/input.svelte index faf34125b141..0ec25f7ac4bd 100644 --- a/test/validator/samples/siblings-combinator-in-custom-element-selects-slot-fallback/input.svelte +++ b/test/validator/samples/siblings-combinator-in-custom-element-selects-slot-fallback/input.svelte @@ -7,12 +7,12 @@ diff --git a/test/validator/samples/siblings-combinator-in-custom-element-selects-slot-fallback/warnings.json b/test/validator/samples/siblings-combinator-in-custom-element-selects-slot-fallback/warnings.json index 3ef66ebf60dc..9db06f83091b 100644 --- a/test/validator/samples/siblings-combinator-in-custom-element-selects-slot-fallback/warnings.json +++ b/test/validator/samples/siblings-combinator-in-custom-element-selects-slot-fallback/warnings.json @@ -5,7 +5,7 @@ "column": 11, "line": 10 }, - "message": "Unused CSS selector \"h1 + span\"", + "message": "Unused CSS selector \"h1 + slot > span\"", "start": { "column": 2, "line": 10 From 14c680e1b7630b5738f8321c3dacbbb6e52eebb0 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Thu, 4 May 2023 17:05:23 +0200 Subject: [PATCH 8/8] fix --- .../warnings.json | 2 +- .../warnings.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/validator/samples/general-siblings-combinator-in-custom-element-selects-slot-fallback/warnings.json b/test/validator/samples/general-siblings-combinator-in-custom-element-selects-slot-fallback/warnings.json index 936109f53811..c1db03aa548b 100644 --- a/test/validator/samples/general-siblings-combinator-in-custom-element-selects-slot-fallback/warnings.json +++ b/test/validator/samples/general-siblings-combinator-in-custom-element-selects-slot-fallback/warnings.json @@ -7,7 +7,7 @@ "line": 12 }, "end": { - "column": 7, + "column": 14, "line": 12 } } diff --git a/test/validator/samples/siblings-combinator-in-custom-element-selects-slot-fallback/warnings.json b/test/validator/samples/siblings-combinator-in-custom-element-selects-slot-fallback/warnings.json index 9db06f83091b..c027e667609a 100644 --- a/test/validator/samples/siblings-combinator-in-custom-element-selects-slot-fallback/warnings.json +++ b/test/validator/samples/siblings-combinator-in-custom-element-selects-slot-fallback/warnings.json @@ -2,12 +2,12 @@ { "code": "css-unused-selector", "end": { - "column": 11, + "column": 17, "line": 10 }, "message": "Unused CSS selector \"h1 + slot > span\"", "start": { - "column": 2, + "column": 1, "line": 10 } }