Skip to content

Commit

Permalink
fix: avoid missing backend element on detached
Browse files Browse the repository at this point in the history
  • Loading branch information
Tidyzq committed Jan 29, 2024
1 parent 2e1ad61 commit d7977b5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion glass-easel/src/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,12 @@ export class Element implements NodeCast {
}

private static checkAndCallDetached(node: Node) {
const destroyQueue: Node[] = []

const callFunc = function callFunc(node: Node) {
if (node._$destroyOnDetach) {
node.destroyBackendElement()
// Destroy later to avoid missing backend elements
destroyQueue.push(node)
}
if (isElement(node) && node._$attached) {
if (isComponent(node)) {
Expand Down Expand Up @@ -530,6 +533,10 @@ export class Element implements NodeCast {
}
}
callFunc(node)

for (let i = 0; i < destroyQueue.length; i += 1) {
destroyQueue[i]!.destroyBackendElement()
}
}

private static checkAndCallMoved(node: Node) {
Expand Down

0 comments on commit d7977b5

Please sign in to comment.