diff --git a/CHANGELOG.md b/CHANGELOG.md index 53191504a516..437d084faffd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ * Add `a11y-no-static-element-interactions`rule ([#8251](https://github.com/sveltejs/svelte/pull/8251)) * Bind `null` option and input values consistently ([#8312](https://github.com/sveltejs/svelte/issues/8312)) * Allow `$store` to be used with changing values including nullish values ([#7555](https://github.com/sveltejs/svelte/issues/7555)) +* Initialize stylesheet with `/* empty */` to enable setting CSP directive that also works in Safari ([#7800](https://github.com/sveltejs/svelte/pull/7800)) +* Treat slots as if they don't exist when using CSS adjacent and general sibling combinators ([#8284](https://github.com/sveltejs/svelte/issues/8284)) ## Unreleased (3.0) 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/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index 9125eb0b9829..16a58b191a77 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -157,6 +157,12 @@ 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 = '/* empty */'; append_stylesheet(get_root_for_style(node), style_element); return style_element.sheet as CSSStyleSheet; } 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..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 @@ -1,4 +1,4 @@ - +

Heading 1

Span 1 @@ -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..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 @@ -1,13 +1,13 @@ [ { "code": "css-unused-selector", - "message": "Unused CSS selector \"h1 ~ p\"", + "message": "Unused CSS selector \"h1 ~ slot > p\"", "start": { "column": 1, "line": 12 }, "end": { - "column": 7, + "column": 14, "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 1d98415321d7..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 @@ -1,4 +1,4 @@ - +

test

@@ -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..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 + span\"", + "message": "Unused CSS selector \"h1 + slot > span\"", "start": { - "column": 2, + "column": 1, "line": 10 } }