From 49b9d02dc51b5f462800808980aa04765f485215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Denuzi=C3=A8re?= Date: Sat, 18 Nov 2023 14:11:25 +0100 Subject: [PATCH] fix hash scrolling on first render --- src/Bolero/Components.fs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/Bolero/Components.fs b/src/Bolero/Components.fs index c9a26e45..8c943540 100644 --- a/src/Bolero/Components.fs +++ b/src/Bolero/Components.fs @@ -231,22 +231,19 @@ and [] | None -> initModel, [] override this.OnAfterRenderAsync(firstRender) = - if firstRender then - runProgramLoop() - if router.IsSome then - this.NavigationInterception.EnableNavigationInterceptionAsync() - else - Task.CompletedTask - else + task { + if firstRender then + runProgramLoop() + if router.IsSome then + do! this.NavigationInterception.EnableNavigationInterceptionAsync() + match routeHash with - | None -> - Task.CompletedTask + | None -> () | Some h -> routeHash <- None - task { - let! elt = this.JSRuntime.InvokeAsync("document.getElementById", h) - return! elt.InvokeVoidAsync("scrollIntoView") - } + let! elt = this.JSRuntime.InvokeAsync("document.getElementById", h) + return! elt.InvokeVoidAsync("scrollIntoView") + } override this.Render() = view