-
Notifications
You must be signed in to change notification settings - Fork 47k
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
[Fiber] Use synchronous scheduling by default #8127
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ab92097
Ensure first iteration of performAnimationWork loop has right priority
acdlite a07f5ee
Synchronous work
acdlite 7b9ae92
Updates should use the same priority context as top-level render
acdlite 78aef38
Add config to enable sync scheduling by default
acdlite ecf468e
Batch nested updates when in sync mode
acdlite d153b1e
Enqueue update and callback simultaneously
acdlite b41883f
unstable_batchedUpdates
acdlite 2e5e88c
Don't need defaultPriorityContext
acdlite 26731ea
unstable_batchedUpdates should return value of callback
acdlite 3121e05
At the end of a batch, perform any sync work that was scheduled
acdlite da45010
Remove first-class function
acdlite 2182b69
batchedUpdates tests
acdlite c3ab541
New effect type: Callback
acdlite 95084be
Fix lint by removing unneeded type import
gaearon 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
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
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
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 |
---|---|---|
|
@@ -13,10 +13,8 @@ | |
'use strict'; | ||
|
||
import type { Fiber } from 'ReactFiber'; | ||
import type { PriorityLevel } from 'ReactPriorityLevel'; | ||
import type { UpdateQueue } from 'ReactFiberUpdateQueue'; | ||
|
||
var { LowPriority } = require('ReactPriorityLevel'); | ||
var { | ||
createUpdateQueue, | ||
addToQueue, | ||
|
@@ -27,16 +25,16 @@ var { isMounted } = require('ReactFiberTreeReflection'); | |
var ReactInstanceMap = require('ReactInstanceMap'); | ||
var shallowEqual = require('shallowEqual'); | ||
|
||
module.exports = function(scheduleUpdate : (fiber: Fiber, priorityLevel : PriorityLevel) => void) { | ||
module.exports = function(scheduleUpdate : (fiber: Fiber) => void) { | ||
|
||
function scheduleUpdateQueue(fiber: Fiber, updateQueue: UpdateQueue, priorityLevel : PriorityLevel) { | ||
function scheduleUpdateQueue(fiber: Fiber, updateQueue: UpdateQueue) { | ||
fiber.updateQueue = updateQueue; | ||
// Schedule update on the alternate as well, since we don't know which tree | ||
// is current. | ||
if (fiber.alternate) { | ||
fiber.alternate.updateQueue = updateQueue; | ||
} | ||
scheduleUpdate(fiber, priorityLevel); | ||
scheduleUpdate(fiber); | ||
} | ||
|
||
// Class component state updater | ||
|
@@ -47,30 +45,27 @@ module.exports = function(scheduleUpdate : (fiber: Fiber, priorityLevel : Priori | |
const updateQueue = fiber.updateQueue ? | ||
addToQueue(fiber.updateQueue, partialState) : | ||
createUpdateQueue(partialState); | ||
scheduleUpdateQueue(fiber, updateQueue, LowPriority); | ||
scheduleUpdateQueue(fiber, updateQueue); | ||
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 think I found the problem... If |
||
}, | ||
enqueueReplaceState(instance, state) { | ||
const fiber = ReactInstanceMap.get(instance); | ||
const updateQueue = createUpdateQueue(state); | ||
updateQueue.isReplace = true; | ||
scheduleUpdateQueue(fiber, updateQueue, LowPriority); | ||
scheduleUpdateQueue(fiber, updateQueue); | ||
}, | ||
enqueueForceUpdate(instance) { | ||
const fiber = ReactInstanceMap.get(instance); | ||
const updateQueue = fiber.updateQueue || createUpdateQueue(null); | ||
updateQueue.isForced = true; | ||
scheduleUpdateQueue(fiber, updateQueue, LowPriority); | ||
scheduleUpdateQueue(fiber, updateQueue); | ||
}, | ||
enqueueCallback(instance, callback) { | ||
const fiber = ReactInstanceMap.get(instance); | ||
let updateQueue = fiber.updateQueue ? | ||
fiber.updateQueue : | ||
createUpdateQueue(null); | ||
addCallbackToQueue(updateQueue, callback); | ||
fiber.updateQueue = updateQueue; | ||
if (fiber.alternate) { | ||
fiber.alternate.updateQueue = updateQueue; | ||
} | ||
scheduleUpdateQueue(fiber, updateQueue); | ||
}, | ||
}; | ||
|
||
|
@@ -131,7 +126,7 @@ module.exports = function(scheduleUpdate : (fiber: Fiber, priorityLevel : Priori | |
// process them now. | ||
const updateQueue = workInProgress.updateQueue; | ||
if (updateQueue) { | ||
instance.state = mergeUpdateQueue(updateQueue, state, props); | ||
instance.state = mergeUpdateQueue(updateQueue, instance, state, props); | ||
} | ||
} | ||
} | ||
|
@@ -175,7 +170,7 @@ module.exports = function(scheduleUpdate : (fiber: Fiber, priorityLevel : Priori | |
// process them now. | ||
const newUpdateQueue = workInProgress.updateQueue; | ||
if (newUpdateQueue) { | ||
newInstance.state = mergeUpdateQueue(newUpdateQueue, newState, newProps); | ||
newInstance.state = mergeUpdateQueue(newUpdateQueue, newInstance, newState, newProps); | ||
} | ||
} | ||
return true; | ||
|
@@ -212,11 +207,21 @@ module.exports = function(scheduleUpdate : (fiber: Fiber, priorityLevel : Priori | |
// TODO: Previous state can be null. | ||
let newState; | ||
if (updateQueue) { | ||
newState = mergeUpdateQueue(updateQueue, previousState, newProps); | ||
if (!updateQueue.hasUpdate) { | ||
newState = previousState; | ||
} else { | ||
newState = mergeUpdateQueue(updateQueue, instance, previousState, newProps); | ||
} | ||
} else { | ||
newState = previousState; | ||
} | ||
|
||
if (oldProps === newProps && | ||
previousState === newState && | ||
updateQueue && !updateQueue.isForced) { | ||
return false; | ||
} | ||
|
||
if (!checkShouldComponentUpdate( | ||
workInProgress, | ||
oldProps, | ||
|
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
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.
Just learned about this a week ago. This is the weirdest part of React API 😄