Teact: Fix textContent optimization
This commit is contained in:
parent
a2eb398feb
commit
7daee68c0e
24
src/components/test/TestSetContent.tsx
Normal file
24
src/components/test/TestSetContent.tsx
Normal file
@ -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 (
|
||||||
|
<div onClick={() => setWithFirstLine((current) => !current)}>
|
||||||
|
{withFirstLine && 'First line'}
|
||||||
|
<Text />
|
||||||
|
Last line
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default App;
|
||||||
@ -129,9 +129,12 @@ function renderWithVirtual<T extends VirtualElement | undefined>(
|
|||||||
|
|
||||||
mountChildren(parentEl, $new as VirtualElementComponent | VirtualElementFragment, { nextSibling, fragment });
|
mountChildren(parentEl, $new as VirtualElementComponent | VirtualElementFragment, { nextSibling, fragment });
|
||||||
} else {
|
} else {
|
||||||
const canSetTextContent = (
|
const canSetTextContent = !fragment
|
||||||
!fragment && !nextSibling && $newAsReal.type === VirtualType.Text && $parent.children.length === 1
|
&& !nextSibling
|
||||||
);
|
&& $newAsReal.type === VirtualType.Text
|
||||||
|
&& $parent.children.length === 1
|
||||||
|
&& !parentEl.firstChild;
|
||||||
|
|
||||||
if (canSetTextContent) {
|
if (canSetTextContent) {
|
||||||
parentEl.textContent = $newAsReal.value;
|
parentEl.textContent = $newAsReal.value;
|
||||||
$newAsReal.target = parentEl.firstChild!;
|
$newAsReal.target = parentEl.firstChild!;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user