-
Notifications
You must be signed in to change notification settings - Fork 46.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix incorrect unmounted state update warning #18617
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -116,6 +116,7 @@ import { | |||||||
Snapshot, | ||||||||
Callback, | ||||||||
Passive, | ||||||||
PassiveUnmountPending, | ||||||||
Incomplete, | ||||||||
HostEffectMask, | ||||||||
Hydrating, | ||||||||
|
@@ -2310,6 +2311,15 @@ export function enqueuePendingPassiveHookEffectUnmount( | |||||||
): void { | ||||||||
if (runAllPassiveEffectDestroysBeforeCreates) { | ||||||||
pendingPassiveHookEffectsUnmount.push(effect, fiber); | ||||||||
if (__DEV__) { | ||||||||
if (deferPassiveEffectCleanupDuringUnmount) { | ||||||||
fiber.effectTag |= PassiveUnmountPending; | ||||||||
const alternate = fiber.alternate; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Can you pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could do that for But we also call Is this still the right change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like what we're calling "current" is inconsistent between For e.g. react/packages/react-reconciler/src/ReactFiberWorkLoop.new.js Lines 2192 to 2193 in cfefc81
But for
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also call Since this was a "nit" and given the above considerations, I think I'm not going to make any additional change to the alternate stuff for now. Seems like it would be a net loss. We can always follow up with another PR if someone disagrees strongly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right I guess “current” isn’t accurate, it’s just the “other fiber” Yeah that makes sense. If we got rid of alternates, each fiber would have a shared instance object and we could put the flag on that. |
||||||||
if (alternate !== null) { | ||||||||
alternate.effectTag |= PassiveUnmountPending; | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
if (!rootDoesHavePassiveEffects) { | ||||||||
rootDoesHavePassiveEffects = true; | ||||||||
scheduleCallback(NormalPriority, () => { | ||||||||
|
@@ -2372,6 +2382,17 @@ function flushPassiveEffectsImpl() { | |||||||
const fiber = ((unmountEffects[i + 1]: any): Fiber); | ||||||||
const destroy = effect.destroy; | ||||||||
effect.destroy = undefined; | ||||||||
|
||||||||
if (__DEV__) { | ||||||||
if (deferPassiveEffectCleanupDuringUnmount) { | ||||||||
fiber.effectTag &= ~PassiveUnmountPending; | ||||||||
const alternate = fiber.alternate; | ||||||||
if (alternate !== null) { | ||||||||
alternate.effectTag &= ~PassiveUnmountPending; | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
if (typeof destroy === 'function') { | ||||||||
if (__DEV__) { | ||||||||
setCurrentDebugFiberInDEV(fiber); | ||||||||
|
@@ -2851,7 +2872,7 @@ function warnAboutUpdateOnUnmountedFiberInDEV(fiber) { | |||||||
) { | ||||||||
// If there are pending passive effects unmounts for this Fiber, | ||||||||
// we can assume that they would have prevented this update. | ||||||||
if (pendingPassiveHookEffectsUnmount.indexOf(fiber) >= 0) { | ||||||||
if ((fiber.effectTag & PassiveUnmountPending) !== NoEffect) { | ||||||||
return; | ||||||||
} | ||||||||
} | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it weird to only set this bit in DEV mode? It's only needed there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add Dev suffix to the flag?