@@ -118,7 +118,9 @@ and [<AbstractClass>]
118118
119119 let mutable oldModel = None
120120 let mutable view = Node( fun _ _ s -> s)
121+ #if ! NET9_ 0_ OR_ GREATER
121122 let mutable runProgramLoop = fun () -> ()
123+ #endif
122124 let mutable dispatch = ignore< 'msg>
123125 let mutable program = Unchecked.defaultof< Program< 'model, 'msg>>
124126 let mutable router = None : option< IRouter< 'model, 'msg>>
@@ -194,9 +196,52 @@ and [<AbstractClass>]
194196 with _ -> () // fails if run in prerender
195197 )
196198
199+ #if NET9_ 0_ OR_ GREATER
200+ override this.OnInitializedAsync () =
201+ program <- this.Program
202+ let initModel , initCmd = Program.init program this
203+ view <- Program.view program initModel ( fun cmd -> dispatch cmd)
204+ oldModel <- Some initModel
205+ let isInteractive = this.RendererInfo.IsInteractive
206+
207+ task {
208+ if isInteractive then
209+ let setDispatch d =
210+ dispatch <- d
211+
212+ setState <- fun model dispatch ->
213+ match oldModel with
214+ | Some oldModel when this.ShouldRender( oldModel, model) -> this.ForceSetState( model, dispatch)
215+ | _ -> ()
216+
217+ match this.StreamingInit with
218+ | None ->
219+ program <-
220+ program
221+ |> Program.map
222+ ( fun _ _ -> initModel, setDispatch :: initCmd)
223+ id id
224+ ( fun _ model dispatch -> setState model dispatch)
225+ id id
226+
227+ | Some streamInit ->
228+ let! streamedModel , streamedCmd = streamInit initModel
229+ view <- Program.view program streamedModel ( fun cmd -> dispatch cmd)
230+ oldModel <- Some streamedModel
231+ program <-
232+ program
233+ |> Program.map
234+ ( fun _ _ -> streamedModel, setDispatch :: initCmd @ streamedCmd)
235+ id id
236+ ( fun _ model dispatch -> setState model dispatch)
237+ id id
238+ }
239+
240+ #else
197241 override this.OnInitializedAsync () =
198242 let setDispatch d =
199243 dispatch <- d
244+
200245 program <-
201246 this.Program
202247 |> Program.map
@@ -222,6 +267,7 @@ and [<AbstractClass>]
222267 let! model , cmd = init initModel
223268 updateInitState model cmd
224269 }
270+ #endif
225271
226272 member val internal StreamingInit : ( 'model -> Task < 'model * Cmd < 'msg >>) option = None with get, set
227273
@@ -245,7 +291,11 @@ and [<AbstractClass>]
245291 override this.OnAfterRenderAsync ( firstRender ) =
246292 task {
247293 if firstRender then
294+ #if NET9_ 0_ OR_ GREATER
295+ Program.runWith this program
296+ #else
248297 runProgramLoop()
298+ #endif
249299 if router.IsSome then
250300 do ! this.NavigationInterception.EnableNavigationInterceptionAsync()
251301
0 commit comments