Skip to content

Commit

Permalink
proprly clear viewHooks when destroying a hook
Browse files Browse the repository at this point in the history
Relates to: #3496
Fixes: #3623

In #3496, I cleared the hookId on the element in destroyed,
but the view's destroyHook function actually relied on the hookId to
clean up the view's viewHooks object. This would cause hooks' destroy
function to be called multiple times, as the view was not able to remove
old hooks.
  • Loading branch information
SteffenDE committed Jan 10, 2025
1 parent cc92bdd commit c6118e5
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 9 deletions.
5 changes: 4 additions & 1 deletion assets/js/phoenix_live_view/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,12 @@ export default class View {
}

destroyHook(hook){
// __destroyed clears the elementID from the hook, therefore
// we need to get it before calling __destroyed
const hookId = ViewHook.elementID(hook.el)
hook.__destroyed()
hook.__cleanup__()
delete this.viewHooks[ViewHook.elementID(hook.el)]
delete this.viewHooks[hookId]
}

applyPendingUpdates(){
Expand Down
3 changes: 2 additions & 1 deletion priv/static/phoenix_live_view.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions priv/static/phoenix_live_view.cjs.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion priv/static/phoenix_live_view.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions priv/static/phoenix_live_view.esm.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion priv/static/phoenix_live_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -3949,9 +3949,10 @@ removing illegal node: "${(childNode.outerHTML || childNode.nodeValue).trim()}"
}
}
destroyHook(hook) {
const hookId = ViewHook.elementID(hook.el);
hook.__destroyed();
hook.__cleanup__();
delete this.viewHooks[ViewHook.elementID(hook.el)];
delete this.viewHooks[hookId];
}
applyPendingUpdates() {
this.pendingDiffs.forEach(({ diff, events }) => this.update(diff, events));
Expand Down
2 changes: 1 addition & 1 deletion priv/static/phoenix_live_view.min.js

Large diffs are not rendered by default.

0 comments on commit c6118e5

Please sign in to comment.