on develop help sign in
Delete prerender markers too
79463a3Tom Smalley
reflex-dom-core/src/Reflex/Dom/Builder/Hydration.hs+18
@@ -40,6 +40,7 @@ module Reflex.Dom.Builder.Hydration
40 , DOM(..), runDOMForest
40 , DOM(..), runDOMForest
41 , hydrateDOM
41 , hydrateDOM
42 , hydrateNode
42 , hydrateNode
43+ , getPreviousNode, setPreviousNode
43 , runHydrationDomBuilderT
44 , runHydrationDomBuilderT
44 , askParent
45 , askParent
45 , askEvents
46 , askEvents
@@ -47,6 +48,8 @@ module Reflex.Dom.Builder.Hydration
47 , textNodeInternal
48 , textNodeInternal
48 , deleteBetweenExclusive
49 , deleteBetweenExclusive
49 , extractBetweenExclusive
50 , extractBetweenExclusive
51+ , deleteBetweenInclusive
52+ , extractBetweenInclusive
50 , deleteUpTo
53 , deleteUpTo
51 , extractUpTo
54 , extractUpTo
52 , SupportsHydrationDomBuilder
55 , SupportsHydrationDomBuilder
@@ -482,6 +485,21 @@ extractBetweenExclusive df s e = liftJSM $ do
482 f <- eval ("(function(df,s,e) { var x; for(;;) { x = s['nextSibling']; if(e===x) { break; }; df['appendChild'](x); } })" :: Text)
485 f <- eval ("(function(df,s,e) { var x; for(;;) { x = s['nextSibling']; if(e===x) { break; }; df['appendChild'](x); } })" :: Text)
483 void $ call f f (df, s, e)
486 void $ call f f (df, s, e)
484
487
488+-- | s and e must both be children of the same node and s must precede e;
489+-- all nodes between s and e will be removed, including s and e
490+deleteBetweenInclusive :: (MonadJSM m, IsNode start, IsNode end) => start -> end -> m ()
491+deleteBetweenInclusive s e = do
492+ df <- createDocumentFragment =<< getOwnerDocumentUnchecked s
493+ extractBetweenInclusive df s e -- In many places in HydrationDomBuilderT, we assume that things always have a parent; by adding them to this DocumentFragment, we maintain that invariant
494+
495+-- | s and e must both be children of the same node and s must precede e; all
496+-- nodes between s and e will be moved into the given DocumentFragment,
497+-- including s and e
498+extractBetweenInclusive :: (MonadJSM m, IsNode start, IsNode end) => DOM.DocumentFragment -> start -> end -> m ()
499+extractBetweenInclusive df s e = liftJSM $ do
500+ f <- eval ("(function(df,s,e) { var x = s; var next; for(;;) { next = x['nextSibling']; df['appendChild'](x); if(e===x) { break; }; x = next; } })" :: Text)
501+ void $ call f f (df, s, e)
502+
485-- | s and e must both be children of the same node and s must precede e;
503-- | s and e must both be children of the same node and s must precede e;
486-- s and all nodes between s and e will be removed, but e will not be removed
504-- s and all nodes between s and e will be removed, but e will not be removed
487{-# INLINABLE deleteUpTo #-}
505{-# INLINABLE deleteUpTo #-}
reflex-dom-core/src/Reflex/Dom/Prerender.hs+3−1
@@ -117,6 +117,7 @@ endMarker = "prerender/end"
117deleteToPrerenderEnd :: (MonadIO m, MonadJSM m) => HydrationRunnerT t m ()
117deleteToPrerenderEnd :: (MonadIO m, MonadJSM m) => HydrationRunnerT t m ()
118deleteToPrerenderEnd = do
118deleteToPrerenderEnd = do
119 depth <- liftIO $ newIORef 0
119 depth <- liftIO $ newIORef 0
120+ ref <- getPreviousNode
120 startNode <- hydrateNode (\e -> do
121 startNode <- hydrateNode (\e -> do
121 n :: DOM.JSString <- Element.getTagName e
122 n :: DOM.JSString <- Element.getTagName e
122 mt :: Maybe DOM.JSString <- Element.getAttribute e ("type" :: DOM.JSString)
123 mt :: Maybe DOM.JSString <- Element.getAttribute e ("type" :: DOM.JSString)
@@ -137,7 +138,8 @@ deleteToPrerenderEnd = do
137 pure False
138 pure False
138 _ -> pure False
139 _ -> pure False
139 pure $ n == "SCRIPT" && attrCheck) DOM.Element
140 pure $ n == "SCRIPT" && attrCheck) DOM.Element
140− deleteBetweenExclusive startNode endNode
141+ deleteBetweenInclusive startNode endNode
142+ setPreviousNode ref
141
143
142data NoJavaScript -- This type should never have a HasJS instance
144data NoJavaScript -- This type should never have a HasJS instance
143
145