Skip to content

Commit

Permalink
wait for transitions before determining cids_destroyed
Browse files Browse the repository at this point in the history
Fixes #3139.
  • Loading branch information
SteffenDE committed May 19, 2024
1 parent 6ce0613 commit 22b9f29
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions assets/js/phoenix_live_view/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -1267,17 +1267,21 @@ export default class View {
willDestroyCIDs.forEach(cid => this.rendered.resetRender(cid))

this.pushWithReply(null, "cids_will_destroy", {cids: willDestroyCIDs}, () => {
// See if any of the cids we wanted to destroy were added back,
// if they were added back, we don't actually destroy them.
let completelyDestroyCIDs = willDestroyCIDs.filter(cid => {
return DOM.findComponentNodeList(this.el, cid).length === 0
})

if(completelyDestroyCIDs.length > 0){
this.pushWithReply(null, "cids_destroyed", {cids: completelyDestroyCIDs}, (resp) => {
this.rendered.pruneCIDs(resp.cids)
// we must wait for pending transitions to complete before determining
// if the cids were added back to the DOM in the meantime (#3139)
this.liveSocket.requestDOMUpdate(() => {
// See if any of the cids we wanted to destroy were added back,
// if they were added back, we don't actually destroy them.
let completelyDestroyCIDs = willDestroyCIDs.filter(cid => {
return DOM.findComponentNodeList(this.el, cid).length === 0
})
}

if(completelyDestroyCIDs.length > 0){
this.pushWithReply(null, "cids_destroyed", {cids: completelyDestroyCIDs}, (resp) => {
this.rendered.pruneCIDs(resp.cids)
})
}
})
})
}
}
Expand Down

0 comments on commit 22b9f29

Please sign in to comment.