-
Notifications
You must be signed in to change notification settings - Fork 880
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[reactive-element] Add CSP compatibility for element styles (#2134)
- Loading branch information
1 parent
d8ff590
commit 0470d86
Showing
4 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@lit/reactive-element': patch | ||
--- | ||
|
||
Allow assigning a nonce value to `window.litNonce` in order to apply the nonce to generated <style> tags for CSP compatibility. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/reactive-element/src/test/reactive-element-csp_test.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<html> | ||
<head> | ||
<meta | ||
http-equiv="Content-Security-Policy" | ||
content="style-src 'nonce-abc123';" | ||
/> | ||
<script> | ||
window.litNonce = 'abc123'; | ||
</script> | ||
<link rel="stylesheet" href="../../node_modules/mocha/mocha.css" /> | ||
</head> | ||
|
||
<body> | ||
<script type="module"> | ||
// node resolution doesn't seem to be working here. | ||
import { | ||
mocha, | ||
sessionFinished, | ||
sessionFailed, | ||
} from '../../../tests/node_modules/@web/test-runner-mocha/dist/standalone.js'; | ||
// import { mocha, sessionFinished, sessionFailed } from '@web/test-runner-mocha'; | ||
|
||
(async () => { | ||
try { | ||
// setup mocha | ||
mocha.setup({ui: 'tdd'}); | ||
|
||
await import('./reactive-element_styling_test.js'); | ||
|
||
// run the tests, and notify the test runner after finishing | ||
mocha.run(() => { | ||
sessionFinished(); | ||
}); | ||
} catch (error) { | ||
console.error(error); | ||
// notify the test runner about errors | ||
sessionFailed(error); | ||
} | ||
})(); | ||
</script> | ||
<div id="mocha"></div> | ||
</body> | ||
</html> |