diff --git a/assets/js/phoenix_live_view/view.js b/assets/js/phoenix_live_view/view.js index f9b3b2e386..a839e06fe7 100644 --- a/assets/js/phoenix_live_view/view.js +++ b/assets/js/phoenix_live_view/view.js @@ -543,7 +543,7 @@ export default class View { !fromEl.isEqualNode(toEl) && !(isIgnored && isEqualObj(fromEl.dataset, toEl.dataset)) ) { - hook.__beforeUpdate(); + hook.__beforeUpdate(fromEl, toEl); return hook; } } diff --git a/assets/js/phoenix_live_view/view_hook.ts b/assets/js/phoenix_live_view/view_hook.ts index 1a3ce881bd..0c6ab4a83b 100644 --- a/assets/js/phoenix_live_view/view_hook.ts +++ b/assets/js/phoenix_live_view/view_hook.ts @@ -35,7 +35,7 @@ export interface HookInterface { * Called when the element is about to be updated in the DOM. * Note: any call here must be synchronous as the operation cannot be deferred or cancelled. */ - beforeUpdate?: () => void; + beforeUpdate?: (fromEl: E, toEl: E) => void; /** * The updated callback. @@ -173,7 +173,7 @@ export interface Hook { * Called when the element is about to be updated in the DOM. * Note: any call here must be synchronous as the operation cannot be deferred or cancelled. */ - beforeUpdate?: (this: T & HookInterface) => void; + beforeUpdate?: (this: T & HookInterface, fromEl: E, toEl: E) => void; /** * The updated callback. @@ -347,7 +347,7 @@ export class ViewHook // Default lifecycle methods mounted(): void {} - beforeUpdate(): void {} + beforeUpdate(_fromEl: E, _toEl: E): void {} updated(): void {} destroyed(): void {} disconnected(): void {} @@ -364,8 +364,8 @@ export class ViewHook this.updated(); } /** @internal */ - __beforeUpdate() { - this.beforeUpdate(); + __beforeUpdate(fromEl, toEl) { + this.beforeUpdate(fromEl, toEl); } /** @internal */ __destroyed() {