-
Notifications
You must be signed in to change notification settings - Fork 50.1k
[Fiber] Change work priority to represent the priority of the child #8716
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
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
40d9404
Change pendingWorkPriority to represent the priority of the child
acdlite aabcaa6
Ensure effects are reused when bailing out on the child
acdlite 02a32fc
When a boundary fails, set pendingWorkPriority to TaskPriority
acdlite a0c62aa
Ensure that priority is not dropped from a progressed subtree
acdlite d6a9c05
Fix mistake in sCU test
acdlite 865c452
Add failing test for bailing out on already completed work
acdlite 3032674
Don't reset work priority when resuming on progressed child
acdlite 32ab4b5
Fix reuseChildrenEffects to include effects on the fiber itself
acdlite 700296d
Remove outdated TODO
acdlite be824d1
Apply performUnitOfWork changes to performFailedUnitOfWork, too
acdlite 55366f8
Run test script
acdlite 2ce2a4b
Don't transfer side-effects to parent unless priority matches
acdlite d073460
Polyfill requestIdleCallback when native is not available
sebmarkbage 739281e
Update progressed priority when cloning
acdlite 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| /** | ||
| * Copyright 2013-present, Facebook, Inc. | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the BSD-style license found in the | ||
| * LICENSE file in the root directory of this source tree. An additional grant | ||
| * of patent rights can be found in the PATENTS file in the same directory. | ||
| * | ||
| * @providesModule ReactDOMFrameScheduling | ||
| * @flow | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| // This a built-in polyfill for requestIdleCallback. It works by scheduling | ||
| // a requestAnimationFrame, store the time for the start of the frame, then | ||
| // schedule a postMessage which gets scheduled after paint. Within the | ||
| // postMessage handler do as much work as possible until time + frame rate. | ||
| // By separating the idle call into a separate event tick we ensure that | ||
| // layout, paint and other browser work is counted against the available time. | ||
| // The frame rate is dynamically adjusted. | ||
|
|
||
| import type { Deadline } from 'ReactFiberReconciler'; | ||
|
|
||
| var invariant = require('invariant'); | ||
|
|
||
| // TODO: There's no way to cancel these, because Fiber doesn't atm. | ||
| let rAF : (callback : (time : number) => void) => number; | ||
| let rIC : (callback : (deadline : Deadline) => void) => number; | ||
| if (typeof requestAnimationFrame !== 'function') { | ||
| invariant( | ||
| false, | ||
| 'React depends on requestAnimationFrame. Make sure that you load a ' + | ||
| 'polyfill in older browsers.' | ||
| ); | ||
| } else if (typeof requestIdleCallback !== 'function') { | ||
| // Wrap requestAnimationFrame and polyfill requestIdleCallback. | ||
|
|
||
| var scheduledRAFCallback = null; | ||
| var scheduledRICCallback = null; | ||
|
|
||
| var isIdleScheduled = false; | ||
| var isAnimationFrameScheduled = false; | ||
|
|
||
| var frameDeadline = 0; | ||
| // We start out assuming that we run at 30fps but then the heuristic tracking | ||
| // will adjust this value to a faster fps if we get more frequent animation | ||
| // frames. | ||
| var previousFrameTime = 33; | ||
| var activeFrameTime = 33; | ||
|
|
||
| var frameDeadlineObject = { | ||
| timeRemaining: ( | ||
| typeof performance === 'object' && | ||
| typeof performance.now === 'function' ? function() { | ||
| // We assume that if we have a performance timer that the rAF callback | ||
| // gets a performance timer value. Not sure if this is always true. | ||
| return frameDeadline - performance.now(); | ||
| } : function() { | ||
| // As a fallback we use Date.now. | ||
| return frameDeadline - Date.now(); | ||
| } | ||
| ), | ||
| }; | ||
|
|
||
| // We use the postMessage trick to defer idle work until after the repaint. | ||
| var messageKey = | ||
| '__reactIdleCallback$' + Math.random().toString(36).slice(2); | ||
| var idleTick = function(event) { | ||
| if (event.source !== window || event.data !== messageKey) { | ||
| return; | ||
| } | ||
| isIdleScheduled = false; | ||
| var callback = scheduledRICCallback; | ||
| scheduledRICCallback = null; | ||
| if (callback) { | ||
| callback(frameDeadlineObject); | ||
| } | ||
| }; | ||
| // Assumes that we have addEventListener in this environment. Might need | ||
| // something better for old IE. | ||
| window.addEventListener('message', idleTick, false); | ||
|
|
||
| var animationTick = function(rafTime) { | ||
| isAnimationFrameScheduled = false; | ||
| var nextFrameTime = rafTime - frameDeadline + activeFrameTime; | ||
| if (nextFrameTime < activeFrameTime && previousFrameTime < activeFrameTime) { | ||
| if (nextFrameTime < 8) { | ||
| // Defensive coding. We don't support higher frame rates than 120hz. | ||
| // If we get lower than that, it is probably a bug. | ||
| nextFrameTime = 8; | ||
| } | ||
| // If one frame goes long, then the next one can be short to catch up. | ||
| // If two frames are short in a row, then that's an indication that we | ||
| // actually have a higher frame rate than what we're currently optimizing. | ||
| // We adjust our heuristic dynamically accordingly. For example, if we're | ||
| // running on 120hz display or 90hz VR display. | ||
| // Take the max of the two in case one of them was an anomaly due to | ||
| // missed frame deadlines. | ||
| activeFrameTime = nextFrameTime < previousFrameTime ? | ||
| previousFrameTime : nextFrameTime; | ||
| } else { | ||
| previousFrameTime = nextFrameTime; | ||
| } | ||
| frameDeadline = rafTime + activeFrameTime; | ||
| if (!isIdleScheduled) { | ||
| isIdleScheduled = true; | ||
| window.postMessage(messageKey, '*'); | ||
| } | ||
| var callback = scheduledRAFCallback; | ||
| scheduledRAFCallback = null; | ||
| if (callback) { | ||
| callback(rafTime); | ||
| } | ||
| }; | ||
|
|
||
| rAF = function(callback : (time : number) => void) : number { | ||
| // This assumes that we only schedule one callback at a time because that's | ||
| // how Fiber uses it. | ||
| scheduledRAFCallback = callback; | ||
| if (!isAnimationFrameScheduled) { | ||
| // If rIC didn't already schedule one, we need to schedule a frame. | ||
| isAnimationFrameScheduled = true; | ||
| requestAnimationFrame(animationTick); | ||
| } | ||
| return 0; | ||
| }; | ||
|
|
||
| rIC = function(callback : (deadline : Deadline) => void) : number { | ||
| // This assumes that we only schedule one callback at a time because that's | ||
| // how Fiber uses it. | ||
| scheduledRICCallback = callback; | ||
| if (!isAnimationFrameScheduled) { | ||
| // If rAF didn't already schedule one, we need to schedule a frame. | ||
| // TODO: If this rAF doesn't materialize because the browser throttles, we | ||
| // might want to still have setTimeout trigger rIC as a backup to ensure | ||
| // that we keep performing work. | ||
| isAnimationFrameScheduled = true; | ||
| requestAnimationFrame(animationTick); | ||
| } | ||
| return 0; | ||
| }; | ||
| } else { | ||
| rAF = requestAnimationFrame; | ||
| rIC = requestIdleCallback; | ||
| } | ||
|
|
||
| exports.rAF = rAF; | ||
| exports.rIC = rIC; | ||
Oops, something went wrong.
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.
Is it safe to assume this module isn’t relevant for server rendering?
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.
Fiber DOM renderer is client-only so no, it's not relevant.