Skip to content

Commit 4832063

Browse files
authored
Ensure root is set early (#4184)
Closes #4177. When a child view was removed from the DOM in between in joining and receving the join callback, we'd fail to mark it as destroyed, because destroyViewByEl uses the root id for lookup. This meant that the child view crashed when trying to attach to the element.
1 parent eac9958 commit 4832063

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

assets/js/phoenix_live_view/view.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ export default class View {
110110
// bind the view to the element
111111
DOM.putPrivate(this.el, "view", this);
112112
this.id = this.el.id;
113+
// destroyViewByEl requires the root set, so we need to set it early
114+
// otherwise it could happen that we try to apply a join result for a
115+
// view whose DOM node was already removed
116+
// See https://github.com/phoenixframework/phoenix_live_view/issues/4177.
117+
this.el.setAttribute(PHX_ROOT_ID, this.root.id);
113118
this.ref = 0;
114119
this.lastAckRef = null;
115120
this.childJoins = 0;

0 commit comments

Comments
 (0)