-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
[scheduler] Eagerly schedule rAF at beginning of frame #13785
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,17 +50,18 @@ describe('SchedulerDOM', () => { | |
function runRAFCallbacks() { | ||
startOfLatestFrame += frameSize; | ||
currentTime = startOfLatestFrame; | ||
rAFCallbacks.forEach(cb => cb()); | ||
const cbs = rAFCallbacks; | ||
rAFCallbacks = []; | ||
cbs.forEach(cb => cb()); | ||
} | ||
function advanceOneFrame(config: FrameTimeoutConfigType = {}) { | ||
runRAFCallbacks(); | ||
runPostMessageCallbacks(config); | ||
} | ||
|
||
let frameSize = 33; | ||
let startOfLatestFrame = Date.now(); | ||
let currentTime = Date.now(); | ||
let startOfLatestFrame = 0; | ||
let currentTime = 0; | ||
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. This is to make debugging easier. These tests use overridden |
||
|
||
beforeEach(() => { | ||
// TODO pull this into helper method, reduce repetition. | ||
|
@@ -109,6 +110,25 @@ describe('SchedulerDOM', () => { | |
expect(typeof cb.mock.calls[0][0].timeRemaining()).toBe('number'); | ||
}); | ||
|
||
it('inserts its rAF callback as early into the queue as possible', () => { | ||
const {unstable_scheduleCallback: scheduleCallback} = Scheduler; | ||
const log = []; | ||
const useRAFCallback = () => { | ||
log.push('userRAFCallback'); | ||
}; | ||
scheduleCallback(() => { | ||
// Call rAF while idle work is being flushed. | ||
requestAnimationFrame(useRAFCallback); | ||
}); | ||
advanceOneFrame({timeLeftInFrame: 1}); | ||
// There should be two callbacks: the one scheduled by Scheduler at the | ||
// beginning of the frame, and the one scheduled later during that frame. | ||
expect(rAFCallbacks.length).toBe(2); | ||
// The user callback should be the second callback. | ||
rAFCallbacks[1](); | ||
expect(log).toEqual(['userRAFCallback']); | ||
}); | ||
|
||
describe('with multiple callbacks', () => { | ||
it('accepts multiple callbacks and calls within frame when not blocked', () => { | ||
const {unstable_scheduleCallback: scheduleCallback} = Scheduler; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We can now unify these checks so we can get rid of this flag and just use
scheduledCallback
as the flag.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 thought this would work but now I don't think it does. There are three callbacks: the one scheduled with
requestAnimationFrame
(represented byisAnimationFrameScheduled
), themessage
event handler (represented byisIdleScheduled
), and the one that actually contains the work (scheduledCallback
). Need all three concepts. For example, as added by this PR, sometimes an animation frame is scheduled even if there's no actual work scheduled. So I think all three are needed.I'll rename these a bit so it's less confusing.