Skip to content

Commit

Permalink
fix navigate callback running after patch
Browse files Browse the repository at this point in the history
  • Loading branch information
enewbury committed Jul 17, 2023
1 parent 13a1752 commit 32cf1a8
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions assets/js/phoenix_live_view/live_socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ export default class LiveSocket {
DOM.findPhxSticky(document).forEach(el => newMainEl.appendChild(el))
this.outgoingMainEl.replaceWith(newMainEl)
this.outgoingMainEl = null
callback && requestAnimationFrame(callback)
callback && requestAnimationFrame(() => callback(linkRef))
onDone()
})
}
Expand Down Expand Up @@ -775,10 +775,12 @@ export default class LiveSocket {
}
let scroll = window.scrollY
this.withPageLoading({to: href, kind: "redirect"}, done => {
this.replaceMain(href, flash, () => {
Browser.pushState(linkState, {type: "redirect", id: this.main.id, scroll: scroll}, href)
DOM.dispatchEvent(window, "phx:navigate", {detail: {href, patch: false, pop: false}})
this.registerNewLocation(window.location)
this.replaceMain(href, flash, (linkRef) => {
if(linkRef === this.linkRef){
Browser.pushState(linkState, {type: "redirect", id: this.main.id, scroll: scroll}, href)
DOM.dispatchEvent(window, "phx:navigate", {detail: {href, patch: false, pop: false}})
this.registerNewLocation(window.location)
}
done()
})
})
Expand Down

0 comments on commit 32cf1a8

Please sign in to comment.