on develop help sign in
Merge pull request #317 from reflex-frp/cg-hydration-fixes

Hydration fixes

commitadeee9dda8ab7253481c09414d169dac1ad027e3 authorAli Abrar <aliabrar@gmail.com> dateFri 14 Jun 2019, 21:10 (7 years ago) parent36647b728fef25
8 files changed+32−28
reflex-dom-core/ChangeLog.md+9 reflex-dom-core/default.nix+1−1 reflex-dom-core/reflex-dom-core.cabal+8−8 reflex-dom-core/src/Reflex/Dom/Builder/Immediate.hs+8−8 reflex-dom-core/test/hydration.hs−7 reflex-dom/ChangeLog.md+2 reflex-dom/default.nix+1−1 reflex-dom/reflex-dom.cabal+3−3
reflex-dom-core/ChangeLog.md+9
@@ -1,5 +1,14 @@
11# Revision history for reflex-dom-core
22
3+## 0.5.2
4+
5+* Update to use new dependent-sum/map packages and drop dependency on `*Tag` classes (e.g., `ShowTag`).
6+
7+## 0.5.1
8+
9+* Added support for marking elements with a "data-skip-hydration" attribute, which will cause hydration to ignore and skip over them.
10+* Removed "data-ssr" attributes from statically rendered output.:q
11+
312## 0.5
413
514* Add HydrationDomBuilderT to support hydration of statically rendered DOM nodes. See the note at the top of Reflex.Dom.Builder.Immediate.
reflex-dom-core/default.nix+1−1
@@ -25,7 +25,7 @@ let addGcTestDepends = drv: if (stdenv.system != "x86_64-linux" || stdenv.hostPl
2525 };
2626in mkDerivation (addGcTestDepends {
2727 pname = "reflex-dom-core";
28− version = "0.5";
28+ version = "0.5.2";
2929 src = ./.;
3030 libraryHaskellDepends = [
3131 aeson base bifunctors bimap blaze-builder bytestring constraints
reflex-dom-core/reflex-dom-core.cabal+8−8
@@ -1,5 +1,5 @@
11Name: reflex-dom-core
2−Version: 0.5
2+Version: 0.5.2.0
33Synopsis: Functional Reactive Web Apps with Reflex
44Description: Reflex-DOM is a Functional Reactive web framework based on the Reflex FRP engine
55License: BSD3
@@ -52,9 +52,9 @@ library
5252 constraints >= 0.9 && < 0.11,
5353 contravariant >= 1.4 && < 1.6,
5454 data-default >= 0.5 && < 0.8,
55− dependent-map >= 0.2 && < 0.4,
56− dependent-sum >= 0.3 && < 0.7,
57− dependent-sum-template >= 0.0.0.4 && < 0.2,
55+ dependent-map >= 0.3 && < 0.4,
56+ dependent-sum >= 0.6 && < 0.7,
57+ dependent-sum-template >= 0.1 && < 0.2,
5858 directory >= 1.2 && < 1.4,
5959 exception-transformers == 0.4.*,
6060 ghcjs-dom >= 0.9.1.0 && < 0.10,
@@ -67,7 +67,7 @@ library
6767 primitive >= 0.5 && < 0.7,
6868 random,
6969 ref-tf == 0.4.*,
70− reflex == 0.6.*,
70+ reflex >= 0.6.2,
7171 semigroups >= 0.16 && < 0.19,
7272 stm == 2.4.*,
7373 text == 1.2.*,
@@ -133,8 +133,8 @@ library
133133
134134 if flag(use-template-haskell)
135135 build-depends:
136− dependent-sum >= 0.3 && < 0.7,
137− dependent-sum-template >= 0.0.0.5 && < 0.2,
136+ dependent-sum >= 0.6,
137+ dependent-sum-template >= 0.1 && < 0.2,
138138 template-haskell
139139 other-extensions: TemplateHaskell
140140 cpp-options: -DUSE_TEMPLATE_HASKELL
@@ -142,7 +142,7 @@ library
142142 Reflex.Dom.Builder.Class.TH
143143 else
144144 build-depends:
145− dependent-sum == 0.4.*
145+ dependent-sum == 0.6.*
146146
147147test-suite hlint
148148 build-depends: base, hlint
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
@@ -270,13 +270,6 @@ tests withDebugging wdConfig caps _selenium = do
270270 (e, ()) <- element "div" conf $ text "hello world"
271271 let click = domEvent Click e
272272 return ()
273− -- TODO check this is the correct solution
274− it "has ssr attribute, removes ssr attribute" $ runWD $ do
275− let checkSSRAttr = do
276− e <- findElemWithRetry $ WD.ByTag "div"
277− assertAttr e "data-ssr" (Just "")
278− pure e
279− testWidget' checkSSRAttr (\e -> assertAttr e "data-ssr" Nothing) $ el "div" $ text "hello world"
280273
281274 describe "inputElement" $ do
282275 describe "hydration" $ session' $ do
reflex-dom/ChangeLog.md+2
@@ -1,5 +1,7 @@
11# Revision history for reflex-dom
22
3+## 0.5.1
4+
35* The default jsaddle backend on macOS when built from nix
46 is now jsaddle-wkwebview, matching the behaviour of cabal
57 builds.
reflex-dom/default.nix+1−1
@@ -11,7 +11,7 @@ let isAndroid = hostPlatform.libc == "bionic";
1111 }.${ghcBackend};
1212in mkDerivation {
1313 pname = "reflex-dom";
14− version = "0.5";
14+ version = "0.5.2";
1515 src = builtins.filterSource (path: type: !(builtins.elem (baseNameOf path) [ ".git" "dist" ])) ./.;
1616 libraryHaskellDepends = [
1717 base bytestring reflex reflex-dom-core text
reflex-dom/reflex-dom.cabal+3−3
@@ -1,5 +1,5 @@
11Name: reflex-dom
2−Version: 0.5
2+Version: 0.5.2
33Synopsis: Functional Reactive Web Apps with Reflex
44Description:
55 Reflex-DOM is a Functional Reactive web framework based on the Reflex FRP engine.
@@ -64,8 +64,8 @@ library
6464 build-depends:
6565 base >= 4.7 && < 4.12,
6666 bytestring == 0.10.*,
67− reflex == 0.6.*,
68− reflex-dom-core >=0.5 && <0.6,
67+ reflex >= 0.6.2,
68+ reflex-dom-core >=0.5.2 && <0.6,
6969 text == 1.2.*
7070 if !impl(ghcjs)
7171 if flag(use-warp) && (os(linux) || os(osx))