diff --git a/assets/js/phoenix_live_view/view.js b/assets/js/phoenix_live_view/view.js index 6b9fe4ce7..5514471ab 100644 --- a/assets/js/phoenix_live_view/view.js +++ b/assets/js/phoenix_live_view/view.js @@ -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(){ diff --git a/assets/test/view_test.js b/assets/test/view_test.js index dd1ee1144..bfd5e4b08 100644 --- a/assets/test/view_test.js +++ b/assets/test/view_test.js @@ -832,6 +832,7 @@ describe("View Hooks", function(){ liveview_version }) expect(view.el.firstChild.innerHTML).toBe("TEST MOUNT") + expect(Object.keys(view.viewHooks)).toHaveLength(1) view.update({ s: ["

test update

"], @@ -849,6 +850,7 @@ describe("View Hooks", function(){ view.update({s: ["
"], fingerprint: 123}, []) expect(upcaseWasDestroyed).toBe(true) expect(hookLiveSocket).toBeDefined() + expect(Object.keys(view.viewHooks)).toEqual([]) }) test("createHook", (done) => {