@@ -30,7 +30,15 @@ defmodule LiveSvelte do
3030
3131 attr :csp_nonce , :string ,
3232 default: nil ,
33- doc: "A Content-Security-Policy nonce for the <script> and <style> tags"
33+ doc: "A Content-Security-Policy nonce for the generated <script> and <style> tags"
34+
35+ attr :csp_script_nonce , :string ,
36+ default: nil ,
37+ doc: "A Content-Security-Policy nonce for the generated <script> tag"
38+
39+ attr :csp_style_nonce , :string ,
40+ default: nil ,
41+ doc: "A Content-Security-Policy nonce for the generated <style> tag"
3442
3543 attr :ssr , :boolean ,
3644 default: true ,
@@ -87,17 +95,20 @@ defmodule LiveSvelte do
8795 end
8896 end
8997
98+ csp_attrs = if ( nonce = assigns . csp_nonce , do: [ nonce: nonce ] )
99+
90100 assigns =
91101 assign ( assigns ,
92- csp_attrs: if ( nonce = assigns [ :csp_nonce ] , do: [ nonce: nonce ] ) ,
102+ csp_script_attrs: csp_attrs || if ( nonce = assigns . csp_script_nonce , do: [ nonce: nonce ] ) ,
103+ csp_style_attrs: csp_attrs || if ( nonce = assigns . csp_style_nonce , do: [ nonce: nonce ] ) ,
93104 init: init ,
94105 slots: slots ,
95106 ssr_render: ssr_code
96107 )
97108
98109 ~H"""
99110 < . live_json live_json_props = { @ live_json_props } >
100- < script { @ csp_attrs } >
111+ < script { @ csp_script_attrs } >
101112 <%= raw ( @ ssr_render [ "head" ] ) %>
102113 </ script >
103114 < div
@@ -114,7 +125,7 @@ defmodule LiveSvelte do
114125 class = { @ class }
115126 >
116127 <%= raw ( @ ssr_render [ "head" ] ) %>
117- < style { @ csp_attrs } >
128+ < style { @ csp_style_attrs } >
118129 <%= raw ( @ ssr_render [ "css" ] [ "code" ] ) %>
119130 </ style >
120131 <%= raw ( @ ssr_render [ "html" ] ) %>
0 commit comments