@@ -12,6 +12,7 @@
1212module Obelisk.Frontend
1313 ( ObeliskWidget
1414 , Frontend (..)
15+ , HeadRender (..)
1516 , runFrontend
1617 , renderFrontendHtml
1718 ) where
@@ -67,9 +68,12 @@ type ObeliskWidget t x route m =
6768
6869data Frontend route = Frontend
6970 { _frontend_head :: !(forall t m x. ObeliskWidget t x route m => RoutedT t route m ())
71+ , _frontend_headRender :: HeadRender
7072 , _frontend_body :: !(forall t m x. ObeliskWidget t x route m => RoutedT t route m ())
7173 }
7274
75+data HeadRender = HeadRender_Static | HeadRender_Dynamic
76+
7377type Widget' x = ImmediateDomBuilderT DomTimeline (DomCoreWidget x)
7478
7579-- | A widget that isn't attached to any particular part of the DOM hierarchy
@@ -101,16 +105,16 @@ runWithHeadAndBody app = withJSContextSingletonMono $ \jsSing -> do
101105 headFragment <- createDocumentFragment globalDoc
102106 bodyFragment <- createDocumentFragment globalDoc
103107 unreadyChildren <- liftIO $ newIORef 0
104− let commit = do
108+ let commitHead = do
105109 headElement <- getHeadUnchecked globalDoc
110+ replaceElementContents headElement headFragment
111+ commitBody = do
106112 bodyElement <- getBodyUnchecked globalDoc
107− void $ inAnimationFrame' $ \_ -> do
108− replaceElementContents headElement headFragment
109− replaceElementContents bodyElement bodyFragment
113+ replaceElementContents bodyElement bodyFragment
110114 liftIO $ attachWidget''' $ \events -> flip runWithJSContextSingleton jsSing $ do
111115 (postBuild, postBuildTriggerRef) <- newEventWithTriggerRef
112− let appendImmediateDom :: DOM.DocumentFragment -> Widget' () c -> FloatingWidget () c
113− appendImmediateDom df w = do
116+ let appendImmediateDom :: JSM () -> DOM.DocumentFragment -> Widget' () c -> FloatingWidget () c
117+ appendImmediateDom commit df w = do
114118 events' <- TriggerEvent.askEvents
115119 lift $ do
116120 doc <- getOwnerDocumentUnchecked df
@@ -121,10 +125,10 @@ runWithHeadAndBody app = withJSContextSingletonMono $ \jsSing -> do
121125 , _immediateDomBuilderEnv_commitAction = commit
122126 }
123127 runImmediateDomBuilderT w builderEnv events'
124− flip runPostBuildT postBuild $ flip runTriggerEventT events $ app (appendImmediateDom headFragment) (appendImmediateDom bodyFragment)
125− liftIO (readIORef unreadyChildren) >>= \case
126− 0 -> DOM.liftJSM commit
127− _ -> return ()
128+ flip runPostBuildT postBuild $ flip runTriggerEventT events $ app (appendImmediateDom commitHead headFragment) (appendImmediateDom commitBody bodyFragment)
129+ -- liftIO (readIORef unreadyChildren) >>= \case
130+ -- 0 -> DOM.liftJSM commit
131+ -- _ -> return ()
128132 return postBuildTriggerRef
129133
130134runFrontend :: forall backendRoute route. Encoder Identity Identity (R (Sum backendRoute (ObeliskRoute route))) PageName -> Frontend (R route) -> JSM ()
@@ -146,7 +150,9 @@ runFrontend validFullEncoder frontend = do
146150 -> m a
147151 runMyRouteViewT = runRouteViewT ve
148152 runWithHeadAndBody $ \appendHead appendBody -> runMyRouteViewT $ do
149− mapRoutedT (mapSetRouteT appendHead) $ _frontend_head frontend
153+ case _frontend_headRender frontend of
154+ HeadRender_Dynamic -> mapRoutedT (mapSetRouteT appendHead) $ _frontend_head frontend
155+ HeadRender_Static -> return ()
150156 mapRoutedT (mapSetRouteT appendBody) $ _frontend_body frontend
151157
152158renderFrontendHtml