@@ -671,7 +671,11 @@ commentNodeInternal !t mSetContents = getHydrationMode >>= \case
671671
672672-- | We leave markers in the static builder as comments, and rip these comments
673673-- out at hydration time, replacing them with empty text nodes.
674−skipToAndReplaceComment :: (MonadJSM m, Reflex t, MonadFix m) => Text -> IORef Text -> HydrationDomBuilderT t m (HydrationRunnerT t m (), IORef DOM.Text, IORef Text)
674+skipToAndReplaceComment
675+ :: (MonadJSM m, Reflex t, MonadFix m)
676+ => Text
677+ -> IORef Text
678+ -> HydrationDomBuilderT t m (HydrationRunnerT t m (), IORef DOM.Text, IORef Text)
675679skipToAndReplaceComment prefix key0Ref = getHydrationMode >>= \case
676680 HydrationMode_Immediate -> do
677681 -- If we're in immediate mode, we don't try to replace an existing comment,
@@ -691,8 +695,6 @@ skipToAndReplaceComment prefix key0Ref = getHydrationMode >>= \case
691695 DOM.castTo DOM.Comment node >>= \case
692696 Just comment -> do
693697 commentText <- Node.getTextContentUnchecked comment
694− liftIO $ putStr $ T.unpack $ "[" <> prefix <> "]"
695− liftIO $ putStr $ T.unpack $ "{" <> commentText <> "}"
696698 case T.stripPrefix (prefix <> key0) commentText of
697699 Just key -> do
698700 -- Replace the comment with an (invisible) text node
@@ -708,17 +710,13 @@ skipToAndReplaceComment prefix key0Ref = getHydrationMode >>= \case
708710 go key0 (Just node)
709711 switchComment = do
710712 key0 <- liftIO $ readIORef key0Ref
711− liftIO $ putStrLn $ "///////////////////////////////// switchComment " <> T.unpack key0
712713 (textNode, key) <- go key0 =<< getPreviousNode
713− liftIO $ putStrLn $ T.unpack key
714714 setPreviousNode $ Just $ toNode textNode
715715 liftIO $ do
716716 writeIORef textNodeRef textNode
717717 writeIORef keyRef key
718−-- hydrateDOM $ DOM_Node switchComment
719718 pure (switchComment, textNodeRef, keyRef)
720719
721−
722720skipToReplaceStart :: (MonadJSM m, Reflex t, MonadFix m) => HydrationDomBuilderT t m (HydrationRunnerT t m (), IORef DOM.Text, IORef Text)
723721skipToReplaceStart = skipToAndReplaceComment "replace-start" =<< liftIO (newIORef "")
724722
@@ -913,10 +911,8 @@ instance (Reflex t, Monad m, Adjustable t m, MonadHold t m, MonadFix m) => Adjus
913911instance (Reflex t, Adjustable t m, MonadJSM m, MonadHold t m, MonadFix m, PrimMonad m, Ref m ~ IORef, PerformEvent t m, MonadReflexCreateTrigger t m, MonadJSM (Performable m), MonadRef m) => Adjustable t (HydrationDomBuilderT t m) where
914912 {-# INLINABLE runWithReplace #-}
915913 runWithReplace a0 a' = do
916− liftIO $ putStrLn "In runWithReplace"
917914 initialEnv <- HydrationDomBuilderT ask
918915 let hydrating = _hydrationDomBuilderEnv_hydrationMode initialEnv
919− initialHydrationMode <- liftIO $ readIORef hydrating
920916 (hydrateStart, before, beforeKey) <- skipToReplaceStart
921917 let parentUnreadyChildren = _hydrationDomBuilderEnv_unreadyChildren initialEnv
922918 haveEverBeenReady <- liftIO $ newIORef False
@@ -935,7 +931,6 @@ instance (Reflex t, Adjustable t m, MonadJSM m, MonadHold t m, MonadFix m, PrimM
935931 parent <- getParent
936932 (hydrateEnd, after) <- skipToReplaceEnd beforeKey
937933 let drawInitialChild = do
938− liftIO $ putStrLn "drawInitialChild"
939934 p <- liftIO (readIORef hydrating) >>= \case
940935 HydrationMode_Hydrating -> liftIO $ newIORef parent
941936 HydrationMode_Immediate -> liftIO . newIORef . toNode =<< createDocumentFragment doc
@@ -948,10 +943,9 @@ instance (Reflex t, Adjustable t m, MonadJSM m, MonadHold t m, MonadFix m, PrimM
948943 liftIO $ readIORef unreadyChildren >>= \case
949944 0 -> writeIORef haveEverBeenReady True
950945 _ -> modifyIORef' parentUnreadyChildren succ
951− liftIO $ putStrLn "drawInitialChild: end"
952946 return (dom, result)
953947 a'' <- numberOccurrences a'
954− (result0, evt) <- HydrationDomBuilderT $ lift $ lift $ runWithReplace drawInitialChild $ ffor a'' $ \(cohortId, child) -> do
948+ ((hydrate0, result0), child') <- HydrationDomBuilderT $ lift $ lift $ runWithReplace drawInitialChild $ ffor a'' $ \(cohortId, child) -> do
955949 h <- liftIO $ readIORef hydrating
956950 p' <- case h of
957951 HydrationMode_Hydrating -> pure parent
@@ -959,11 +953,10 @@ instance (Reflex t, Adjustable t m, MonadJSM m, MonadHold t m, MonadFix m, PrimM
959953 p <- liftIO $ newIORef p'
960954 unreadyChildren <- liftIO $ newIORef 0
961955 let commitAction = do
962− liftIO $ putStrLn "Committing runWithReplace update"
963956 c <- liftIO $ readIORef currentCohort
964− !before' <- liftIO $ readIORef before
965− !after' <- liftIO $ readIORef after
966957 when (c <= cohortId) $ do -- If a newer cohort has already been committed, just ignore this
958+ !before' <- liftIO $ readIORef before
959+ !after' <- liftIO $ readIORef after
967960 deleteBetweenExclusive before' after'
968961 insertBefore p' after'
969962 liftIO $ writeIORef currentCohort cohortId
@@ -983,11 +976,10 @@ instance (Reflex t, Adjustable t m, MonadJSM m, MonadHold t m, MonadFix m, PrimM
983976 HydrationMode_Hydrating -> Left dom
984977 HydrationMode_Immediate -> Right commitActionToRunNow
985978 return (actions, result)
986− let (hydrationAction, commitAction) = fanEither $ fmap fst evt
987− base :: Behavior t [DOM t m] <- hold (fst result0) hydrationAction
988− hydrateDOM $ DOM_Replace hydrateStart hydrateEnd base
979+ let (hydrate', commitAction) = fanEither $ fmap fst child'
980+ hydrateDOM . DOM_Replace hydrateStart hydrateEnd =<< hold hydrate0 hydrate'
989981 requestDomAction_ $ fmapMaybe id commitAction
990− return (snd result0, fmap snd evt)
982+ return (result0, snd <$> child')
991983
992984 {-# INLINABLE traverseIntMapWithKeyWithAdjust #-}
993985 traverseIntMapWithKeyWithAdjust = traverseIntMapWithKeyWithAdjust'