-
Notifications
You must be signed in to change notification settings - Fork 740
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
Fixing Promise
race condition
#2220
Conversation
@@ -181,7 +183,7 @@ export const AnimatePresence: React.FunctionComponent< | |||
const insertionIndex = presentKeys.indexOf(key) | |||
|
|||
let exitingComponent = component | |||
if (!exitingComponent) { |
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.
This file is just Prettier
@@ -65,7 +65,6 @@ export function animateValue<V = number>({ | |||
* WAAPI-compatible behaviour. | |||
*/ | |||
const updateFinishedPromise = () => { | |||
resolveFinishedPromise && resolveFinishedPromise() |
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.
The comment above needs to be updated as well.
@@ -280,7 +280,7 @@ export function animateValue<V = number>({ | |||
playState = "finished" | |||
onComplete && onComplete() | |||
stopAnimationDriver() | |||
updateFinishedPromise() | |||
resolveFinishedPromise() |
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.
Could you elaborate a little more on the race condition? Why do we stop updating the finished promise in finish()
?
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.
For reasons slightly beyond my comprehension, but at least related to adding queueMicrotasks
(which is when Promises are resolved), swapping to a new Promise
as soon as we resolve the old one messes with Promise.all
- seemingly at random. As noted in Onne's linked ticket, even adding a console.log
can affect timings in a way that more consistently fixes the observed bug. So instead we swap to a new Promise
later - if and when we start a new animation.
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.
swapping to a new Promise as soon as we resolve the old one messes with Promise.all
Would it have the same impact when cancel()
is called?
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.
I haven't see a bug related to this but it's added there because it's been removed from updateFinishedPromise()
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.
Let's add a comment why we skip it in finish()
, I think it requires context to understand why the code is written this way.
i still have issues with exiting components in quick succession getting stuck, and never getting to the proper final component, unless i comment out all |
Fixes #2172
Fixes https://github.com/framer/company/issues/27486