Skip to content

Commit

Permalink
fail early when hook element is not owned by view
Browse files Browse the repository at this point in the history
Fixes #3530.
  • Loading branch information
SteffenDE committed Jan 26, 2025
1 parent 552c3fe commit d7f0df5
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion assets/js/phoenix_live_view/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,9 @@ export default class View {
addHook(el){
let hookElId = ViewHook.elementID(el)

// only ever try to add hooks to elements owned by this view
if(el.getAttribute && !this.ownsElement(el)){ return }

if(hookElId && !this.viewHooks[hookElId]){
// hook created, but not attached (createHook for web component)
let hook = DOM.getCustomElHook(el) || logError(`no hook found for custom element: ${el.id}`)
Expand All @@ -710,7 +713,6 @@ export default class View {
} else {
// new hook found with phx-hook attribute
let hookName = el.getAttribute(`data-phx-${PHX_HOOK}`) || el.getAttribute(this.binding(PHX_HOOK))
if(hookName && !this.ownsElement(el)){ return }
let callbacks = this.liveSocket.getHookCallbacks(hookName)

if(callbacks){
Expand Down

0 comments on commit d7f0df5

Please sign in to comment.