diff --git a/vike/client/client-routing-runtime/installClientRouter.ts b/vike/client/client-routing-runtime/installClientRouter.ts
index 1572503b90..818d68cfaf 100644
--- a/vike/client/client-routing-runtime/installClientRouter.ts
+++ b/vike/client/client-routing-runtime/installClientRouter.ts
@@ -9,25 +9,35 @@ import { setupNativeScrollRestoration } from './scrollRestoration.js'
import { autoSaveScrollPosition } from './setScrollPosition.js'
async function installClientRouter() {
- setupNativeScrollRestoration()
- initHistoryState()
- autoSaveScrollPosition()
- monkeyPatchHistoryPushState()
+ // Init navigation history and scroll restoration
+ initHistoryAndScroll()
+
+ // Render initial page
+ const renderPromise = render()
+
+ // Intercept clicks
+ onLinkClick()
+
+ // Preserve stack track
+ await renderPromise
+}
- // First initial render
+function render() {
assert(getRenderCount() === 0)
- const promise = renderPageClientSide({
+ const renderPromise = renderPageClientSide({
scrollTarget: 'preserve-scroll',
isBackwardNavigation: null,
isClientSideNavigation: false
})
assert(getRenderCount() === 1)
+ return renderPromise
+}
- // Intercept links
- onLinkClick()
+function initHistoryAndScroll() {
+ setupNativeScrollRestoration()
+ initHistoryState()
+ autoSaveScrollPosition()
+ monkeyPatchHistoryPushState()
// Handle back-/forward navigation
onBrowserHistoryNavigation()
-
- // Only for full stack straces
- await promise
}