From d1e4fd485ba1dd4d97c2b02f59d2732100486ce8 Mon Sep 17 00:00:00 2001 From: Jezen Thomas Date: Mon, 26 Aug 2019 12:03:53 +0200 Subject: [PATCH] Make `jsAttributesHandler` use `jsAttributes` This addresses this comment: https://github.com/yesodweb/yesod/pull/1622#discussion_r317467498 --- yesod-core/src/Yesod/Core/Class/Yesod.hs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/yesod-core/src/Yesod/Core/Class/Yesod.hs b/yesod-core/src/Yesod/Core/Class/Yesod.hs index b6886c70..fde5d476 100644 --- a/yesod-core/src/Yesod/Core/Class/Yesod.hs +++ b/yesod-core/src/Yesod/Core/Class/Yesod.hs @@ -252,13 +252,12 @@ class RenderRoute site => Yesod site where -- | Same as @jsAttributes@ but allows you to run arbitrary Handler code -- -- This is useful if you need to add a randomised nonce value to the script - -- tag generated by @widgetFile@. If you use both this function and - -- @jsAttributes@, the two attribute maps will be merged, favouring the - -- keys from @jsAttributes@ in case of a collision. + -- tag generated by @widgetFile@. If this function is overridden then + -- @jsAttributes@ is ignored. -- -- @since 1.6.16 jsAttributesHandler :: HandlerFor site [(Text, Text)] - jsAttributesHandler = pure [] + jsAttributesHandler = getYesod >>= return . jsAttributes -- | Create a session backend. Returning 'Nothing' disables -- sessions. If you'd like to change the way that the session @@ -532,7 +531,7 @@ widgetToPageContent :: Yesod site => WidgetFor site () -> HandlerFor site (PageContent (Route site)) widgetToPageContent w = do - jsAttrsFromHandler <- jsAttributesHandler + jsAttrs <- jsAttributesHandler HandlerFor $ \hd -> do master <- unHandlerFor getYesod hd ref <- newIORef mempty @@ -544,10 +543,6 @@ widgetToPageContent w = do let title = maybe mempty unTitle mTitle scripts = runUniqueList scripts' stylesheets = runUniqueList stylesheets' - jsAttrs = - let jsAttrsStatic = Map.fromList (jsAttributes master) - jsAttrsDynamic = Map.fromList jsAttrsFromHandler - in Map.toList $ Map.union jsAttrsStatic jsAttrsDynamic flip unHandlerFor hd $ do render <- getUrlRenderParams