Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions packages/react-reconciler/src/ReactFiberCommitEffects.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,10 @@ export function commitHookEffectListMount(
try {
const updateQueue: FunctionComponentUpdateQueue | null =
(finishedWork.updateQueue: any);
const lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
if (lastEffect !== null) {
const firstEffect = lastEffect.next;
let effect = firstEffect;
do {
const effects = updateQueue !== null ? updateQueue.effects : null;
if (effects !== null) {
for (let i = 0; i < effects.length; i++) {
const effect = effects[i];
if ((effect.tag & flags) === flags) {
if (enableSchedulingProfiler) {
if ((flags & HookPassive) !== NoHookEffect) {
Expand Down Expand Up @@ -237,8 +236,7 @@ export function commitHookEffectListMount(
}
}
}
effect = effect.next;
} while (effect !== firstEffect);
}
}
} catch (error) {
captureCommitPhaseError(finishedWork, finishedWork.return, error);
Expand All @@ -253,11 +251,10 @@ export function commitHookEffectListUnmount(
try {
const updateQueue: FunctionComponentUpdateQueue | null =
(finishedWork.updateQueue: any);
const lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
if (lastEffect !== null) {
const firstEffect = lastEffect.next;
let effect = firstEffect;
do {
const effects = updateQueue !== null ? updateQueue.effects : null;
if (effects !== null) {
for (let i = 0; i < effects.length; i++) {
const effect = effects[i];
if ((effect.tag & flags) === flags) {
// Unmount
const inst = effect.inst;
Expand Down Expand Up @@ -293,8 +290,7 @@ export function commitHookEffectListUnmount(
}
}
}
effect = effect.next;
} while (effect !== firstEffect);
}
}
} catch (error) {
captureCommitPhaseError(finishedWork, finishedWork.return, error);
Expand Down
21 changes: 7 additions & 14 deletions packages/react-reconciler/src/ReactFiberHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ export type Effect = {
inst: EffectInstance,
create: () => (() => void) | void,
deps: Array<mixed> | void | null,
next: Effect,
};

type StoreInstance<T> = {
Expand All @@ -245,7 +244,7 @@ type EventFunctionPayload<Args, Return, F: (...Array<Args>) => Return> = {
};

export type FunctionComponentUpdateQueue = {
lastEffect: Effect | null,
effects: Array<Effect> | null,
events: Array<EventFunctionPayload<any, any, any>> | null,
stores: Array<StoreConsistencyCheck<any>> | null,
memoCache: MemoCache | null,
Expand Down Expand Up @@ -1071,7 +1070,7 @@ function updateWorkInProgressHook(): Hook {

function createFunctionComponentUpdateQueue(): FunctionComponentUpdateQueue {
return {
lastEffect: null,
effects: null,
events: null,
stores: null,
memoCache: null,
Expand All @@ -1081,7 +1080,7 @@ function createFunctionComponentUpdateQueue(): FunctionComponentUpdateQueue {
function resetFunctionComponentUpdateQueue(
updateQueue: FunctionComponentUpdateQueue,
): void {
updateQueue.lastEffect = null;
updateQueue.effects = null;
updateQueue.events = null;
updateQueue.stores = null;
if (updateQueue.memoCache != null) {
Expand Down Expand Up @@ -2571,8 +2570,6 @@ function pushSimpleEffect(
create,
deps,
inst,
// Circular
next: (null: any),
};
return pushEffectImpl(effect);
}
Expand All @@ -2584,15 +2581,11 @@ function pushEffectImpl(effect: Effect): Effect {
componentUpdateQueue = createFunctionComponentUpdateQueue();
currentlyRenderingFiber.updateQueue = (componentUpdateQueue: any);
}
const lastEffect = componentUpdateQueue.lastEffect;
if (lastEffect === null) {
componentUpdateQueue.lastEffect = effect.next = effect;
} else {
const firstEffect = lastEffect.next;
lastEffect.next = effect;
effect.next = firstEffect;
componentUpdateQueue.lastEffect = effect;
let effects = componentUpdateQueue.effects;
if (effects === null) {
componentUpdateQueue.effects = effects = [];
}
effects.push(effect);
return effect;
}

Expand Down
Loading