diff --git a/.changeset/many-papayas-clap.md b/.changeset/many-papayas-clap.md new file mode 100644 index 0000000000..1553f982a3 --- /dev/null +++ b/.changeset/many-papayas-clap.md @@ -0,0 +1,5 @@ +--- +"@zag-js/avatar": patch +--- + +Fix issues where avatar could throw when the fallback inner text changes. diff --git a/packages/machines/avatar/src/avatar.machine.ts b/packages/machines/avatar/src/avatar.machine.ts index d5c0988a41..6b5e68990c 100644 --- a/packages/machines/avatar/src/avatar.machine.ts +++ b/packages/machines/avatar/src/avatar.machine.ts @@ -74,7 +74,9 @@ export function machine(userContext: UserDefinedContext) { return observeChildren(rootEl, { callback(records) { const removedNodes = Array.from(records[0].removedNodes) as HTMLElement[] - const removed = removedNodes.find((node) => node.matches("[data-scope=avatar][data-part=image]")) + const removed = removedNodes.find( + (node) => node.nodeType === Node.ELEMENT_NODE && node.matches("[data-scope=avatar][data-part=image]"), + ) if (removed) { send({ type: "IMG.UNMOUNT" }) }