on develop help sign in
Merge pull request #358 from jhartzell42/jimmy/hydration-namespace-bug

Fix issue with namespaces in hydration

commite2a9716d37e9090e59503915263999fb566793e2 authorJohn Ericson <John.Ericson@Obsidian.Systems> dateTue 4 Feb 2020, 16:56 (7 years ago) parent27720c0218d582
4 files changed+18−11
cabal.project+1 reflex-dom-core/ChangeLog.md+2−1 reflex-dom-core/src/Reflex/Dom/Builder/Immediate.hs+5−10 reflex-dom-core/test/hydration.hs+10
cabal.projectnew file+1
@@ -0,0 +1 @@
1+packages: reflex-dom-core, reflex-dom
reflex-dom-core/ChangeLog.md+2−1
@@ -2,7 +2,8 @@
22
33## Unreleased
44
5−Support GHC 8.8.
5+* Support GHC 8.8.
6+* Fix attribute support for explicitly namespaced elements
67
78## 0.5.3
89
reflex-dom-core/src/Reflex/Dom/Builder/Immediate.hs+5−10
@@ -141,7 +141,7 @@ import Data.Text (Text)
141141import Foreign.JavaScript.Internal.Utils
142142import Foreign.JavaScript.TH
143143import GHCJS.DOM.Document (Document, createDocumentFragment, createElement, createElementNS, createTextNode, createComment)
144−import GHCJS.DOM.Element (getScrollTop, removeAttribute, removeAttributeNS, setAttribute, setAttributeNS, hasAttribute, hasAttributeNS)
144+import GHCJS.DOM.Element (getScrollTop, removeAttribute, removeAttributeNS, setAttribute, setAttributeNS, hasAttribute)
145145import GHCJS.DOM.EventM (EventM, event, on)
146146import GHCJS.DOM.KeyboardEvent as KeyboardEvent
147147import GHCJS.DOM.MouseEvent
@@ -767,15 +767,10 @@ hydrateElement elementTag cfg child = do
767767 let skipAttr = "data-hydration-skip" :: DOM.JSString
768768 ssrAttr = "data-ssr" :: DOM.JSString
769769 shouldSkip :: DOM.Element -> HydrationRunnerT t m Bool
770− shouldSkip e = case cfg ^. namespace of
771− Nothing -> do
772− skip <- hasAttribute e skipAttr
773− ssr <- hasAttribute e ssrAttr
774− pure $ skip || not ssr
775− Just ns -> do
776− skip <- hasAttributeNS e (Just ns) skipAttr
777− ssr <- hasAttributeNS e (Just ns) ssrAttr
778− pure $ skip || not ssr
770+ shouldSkip e = do
771+ skip <- hasAttribute e skipAttr
772+ ssr <- hasAttribute e ssrAttr
773+ pure $ skip || not ssr
779774 childDom <- liftIO $ readIORef childDelayedRef
780775 let rawCfg = extractRawElementConfig cfg
781776 doc <- askDocument
reflex-dom-core/test/hydration.hs+10
@@ -22,6 +22,7 @@
2222
2323import Prelude hiding (fail)
2424import Control.Concurrent
25+import Control.Lens.Operators
2526import Control.Monad hiding (fail)
2627import Control.Monad.Catch
2728import Control.Monad.Fail
@@ -770,6 +771,15 @@ tests withDebugging wdConfig caps _selenium = do
770771 prerender_ (pure ()) (liftIO $ trigger "Client")
771772 textNode $ TextNodeConfig "Initial" $ Just e
772773
774+ describe "namespaces" $ session' $ do
775+ it "dyn can be nested in namespaced widget" $ runWD $ do
776+ testWidget (pure ()) (checkTextInTag "svg" "one") $ do
777+ let svgRootCfg = def
778+ & (elementConfig_namespace ?~ "http://www.w3.org/2000/svg")
779+ & (elementConfig_initialAttributes .~ ("width" =: "100%" <> "height" =: "100%" <> "viewBox" =: "0 0 1536 2048"))
780+ void $ element "svg" svgRootCfg $ do
781+ dyn_ $ text "one" <$ pure ()
782+
773783 describe "runWithReplace" $ session' $ do
774784 it "works" $ runWD $ do
775785 replaceChan :: Chan Text <- liftIO newChan