@@ -149,6 +149,61 @@ runHydrationWidgetWithHeadAndBody switchoverAction app = withJSContextSingletonM
149149 flip runPostBuildT postBuild $ flip runTriggerEventT events $ app (hydrateDom $ toNode headElement) (hydrateDom $ toNode bodyElement)
150150 return postBuildTriggerRef
151151
152+{-# INLINABLE mainHydrationWidgetWithHeadImmediate #-}
153+-- | Warning: `mainHydrationWidgetWithHeadImmediate` is provided only as performance tweak. It is expected to disappear in future releases.
154+mainHydrationWidgetWithHeadImmediate :: HydrationWidget () () -> HydrationWidget () () -> JSM ()
155+mainHydrationWidgetWithHeadImmediate head' body = do
156+ runHydrationWidgetWithHeadAndBodyImmediate (pure ()) $ \appendHead appendBody -> do
157+ appendHead head'
158+ appendBody body
159+
160+{-# INLINABLE attachHydrationWidgetImmediate #-}
161+attachHydrationWidgetImmediate
162+ :: JSContextSingleton ()
163+ -> (EventChannel -> PerformEventT DomTimeline DomHost (IORef (Maybe (EventTrigger DomTimeline ()))))
164+ -> IO ()
165+attachHydrationWidgetImmediate jsSing w = do
166+ events <- newChan
167+ runDomHost $ flip runTriggerEventT events $ mdo
168+ (postBuildTriggerRef, fc@(FireCommand fire)) <- lift $ hostPerformEventT $ w events
169+ mPostBuildTrigger <- readRef postBuildTriggerRef
170+ lift $ forM_ mPostBuildTrigger $ \postBuildTrigger -> fire [postBuildTrigger :=> Identity ()] $ return ()
171+ liftIO $ processAsyncEvents events fc
172+
173+{-# INLINABLE runHydrationWidgetWithHeadAndBodyImmediate #-}
174+runHydrationWidgetWithHeadAndBodyImmediate
175+ :: IO ()
176+ -> ( (forall c. HydrationWidget () c -> FloatingWidget () c) -- "Append to head"
177+ -> (forall c. HydrationWidget () c -> FloatingWidget () c) -- "Append to body"
178+ -> FloatingWidget () ()
179+ )
180+ -> JSM ()
181+runHydrationWidgetWithHeadAndBodyImmediate switchoverAction app = withJSContextSingletonMono $ \jsSing -> do
182+ globalDoc <- currentDocumentUnchecked
183+ headElement <- getHeadUnchecked globalDoc
184+ bodyElement <- getBodyUnchecked globalDoc
185+ unreadyChildren <- liftIO $ newIORef 0
186+ hydrationMode <- liftIO $ newIORef HydrationMode_Immediate
187+ liftIO $ attachHydrationWidgetImmediate jsSing $ \events -> flip runWithJSContextSingleton jsSing $ do
188+ (postBuild, postBuildTriggerRef) <- newEventWithTriggerRef
189+ let hydrateDom :: DOM.Node -> HydrationWidget () c -> FloatingWidget () c
190+ hydrateDom n w = do
191+ events' <- TriggerEvent.askEvents
192+ parent <- liftIO $ newIORef $ toNode n
193+ lift $ do
194+ let builderEnv = HydrationDomBuilderEnv
195+ { _hydrationDomBuilderEnv_document = globalDoc
196+ , _hydrationDomBuilderEnv_parent = parent
197+ , _hydrationDomBuilderEnv_unreadyChildren = unreadyChildren
198+ , _hydrationDomBuilderEnv_commitAction = pure ()
199+ , _hydrationDomBuilderEnv_hydrationMode = hydrationMode
200+ , _hydrationDomBuilderEnv_switchover = never
201+ }
202+ (a, _res) <- runHydrationDomBuilderT w builderEnv events'
203+ pure a
204+ flip runPostBuildT postBuild $ flip runTriggerEventT events $ app (hydrateDom $ toNode headElement) (hydrateDom $ toNode bodyElement)
205+ return postBuildTriggerRef
206+
152207{-# INLINE mainWidget #-}
153208mainWidget :: (forall x. Widget x ()) -> JSM ()
154209mainWidget = mainWidget'
@@ -283,7 +338,6 @@ processAsyncEvents events (FireCommand fire) = void $ forkIO $ forever $ do
283338 liftIO $ forM_ ers $ \(_ :=> TriggerInvocation _ cb) -> cb
284339 return ()
285340
286−
287341-- | Run a reflex-dom application inside of an existing DOM element with the given ID
288342mainWidgetInElementById :: Text -> (forall x. Widget x ()) -> JSM ()
289343mainWidgetInElementById eid w = withJSContextSingleton $ \jsSing -> do