Teact: Fix effects in portals
This commit is contained in:
parent
a49374a666
commit
62271f6ced
@ -18,8 +18,7 @@ import {
|
||||
renderComponent,
|
||||
unmountComponent,
|
||||
isFragmentElement,
|
||||
runImmediateEffects,
|
||||
willRunImmediateEffects,
|
||||
captureImmediateEffects,
|
||||
} from './teact';
|
||||
import { DEBUG } from '../../config';
|
||||
import { addEventListener, removeAllDelegatedListeners, removeEventListener } from './dom-events';
|
||||
@ -55,12 +54,10 @@ function render($element: VirtualElement | undefined, parentEl: HTMLElement) {
|
||||
headsByElement.set(parentEl, { children: [] });
|
||||
}
|
||||
|
||||
const runImmediateEffects = captureImmediateEffects();
|
||||
const $head = headsByElement.get(parentEl)!;
|
||||
const $newElement = renderWithVirtual(parentEl, $head.children[0], $element, $head, 0);
|
||||
|
||||
if (!willRunImmediateEffects()) {
|
||||
runImmediateEffects();
|
||||
}
|
||||
runImmediateEffects?.();
|
||||
|
||||
$head.children = $newElement ? [$newElement] : [];
|
||||
|
||||
|
||||
@ -309,7 +309,7 @@ let pendingEffects = new Map<string, Effect>();
|
||||
let pendingCleanups = new Map<string, EffectCleanup>();
|
||||
let pendingLayoutEffects = new Map<string, Effect>();
|
||||
let pendingLayoutCleanups = new Map<string, EffectCleanup>();
|
||||
let areImmediateEffectsPending = false;
|
||||
let areImmediateEffectsCaptured = false;
|
||||
|
||||
/*
|
||||
Order:
|
||||
@ -325,7 +325,7 @@ let areImmediateEffectsPending = false;
|
||||
*/
|
||||
|
||||
const runUpdatePassOnRaf = throttleWith(requestMeasure, () => {
|
||||
areImmediateEffectsPending = true;
|
||||
const runImmediateEffects = captureImmediateEffects();
|
||||
|
||||
idsToExcludeFromUpdate = new Set();
|
||||
const instancesToUpdate = Array
|
||||
@ -351,16 +351,20 @@ const runUpdatePassOnRaf = throttleWith(requestMeasure, () => {
|
||||
forceUpdateComponent(instance);
|
||||
});
|
||||
|
||||
areImmediateEffectsPending = false;
|
||||
runImmediateEffects();
|
||||
runImmediateEffects?.();
|
||||
});
|
||||
});
|
||||
|
||||
export function willRunImmediateEffects() {
|
||||
return areImmediateEffectsPending;
|
||||
export function captureImmediateEffects() {
|
||||
if (areImmediateEffectsCaptured) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
areImmediateEffectsCaptured = true;
|
||||
return runCapturedImmediateEffects;
|
||||
}
|
||||
|
||||
export function runImmediateEffects() {
|
||||
function runCapturedImmediateEffects() {
|
||||
const currentLayoutCleanups = pendingLayoutCleanups;
|
||||
pendingLayoutCleanups = new Map();
|
||||
currentLayoutCleanups.forEach((cb) => cb());
|
||||
@ -368,6 +372,8 @@ export function runImmediateEffects() {
|
||||
const currentLayoutEffects = pendingLayoutEffects;
|
||||
pendingLayoutEffects = new Map();
|
||||
currentLayoutEffects.forEach((cb) => cb());
|
||||
|
||||
areImmediateEffectsCaptured = false;
|
||||
}
|
||||
|
||||
export function renderComponent(componentInstance: ComponentInstance) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user