Skip to content

Commit

Permalink
minor refactor: rename initHistoryState => enhanceHistoryState
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Oct 14, 2024
1 parent 9df2fff commit 7a68c18
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions vike/client/client-routing-runtime/history.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export {
initHistoryState,
enhanceHistoryState,
getHistoryState,
pushHistory,
type ScrollPosition,
Expand Down Expand Up @@ -31,7 +31,7 @@ type StateNotInitialized =
// - The very first render
// - The user's code runs `location.hash = '#section'`
// - The user clicks on an anchor link `<a href="#section">Section</a>` (Vike's `initOnLinkClick()` handler skips hash links).
function initHistoryState() {
function enhanceHistoryState() {
const stateNotInitialized: StateNotInitialized = window.history.state

const stateVikeEnhanced = enhanceState(stateNotInitialized)
Expand Down
4 changes: 2 additions & 2 deletions vike/client/client-routing-runtime/initClientRouter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { initClientRouter }

import { assert } from './utils.js'
import { initHistoryState, monkeyPatchHistoryPushState } from './history.js'
import { enhanceHistoryState, monkeyPatchHistoryPushState } from './history.js'
import { getRenderCount, renderPageClientSide } from './renderPageClientSide.js'
import { onBrowserHistoryNavigation } from './onBrowserHistoryNavigation.js'
import { initOnLinkClick } from './initOnLinkClick.js'
Expand Down Expand Up @@ -37,7 +37,7 @@ async function renderFirstPage() {

function initHistoryAndScroll() {
setupNativeScrollRestoration()
initHistoryState()
enhanceHistoryState()
autoSaveScrollPosition()
monkeyPatchHistoryPushState()
// Handle back-/forward navigation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export { onBrowserHistoryNavigation }
export { updateState }

import { getCurrentUrl, getGlobalObject } from './utils.js'
import { initHistoryState, getHistoryState } from './history.js'
import { enhanceHistoryState, getHistoryState } from './history.js'
import { renderPageClientSide } from './renderPageClientSide.js'
import { type ScrollTarget, setScrollPosition } from './setScrollPosition.js'

Expand Down Expand Up @@ -47,8 +47,8 @@ function onBrowserHistoryNavigation() {
// - Specification: https://html.spec.whatwg.org/multipage/history.html#the-history-interface
// - https://stackoverflow.com/questions/70188241/history-scrollrestoration-manual-doesnt-prevent-safari-from-restoring-scrol
if (window.history.state === null) {
// The browser already scrolled to `#${hash}` => the current scroll position is the right one => we save it with `initHistoryState()`.
initHistoryState()
// The browser already scrolled to `#${hash}` => the current scroll position is the right one => we save it with `enhanceHistoryState()`.
enhanceHistoryState()
globalObject.previousState = getState()
} else {
// If `history.state !== null` then it means that `popstate` was triggered by the user clicking on his browser's forward/backward history button.
Expand Down

0 comments on commit 7a68c18

Please sign in to comment.