Skip to content

Commit

Permalink
Remove Animation priority
Browse files Browse the repository at this point in the history
There's no advantage to scheduling updates with animation priority
versus scheduling sync work inside requestAnimationCallback. So we can
remove all the animation-specific code. Now there's only one type of
callback.
  • Loading branch information
acdlite committed Jun 19, 2017
1 parent 6a0c56c commit 812244b
Show file tree
Hide file tree
Showing 18 changed files with 288 additions and 579 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"jest": "^19.0.1",
"jest-config": "^19.0.1",
"jest-jasmine2": "^19.0.1",
"jest-matchers": "^20.0.3",
"jest-matchers": "^19.0.1",
"jest-runtime": "^19.0.1",
"loose-envify": "^1.1.0",
"merge-stream": "^1.0.0",
Expand Down
8 changes: 2 additions & 6 deletions scripts/fiber/tests-passing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1791,12 +1791,10 @@ src/renderers/shared/fiber/__tests__/ReactIncremental-test.js
src/renderers/shared/fiber/__tests__/ReactIncrementalErrorHandling-test.js
* catches render error in a boundary during full deferred mounting
* catches render error in a boundary during partial deferred mounting
* catches render error in a boundary during animation mounting
* catches render error in a boundary during synchronous mounting
* catches render error in a boundary during batched mounting
* propagates an error from a noop error boundary during full deferred mounting
* propagates an error from a noop error boundary during partial deferred mounting
* propagates an error from a noop error boundary during animation mounting
* propagates an error from a noop error boundary during synchronous mounting
* propagates an error from a noop error boundary during batched mounting
* applies batched updates regardless despite errors in scheduling
Expand Down Expand Up @@ -1842,18 +1840,16 @@ src/renderers/shared/fiber/__tests__/ReactIncrementalReflection-test.js

