Skip to content

Commit

Permalink
fix(avatar): check removed avatar node type (#1822)
Browse files Browse the repository at this point in the history
* fix(avatar): check removed avatar node type

* chore: update

---------

Co-authored-by: Segun Adebayo <[email protected]>
  • Loading branch information
healtheloper and segunadebayo authored Sep 5, 2024
1 parent b6033de commit 6d958b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/many-papayas-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zag-js/avatar": patch
---

Fix issues where avatar could throw when the fallback inner text changes.
4 changes: 3 additions & 1 deletion packages/machines/avatar/src/avatar.machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" })
}
Expand Down

0 comments on commit 6d958b3

Please sign in to comment.