Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed May 12, 2024
1 parent 9210982 commit bbb131e
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions vike/client/client-routing-runtime/installClientRouter.ts
Expand Up @@ -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 <a> 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 <a> links
onLinkClick()
function initHistoryAndScroll() {
setupNativeScrollRestoration()
initHistoryState()
autoSaveScrollPosition()
monkeyPatchHistoryPushState()
// Handle back-/forward navigation
onBrowserHistoryNavigation()

// Only for full stack straces
await promise
}

0 comments on commit bbb131e

Please sign in to comment.