on develop help sign in
Skip hydration for elements with data-ssr attribute
commit98714b4a763ba29e1f8799a1ca26887438f0c24f authorTom Smalley <tfsmalley@gmail.com> dateTue 20 Aug 2019, 16:51 (7 years ago) parent9a5972f
1 file changed+12−5
reflex-dom-core/src/Reflex/Dom/Builder/Immediate.hs+12−5
reflex-dom-core/src/Reflex/Dom/Builder/Immediate.hs+12−5
@@ -765,10 +765,17 @@ hydrateElement elementTag cfg child = do
765765 result <- HydrationDomBuilderT $ lift $ runReaderT (unHydrationDomBuilderT child) env'
766766 wrapResult <- liftIO newEmptyMVar
767767 let skipAttr = "data-hydration-skip" :: DOM.JSString
768− hasSkipAttribute :: DOM.Element -> HydrationRunnerT t m Bool
769− hasSkipAttribute e = case cfg ^. namespace of
770− Nothing -> hasAttribute e skipAttr
771− Just ns -> hasAttributeNS e (Just ns) skipAttr
768+ ssrAttr = "data-ssr" :: DOM.JSString
769+ 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
772779 childDom <- liftIO $ readIORef childDelayedRef
773780 let rawCfg = extractRawElementConfig cfg
774781 doc <- askDocument
@@ -783,7 +790,7 @@ hydrateElement elementTag cfg child = do
783790 pure e
784791 Just node -> DOM.castTo DOM.Element node >>= \case
785792 Nothing -> go (Just node) -- this node is not an element, skip
786− Just e -> hasSkipAttribute e >>= \case
793+ Just e -> shouldSkip e >>= \case
787794 True -> go (Just node) -- this element is explicitly marked for being skipped by hydration
788795 False -> do
789796 t <- Element.getTagName e