on develop help sign in
Added support for data-hydration-skip attribute, removed data-ssr.
commit9bd809bc00f88834f23b427e3d2adc0cb0fb09b1 authorCale Gibbard <cgibbard@gmail.com> dateThu 13 Jun 2019, 21:54 (7 years ago) parent83cb62d
3 files changed+13−15
reflex-dom-core/ChangeLog.md+5 reflex-dom-core/src/Reflex/Dom/Builder/Immediate.hs+8−8 reflex-dom-core/test/hydration.hs−7
reflex-dom-core/ChangeLog.md+5
@@ -1,5 +1,10 @@
11# Revision history for reflex-dom-core
22
3+## Unreleased
4+
5+* Added support for marking elements with a "data-skip-hydration" attribute, which will cause hydration to ignore and skip over them.
6+* Removed "data-ssr" attributes from statically rendered output.:q
7+
38## 0.5
49
510* Add HydrationDomBuilderT to support hydration of statically rendered DOM nodes. See the note at the top of Reflex.Dom.Builder.Immediate.
reflex-dom-core/src/Reflex/Dom/Builder/Immediate.hs+8−8
@@ -764,11 +764,11 @@ hydrateElement elementTag cfg child = do
764764 }
765765 result <- HydrationDomBuilderT $ lift $ runReaderT (unHydrationDomBuilderT child) env'
766766 wrapResult <- liftIO newEmptyMVar
767− let ssrAttr = "data-ssr" :: DOM.JSString
768− hasSSRAttribute :: DOM.Element -> HydrationRunnerT t m Bool
769− hasSSRAttribute e = case cfg ^. namespace of
770− Nothing -> hasAttribute e ssrAttr <* removeAttribute e ssrAttr
771− Just ns -> hasAttributeNS e (Just ns) ssrAttr <* removeAttributeNS e (Just ns) ssrAttr
767+ 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
772772 childDom <- liftIO $ readIORef childDelayedRef
773773 let rawCfg = extractRawElementConfig cfg
774774 doc <- askDocument
@@ -783,9 +783,9 @@ hydrateElement elementTag cfg child = do
783783 pure e
784784 Just node -> DOM.castTo DOM.Element node >>= \case
785785 Nothing -> go (Just node) -- this node is not an element, skip
786− Just e -> hasSSRAttribute e >>= \case
787− False -> go (Just node) -- this element was not added by the static renderer, skip
788− True -> do
786+ Just e -> hasSkipAttribute e >>= \case
787+ True -> go (Just node) -- this element is explicitly marked for being skipped by hydration
788+ False -> do
789789 t <- Element.getTagName e
790790 -- TODO: check attributes?
791791 if T.toCaseFold elementTag == T.toCaseFold t
reflex-dom-core/test/hydration.hs−7
@@ -280,13 +280,6 @@ tests withDebugging wdConfig caps _selenium = do
280280 (e, ()) <- element "div" conf $ text "hello world"
281281 let click = domEvent Click e
282282 return ()
283− -- TODO check this is the correct solution
284− it "has ssr attribute, removes ssr attribute" $ runWD $ do
285− let checkSSRAttr = do
286− e <- findElemWithRetry $ WD.ByTag "div"
287− assertAttr e "data-ssr" (Just "")
288− pure e
289− testWidget' checkSSRAttr (\e -> assertAttr e "data-ssr" Nothing) $ el "div" $ text "hello world"
290283
291284 describe "inputElement" $ do
292285 describe "hydration" $ session' $ do