src/renderers/shared/fiber/__tests__/ReactIncrementalScheduling-test.js
* schedules and flushes deferred work
* schedules and flushes animation work
* searches for work on other roots once the current root completes
* schedules an animation callback when there`s leftover animation work
* schedules top-level updates in order of priority
* schedules top-level updates with same priority in order of insertion
* works on deferred roots in the order they were scheduled
* schedules sync updates when inside componentDidMount/Update
* can opt-in to deferred/animation scheduling inside componentDidMount/Update
* can opt-in to async scheduling inside componentDidMount/Update
* performs Task work even after time runs out
* does not perform animation work after time runs out
* can opt-out of batching using unbatchedUpdates
* nested updates are always deferred, even inside unbatchedUpdates
* updates do not schedule a new callback if already inside a callback

src/renderers/shared/fiber/__tests__/ReactIncrementalSideEffects-test.js
* can update child nodes of a host instance
Expand Down
48 changes: 24 additions & 24 deletions scripts/rollup/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@
"gzip": 7690
},
"react-dom.development.js (UMD_DEV)": {
"size": 609702,
"gzip": 139802
"size": 608162,
"gzip": 139430
},
"react-dom.production.min.js (UMD_PROD)": {
"size": 126123,
"gzip": 39666
"size": 125771,
"gzip": 39564
},
"react-dom.development.js (NODE_DEV)": {
"size": 568320,
"gzip": 130089
"size": 566845,
"gzip": 129774
},
"react-dom.production.min.js (NODE_PROD)": {
"size": 122488,
"gzip": 38393
"size": 122136,
"gzip": 38292
},
"ReactDOMFiber-dev.js (FB_DEV)": {
"size": 568338,
"gzip": 130385
"size": 566594,
"gzip": 129950
},
"ReactDOMFiber-prod.js (FB_PROD)": {
"size": 428140,
"gzip": 96977
"size": 426211,
"gzip": 96543
},
"react-dom-test-utils.development.js (NODE_DEV)": {
"size": 52921,
Expand All @@ -65,28 +65,28 @@
"gzip": 81957
},
"react-dom-server.development.js (UMD_DEV)": {
"size": 305758,
"gzip": 76967
"size": 306445,
"gzip": 77153
},
"react-dom-server.production.min.js (UMD_PROD)": {
"size": 65877,
"gzip": 22507
"size": 65952,
"gzip": 22521
},
"react-dom-server.development.js (NODE_DEV)": {
"size": 264541,
"gzip": 67428
"size": 265293,
"gzip": 67673
},
"react-dom-server.production.min.js (NODE_PROD)": {
"size": 62227,
"gzip": 21217
"size": 62302,
"gzip": 21232
},
"ReactDOMServerStream-dev.js (FB_DEV)": {
"size": 264063,
"gzip": 67393
"size": 264750,
"gzip": 67600
},
"ReactDOMServerStream-prod.js (FB_PROD)": {
"size": 197791,
"gzip": 51009
"size": 198041,
"gzip": 51047
},
"react-art.development.js (UMD_DEV)": {
"size": 359725,
Expand Down
2 changes: 0 additions & 2 deletions src/renderers/art/ReactARTFiberEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,6 @@ const ARTRenderer = ReactFiberReconciler({
return emptyObject;
},

scheduleAnimationCallback: ReactDOMFrameScheduling.rAF,

scheduleDeferredCallback: ReactDOMFrameScheduling.rIC,

shouldSetTextContent(type, props) {
Expand Down
2 changes: 0 additions & 2 deletions src/renderers/dom/fiber/ReactDOMFiberEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,6 @@ var DOMRenderer = ReactFiberReconciler({
return textInstance.nodeValue !== text;
},

scheduleAnimationCallback: ReactDOMFrameScheduling.rAF,

scheduleDeferredCallback: ReactDOMFrameScheduling.rIC,

useSyncScheduling: !ReactDOMFeatureFlags.fiberAsyncScheduling,
Expand Down
2 changes: 0 additions & 2 deletions src/renderers/native/ReactNativeFiberRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,6 @@ const NativeRenderer = ReactFiberReconciler({
return false;
},

scheduleAnimationCallback: global.requestAnimationFrame,

scheduleDeferredCallback: global.requestIdleCallback,

shouldSetTextContent(type: string, props: Props): boolean {
Expand Down
72 changes: 20 additions & 52 deletions src/renderers/noop/ReactNoopEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ import type {UpdateQueue} from 'ReactFiberUpdateQueue';
var ReactFiberInstrumentation = require('ReactFiberInstrumentation');
var ReactFiberReconciler = require('ReactFiberReconciler');
var ReactInstanceMap = require('ReactInstanceMap');
var {AnimationPriority} = require('ReactPriorityLevel');
var {TaskPriority} = require('ReactPriorityLevel');
var emptyObject = require('fbjs/lib/emptyObject');

var expect = require('jest-matchers');

const UPDATE_SIGNAL = {};

var scheduledAnimationCallback = null;
var scheduledDeferredCallback = null;
var scheduledCallback = null;

type Container = {rootID: string, children: Array<Instance | TextInstance>};
type Props = {prop: any, hidden?: boolean};
Expand Down Expand Up @@ -192,24 +191,14 @@ var NoopRenderer = ReactFiberReconciler({
removeChild: removeChild,
removeChildFromContainer: removeChild,

scheduleAnimationCallback(callback) {
if (scheduledAnimationCallback) {
throw new Error(
'Scheduling an animation callback twice is excessive. ' +
'Instead, keep track of whether the callback has already been scheduled.',
);
}
scheduledAnimationCallback = callback;
},

scheduleDeferredCallback(callback) {
if (scheduledDeferredCallback) {
if (scheduledCallback) {
throw new Error(
'Scheduling deferred callback twice is excessive. ' +
'Instead, keep track of whether the callback has already been scheduled.',
'Scheduling a callback twice is excessive. Instead, keep track of ' +
'whether the callback has already been scheduled.',
);
}
scheduledDeferredCallback = callback;
scheduledCallback = callback;
},

prepareForCommit(): void {},
Expand All @@ -223,13 +212,11 @@ var DEFAULT_ROOT_ID = '<default>';

let yieldedValues = null;

function* flushUnitsOfWork(
n: number = Infinity,
): Generator<Array<mixed>, void, void> {
function* flushUnitsOfWork(n: number): Generator<Array<mixed>, void, void> {
var didStop = false;
while (!didStop && scheduledDeferredCallback !== null) {
var cb = scheduledDeferredCallback;
scheduledDeferredCallback = null;
while (!didStop && scheduledCallback !== null) {
var cb = scheduledCallback;
scheduledCallback = null;
yieldedValues = null;
var unitsRemaining = n;
cb({
Expand Down Expand Up @@ -308,16 +295,6 @@ var ReactNoop = {
return inst ? NoopRenderer.findHostInstance(inst) : null;
},

// TODO: Remove this method
flushAnimationPri() {
var cb = scheduledAnimationCallback;
if (cb === null) {
return;
}
scheduledAnimationCallback = null;
cb();
},

flushDeferredPri(timeout: number = Infinity): Array<mixed> {
// The legacy version of this function decremented the timeout before
// returning the new time.
Expand All @@ -328,48 +305,37 @@ var ReactNoop = {
for (const value of flushUnitsOfWork(n)) {
values.push(...value);
}
// Don't flush animation priority in this legacy function. Some tests may
// still rely on this behavior.
return values;
},

flush(): Array<mixed> {
ReactNoop.flushAnimationPri();
return ReactNoop.flushDeferredPri();
return ReactNoop.flushUnitsOfWork(Infinity);
},

*flushAndYield(
flushAndYield(
unitsOfWork: number = Infinity,
): Generator<Array<mixed>, void, void> {
for (const value of flushUnitsOfWork(unitsOfWork)) {
yield value;
}
ReactNoop.flushAnimationPri();
return flushUnitsOfWork(unitsOfWork);
},

flushUnitsOfWork(n: number): Array<mixed> {
let values = [];
for (const value of flushUnitsOfWork(n)) {
values.push(...value);
}
// TODO: We should always flush animation priority after flushing normal/low
// priority. Move this to flushUnitsOfWork generator once tests
// are converted.
ReactNoop.flushAnimationPri();
return values;
},

flushThrough(expected: Array<mixed>): void {
let actual = [];
if (expected.length !== 0) {
for (const value of flushUnitsOfWork()) {
for (const value of flushUnitsOfWork(Infinity)) {
actual.push(...value);
if (actual.length >= expected.length) {
break;
}
}
}
ReactNoop.flushAnimationPri();
expect(actual).toEqual(expected);
},

Expand All @@ -381,16 +347,18 @@ var ReactNoop = {
}
},

hasScheduledDeferredCallback() {
return !!scheduledDeferredCallback;
hasScheduledCallback() {
return !!scheduledCallback;
},

performAnimationWork(fn: Function) {
NoopRenderer.performWithPriority(AnimationPriority, fn);
taskUpdates(fn: Function) {
NoopRenderer.performWithPriority(TaskPriority, fn);
},

batchedUpdates: NoopRenderer.batchedUpdates,

deferredUpdates: NoopRenderer.deferredUpdates,

unbatchedUpdates: NoopRenderer.unbatchedUpdates,

syncUpdates: NoopRenderer.syncUpdates,
Expand Down
1 change: 0 additions & 1 deletion src/renderers/shared/fiber/ReactFiberReconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ export type HostConfig<T, P, I, TI, PI, C, CX, PL> = {
removeChild(parentInstance: I, child: I | TI): void,
removeChildFromContainer(container: C, child: I | TI): void,

scheduleAnimationCallback(callback: () => void): number | void,
scheduleDeferredCallback(
callback: (deadline: Deadline) => void,
): number | void,
Expand Down
Loading

0 comments on commit 812244b

Please sign in to comment.