You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When adding inline JavaScript with a nonce to satisfy the Content Security Policy, the CSP properties defined within svelte.config.js will clobber it.
It's hard to describe this. The problem may be better illustrated in this comment and this Github discussion. The OP in this discussion suggests that changing hooks' behavior might be a solution to address this.
Reproduction
Set your computer's system to use dark mode.
Use this code https://stackblitz.com/github/huntabyte/mode-watcher which shows a simple dark/light mode switcher. Notice it works well; i.e. there is no Flash of Unstyled Content showing a white page (containing the page's content) before the dark mode.
But now update this project's svelte.config.js to include a CSP.
If you enable default-src or script-src rules, either individually or both together, a FOUC occurs (i.e. you'll see a light UI–not merely an empty viewport–before it becomes a dark UI). If these properties exist even with an empty array value or a ['*'] value, then FOUC still occurs. Commenting those two properties out removes the FOUC.
Describe the bug
Possible issue for SvelteKit v2.
When adding inline JavaScript with a nonce to satisfy the Content Security Policy, the CSP properties defined within
svelte.config.js
will clobber it.It's hard to describe this. The problem may be better illustrated in this comment and this Github discussion. The OP in this discussion suggests that changing hooks' behavior might be a solution to address this.
Reproduction
svelte.config.js
to include a CSP.If you enable
default-src
orscript-src
rules, either individually or both together, a FOUC occurs (i.e. you'll see a light UI–not merely an empty viewport–before it becomes a dark UI). If these properties exist even with an empty array value or a['*']
value, then FOUC still occurs. Commenting those two properties out removes the FOUC.mode-watcher
adds an inline script tag with a nonce to satisfy the CSP. This works, unlesssvelte.config.js
contains eitherdefault-src
orscript-src
properties, as mentioned, in which case the inline CSP seems to be ignored and the inline script does not execute.Logs
No response
System Info
Severity
annoyance
Additional Information
The workarounds currently are:
svelte.config.js
(reduces security).The text was updated successfully, but these errors were encountered: