Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: provide a workaround for unsafe-inline CSP that also works in Safari #7800

Merged
6 changes: 6 additions & 0 deletions src/runtime/internal/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,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 = style_element.textContent || '/* empty */';
dummdidumm marked this conversation as resolved.
Show resolved Hide resolved
append_stylesheet(get_root_for_style(node), style_element);
return style_element.sheet as CSSStyleSheet;
}
Expand Down