Skip to content

Commit 2a13a98

Browse files
authored
warn if createHook el has no id (#4056)
Closes #4010. Closes #4035.
1 parent e3c1c3d commit 2a13a98

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

assets/js/phoenix_live_view/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import OriginalLiveSocket, { isUsedInput } from "./live_socket";
1010
import DOM from "./dom";
1111
import { ViewHook } from "./view_hook";
1212
import View from "./view";
13+
import { logError } from "./utils";
1314

1415
import type { LiveSocketJSCommands } from "./js_commands";
1516
import type { Hook, HooksOptions } from "./view_hook";
@@ -329,6 +330,13 @@ function createHook(el: HTMLElement, callbacks: Hook): ViewHook {
329330
return existingHook;
330331
}
331332

333+
if (!el.hasAttribute("id")) {
334+
logError(
335+
"Elements passed to createHook need to have a unique id attribute",
336+
el,
337+
);
338+
}
339+
332340
let hook = new ViewHook(View.closestView(el), el, callbacks);
333341
DOM.putCustomElHook(el, hook);
334342
return hook;

0 commit comments

Comments
 (0)