When adding x-ref like this to a div and loading the page, I get an Uncaught TypeError: root is undefined.
<div x-ref="commandview">
Alpine version 3.13.5.
That's the line in question:
// packages/alpinejs/src/directives/x-ref.js
function handler3() {
}
handler3.inline = (el, { expression }, { cleanup: cleanup2 }) => {
let root = closestRoot(el);
if (!root._x_refs) // error happens here
root._x_refs = {};
root._x_refs[expression] = el;
cleanup2(() => delete root._x_refs[expression]);
};
directive("ref", handler3);
Just found this issue comment on GitHub:
By adding
x-datalike this to an parent element of thedivI got it to work as expected: