Teact: Fix missing layout effects after first render

This commit is contained in:
Alexander Zinchuk 2023-04-15 13:51:22 +02:00
parent a11ef0f618
commit ad9e1bb9a1
2 changed files with 9 additions and 1 deletions

View File

@ -18,6 +18,7 @@ import {
renderComponent,
unmountComponent,
isFragmentElement,
runImmediateEffects,
} from './teact';
import { DEBUG } from '../../config';
import { addEventListener, removeAllDelegatedListeners, removeEventListener } from './dom-events';
@ -55,6 +56,9 @@ function render($element: VirtualElement | undefined, parentEl: HTMLElement) {
const $head = headsByElement.get(parentEl)!;
const $newElement = renderWithVirtual(parentEl, $head.children[0], $element, $head, 0);
queueMicrotask(runImmediateEffects);
$head.children = $newElement ? [$newElement] : [];
if (process.env.APP_ENV === 'perf') {

View File

@ -335,6 +335,10 @@ const runUpdatePassOnRaf = throttleWithRafFallback(() => {
forceUpdateComponent(instance);
});
runImmediateEffects();
});
export function runImmediateEffects() {
const currentLayoutCleanups = pendingLayoutCleanups;
pendingLayoutCleanups = new Map();
currentLayoutCleanups.forEach((cb) => cb());
@ -342,7 +346,7 @@ const runUpdatePassOnRaf = throttleWithRafFallback(() => {
const currentLayoutEffects = pendingLayoutEffects;
pendingLayoutEffects = new Map();
currentLayoutEffects.forEach((cb) => cb());
});
}
function scheduleUpdate(componentInstance: ComponentInstance) {
instancesPendingUpdate.add(componentInstance);