-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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 window.requestIdleCallback not firing on iOS #29895
Conversation
Base commit: c68c47d |
Base commit: c68c47d |
Wouldn't it be better to just revert #26114? I don't see the issue it tries to fix. It previously used NSTimeInterval frameElapsed = (CACurrentMediaTime() - update.timestamp); to calculate the frame time difference using the system clock and: NSTimeInterval currentTimestamp = [[NSDate date] timeIntervalSince1970];
NSNumber *absoluteFrameStartMS = @((currentTimestamp - frameElapsed) * 1000); to convert it to unix time. NSTimeInterval and CFTimeInterval are both double in seconds so they are compatible with each other. cc @aleclarson |
Reverting #26114 sounds good. I must have neglected due diligence on that one. 😥 |
I couldn’t tell what the previous change was trying to fix and just assumed that this bug was an unintended side effect. If that’s not the case then I agree that reverting it is a better course of action. |
Yea if reverting works I think it is better since I’d rather keep using the timestamp on the CADisplayLink |
That makes sense. Are one of you ok to open the revert PR or do you need me to do it? |
If you can do it and test that it actually fixes the issue that would be great. I can do it too, but don't have a test case for idle callback. |
@janicduplessis I've tested that reverting that fixes my issue by patching my React Native files after install. I've updated this PR to remove the changes I previously made and instead revert the changes made in #26114. This should be ready for review and merging. |
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.
Thanks! LGTM
Great job @matt-oakes 🎉 Isn't this a pretty critical bug that should be prioritized asap? What is the status of getting this merged and released? Best regards |
Is there any plan to merge this fix at all? |
Could you merge this? |
Hi @matt-oakes Do you think this MR is being downprioritized due to the failing CI test? Would it be possible for you to fix it? I can't really see what you've changed that can cause the test to fail, so maybe a rerun would fix it (I cannot rerun it, maybe you can?). |
@jenskuhrjorgensen I'm not sure why it hasn't been looked at, but I've rerun te tests just to make sure it's not that. Like you said, the tests shouldn't fail as nothing has been changed to break that, but if t fails again I will take another look. |
This was causing issues with the window.requestIdleCallback timers as the timer code was expecting this "timestamp" property to be a unix timestamp in seconds which was causing the calculations to be done incorrectly and for the callbacks to never be called. Fixes facebook#28602
cc @sammy-SC |
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
Hi @mdvacca Sorry for dragging you in to this ancient PR, but I can see that you are very active on this repo, and maybe you would take the time to go through this fairly small PR that fixes a feature that hasn't worked for almost 3 years now and is still present in the newest version of RN. Accordingly, we have a patch on RN that is also 3 years old now, containing the changes in this PR - and as with all other patches we would very much like to get rid of it. I hope you can help out by approving this PR or at least give all the interested parties here an explanation of why this feature is not meant to work. Best regards |
@sammy-SC has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Thanks for prompting @jenskuhrjorgensen and thanks for importing @sammy-SC 👍 I'd given up on this ever getting merged and just accepted I was always going to need to patch this. |
This pull request was successfully merged by @matt-oakes in 72abed2. When will my fix make it into a release? | Upcoming Releases |
thank you for the PR @matt-oakes! |
Summary
Fixes #28602
When creating a
RCTFrameUpdate
, ensure it is created with the correct unix timestamp in seconds. This is needed to match theNSTimeInterval
type defined in the header.Previously, it was using the
CADisplayLink
'stimestamp
property, which is not anNSTimeInterval
but is instead aCFTimeInterval
(note the different class prefix). This is the host time converted to seconds, which is the number of seconds since the device was turned on and therefore not a unix timestamp as expected.This was causing issues with the
window.requestIdleCallback
timers as the timer code was expecting thistimestamp
property to be a unix timestamp in seconds which was causing the calculations to be done incorrectly and for the callbacks to never be called. The code does this calculation is here:react-native/React/CoreModules/RCTTiming.mm
Line 262 in 4d920fe
As one of these is a valid unix timestamp and the other is a much smaller number (number of seconds since device turn on), the
if
statement following this calculation never passes and the callbacks are never called.This regression seems to have been introduced with this pull request: #26114
Changelog
[iOS] [Fixed] - Fixed window.requestIdleCallback not firing on iOS
Test Plan
I have tested this by patching my React Native code and testing that idle callbacks are correctly called. There is a reproduction case of the issue in the linked issue.