on develop help sign in
Skip hydration for elements with data-ssr attribute
98714b4Tom Smalley
reflex-dom-core/src/Reflex/Dom/Builder/Immediate.hs+12−5
@@ -765,10 +765,17 @@ hydrateElement elementTag cfg child = do
765 result <- HydrationDomBuilderT $ lift $ runReaderT (unHydrationDomBuilderT child) env'
765 result <- HydrationDomBuilderT $ lift $ runReaderT (unHydrationDomBuilderT child) env'
766 wrapResult <- liftIO newEmptyMVar
766 wrapResult <- liftIO newEmptyMVar
767 let skipAttr = "data-hydration-skip" :: DOM.JSString
767 let skipAttr = "data-hydration-skip" :: DOM.JSString
768+ ssrAttr = "data-ssr" :: DOM.JSString
768− hasSkipAttribute :: DOM.Element -> HydrationRunnerT t m Bool
769+ shouldSkip :: DOM.Element -> HydrationRunnerT t m Bool
769− hasSkipAttribute e = case cfg ^. namespace of
770+ shouldSkip e = case cfg ^. namespace of
771+ Nothing -> do
770− Nothing -> hasAttribute e skipAttr
772+ skip <- hasAttribute e skipAttr
773+ ssr <- hasAttribute e ssrAttr
774+ pure $ skip || not ssr
775+ Just ns -> do
771− Just ns -> hasAttributeNS e (Just ns) skipAttr
776+ skip <- hasAttributeNS e (Just ns) skipAttr
777+ ssr <- hasAttributeNS e (Just ns) ssrAttr
778+ pure $ skip || not ssr
772 childDom <- liftIO $ readIORef childDelayedRef
779 childDom <- liftIO $ readIORef childDelayedRef
773 let rawCfg = extractRawElementConfig cfg
780 let rawCfg = extractRawElementConfig cfg
774 doc <- askDocument
781 doc <- askDocument
@@ -783,7 +790,7 @@ hydrateElement elementTag cfg child = do
783 pure e
790 pure e
784 Just node -> DOM.castTo DOM.Element node >>= \case
791 Just node -> DOM.castTo DOM.Element node >>= \case
785 Nothing -> go (Just node) -- this node is not an element, skip
792 Nothing -> go (Just node) -- this node is not an element, skip
786− Just e -> hasSkipAttribute e >>= \case
793+ Just e -> shouldSkip e >>= \case
787 True -> go (Just node) -- this element is explicitly marked for being skipped by hydration
794 True -> go (Just node) -- this element is explicitly marked for being skipped by hydration
788 False -> do
795 False -> do
789 t <- Element.getTagName e
796 t <- Element.getTagName e