diff --git a/src/lib/teact/teact-dom.ts b/src/lib/teact/teact-dom.ts index 9e440d6c6..df6c1f6cc 100644 --- a/src/lib/teact/teact-dom.ts +++ b/src/lib/teact/teact-dom.ts @@ -299,10 +299,10 @@ export function unmountRealTree($element: VirtualElement) { if (isTagElement($element)) { if ($element.target) { removeAllDelegatedListeners($element.target as HTMLElement); - } - if ($element.props.ref) { - $element.props.ref.current = undefined; // Help GC + if ($element.props.ref?.current === $element.target) { + $element.props.ref.current = undefined; + } } }