diff --git a/src/components/test/TestSetContent.tsx b/src/components/test/TestSetContent.tsx
new file mode 100644
index 000000000..61c2e71ae
--- /dev/null
+++ b/src/components/test/TestSetContent.tsx
@@ -0,0 +1,24 @@
+import type { FC } from '../../lib/teact/teact';
+import React, { useState } from '../../lib/teact/teact';
+
+// 1. Make sure "First line" is rendered even if followed by a component with single text.
+// 2. Make sure it then can be normally removed (target is preserved).
+// 3. Make sure "Last line" is also rendered.
+
+const Text: FC = () => {
+ return 'text component';
+};
+
+export function App() {
+ const [withFirstLine, setWithFirstLine] = useState(true);
+
+ return (
+
setWithFirstLine((current) => !current)}>
+ {withFirstLine && 'First line'}
+
+ Last line
+
+ );
+}
+
+export default App;
diff --git a/src/lib/teact/teact-dom.ts b/src/lib/teact/teact-dom.ts
index 6370f5efd..99dd0ca0b 100644
--- a/src/lib/teact/teact-dom.ts
+++ b/src/lib/teact/teact-dom.ts
@@ -129,9 +129,12 @@ function renderWithVirtual(
mountChildren(parentEl, $new as VirtualElementComponent | VirtualElementFragment, { nextSibling, fragment });
} else {
- const canSetTextContent = (
- !fragment && !nextSibling && $newAsReal.type === VirtualType.Text && $parent.children.length === 1
- );
+ const canSetTextContent = !fragment
+ && !nextSibling
+ && $newAsReal.type === VirtualType.Text
+ && $parent.children.length === 1
+ && !parentEl.firstChild;
+
if (canSetTextContent) {
parentEl.textContent = $newAsReal.value;
$newAsReal.target = parentEl.firstChild!;