Skip to content

Commit

Permalink
Preserve other hisory.state properties when storing the viewmodel on …
Browse files Browse the repository at this point in the history
…page unload
  • Loading branch information
exyi committed Aug 17, 2024
1 parent 1e6ac4a commit 94319f6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Framework/Framework/Resources/Scripts/dotvvm-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function getStateManager(): StateManager<RootViewModel> { return getCoreS
let initialViewModelWrapper: any;

function isBackForwardNavigation() {
return (performance.getEntriesByType("navigation").at(-1) as PerformanceNavigationTiming)?.type == "back_forward";
return (performance.getEntriesByType?.("navigation").at(-1) as PerformanceNavigationTiming)?.type == "back_forward";
}

export function initCore(culture: string): void {
Expand Down Expand Up @@ -131,8 +131,10 @@ const getViewModelStorageElement = () =>
<HTMLInputElement>document.getElementById("__dot_viewmodel_root")

function persistViewModel() {
const viewModel = getState()
history.replaceState({ viewModel: { ...initialViewModelWrapper, viewModel } }, "")
history.replaceState({
...history.state,
viewModel: { ...initialViewModelWrapper, viewModel: getState() }
}, "")
// avoid storing the viewmodel hidden field, as Firefox would also reuse it on page reloads
getViewModelStorageElement()?.remove()
}

0 comments on commit 94319f6

Please sign in to comment.