Skip to content

Commit

Permalink
better usage of the callback, only call immediately if preserveUrl is…
Browse files Browse the repository at this point in the history
… true
  • Loading branch information
Smef committed Dec 14, 2024
1 parent d536f22 commit 90dff75
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/core/src/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ class CurrentPage {
replace = replace || isSameUrlWithoutHash(hrefToUrl(page.url), location)

return new Promise((resolve) => {
replace ? history.replaceState(page) : history.pushState(page)
resolve(null)
// resolve the promise in the callback, but if history.preserveUrl is true we need to resolve it immediately
// since the callback will never be called
replace ? history.replaceState(page, () => resolve(null)) : history.pushState(page, () => resolve(null))
if (history.preserveUrl) {
resolve(null)
}
}).then(() => {
const isNewComponent = !this.isTheSame(page)

Expand Down

0 comments on commit 90dff75

Please sign in to comment.