Skip to content

Commit

Permalink
Merge branch 'cm-cleanup-pruning'
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord committed Feb 19, 2024
2 parents b52c1c5 + 5fcf422 commit 668dcbe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
3 changes: 3 additions & 0 deletions assets/js/phoenix_live_view/rendered.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ export default class Rendered {
// Both optimization flows apply here. newRender is set based on the onlyCids optimization, and
// we track a deterministic magicId based on the cid.
//
// changeTracking is about the entire tree
// newRender is about the current root in the tree
//
// By default changeTracking is enabled, but we special case the flow where the client is pruning
// cids and the server adds the component back. In such cases, we explicitly disable changeTracking
// with resetRender for this cid, then re-enable it after the recursive call to skip the optimization
Expand Down
8 changes: 2 additions & 6 deletions assets/js/phoenix_live_view/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export default class View {
this.childJoins = 0
this.loaderTimer = null
this.pendingDiffs = []
this.pruningCIDs = []
this.redirect = false
this.href = null
this.joinCount = this.parent ? this.parent.joinCount - 1 : 0
Expand Down Expand Up @@ -559,7 +558,7 @@ export default class View {
let tag = this.el.tagName
// Don't skip any component in the diff nor any marked as pruned
// (as they may have been added back)
let cids = diff ? this.rendered.componentCIDs(diff).concat(this.pruningCIDs) : null
let cids = diff ? this.rendered.componentCIDs(diff) : null
let [html, streams] = this.rendered.toString(cids)
return [`<${tag}>${html}</${tag}>`, streams]
})
Expand Down Expand Up @@ -1186,11 +1185,9 @@ export default class View {
}

maybePushComponentsDestroyed(destroyedCIDs){
let willDestroyCIDs = destroyedCIDs.concat(this.pruningCIDs).filter(cid => {
let willDestroyCIDs = destroyedCIDs.filter(cid => {
return DOM.findComponentNodeList(this.el, cid).length === 0
})
// make sure this is a copy and not a reference
this.pruningCIDs = willDestroyCIDs.concat([])

if(willDestroyCIDs.length > 0){
// we must reset the render change tracking for cids that
Expand All @@ -1206,7 +1203,6 @@ export default class View {

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

0 comments on commit 668dcbe

Please sign in to comment.