[fix] Enable built-in transitions without style-src 'unsafe-inline' CSP directive (part 2) #6988
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a continuation of PR #6776 (I had to make a new PR while cleaning up the commit history), which fixes #6662. This version includes refactored tests and merge squashes the previous commits.
This PR allows Svelte's built-in transitions to work under a strict content security policy (CSP) without the
style-src 'unsafe-inline'
CSP directive. It checks for presence of an external CSS stylesheet with the title 'svelte-stylesheet' which contains no CSS rules (i.e. a blank stylesheet). This stylesheet is used at the beginning of the 1st transition rather creating a blank stylesheet and appending it to the DOM (which is in effect inline CSS, which a strict CSP won't allow). If the 'svelte-stylesheet' is not present, everything works the same as before (this also means that transitions will not work under a strict CSP withoutstyle-src 'unsafe-inline'
).Before submitting the PR, please make sure you do the following
[feat]
,[fix]
,[chore]
, or[docs]
.Tests
npm test
and lint the project withnpm run lint
To run the tests type
npm run test -- -g svelte-styles-csp
at the command line. To view tests in Chromium browser, setheadless_browser
tofalse
andtransition_delay
totrue
in 'tests/svelte-styles-csp/index.ts'.