Skip to content

Commit 8cf2534

Browse files
committed
Use frameAligned for DefaultUpdate
1 parent 287acc7 commit 8cf2534

File tree

14 files changed

+41
-88
lines changed

14 files changed

+41
-88
lines changed

packages/jest-react/src/internalAct.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,6 @@ export function act<T>(scope: () => Thenable<T> | T): Thenable<T> {
106106
let didFlushWork;
107107
do {
108108
didFlushWork = Scheduler.unstable_flushAllWithoutAsserting();
109-
110-
// Flush scheduled rAF.
111-
if (global.flushRequestAnimationFrameQueue) {
112-
global.flushRequestAnimationFrameQueue();
113-
}
114109
} while (didFlushWork);
115110
return {
116111
then(resolve, reject) {

packages/react-dom-bindings/src/client/ReactDOMHostConfig.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ import {
7474
} from 'react-reconciler/src/ReactWorkTags';
7575
import {listenToAllSupportedEvents} from '../events/DOMPluginEventSystem';
7676

77-
import {UnknownEventPriority} from 'react-reconciler/src/ReactEventPriorities';
77+
import {DefaultEventPriority} from 'react-reconciler/src/ReactEventPriorities';
7878

7979
// TODO: Remove this deep import when we delete the legacy root API
8080
import {ConcurrentMode, NoMode} from 'react-reconciler/src/ReactTypeOfMode';
@@ -374,7 +374,7 @@ export function createTextInstance(
374374
export function getCurrentEventPriority(): EventPriority {
375375
const currentEvent = window.event;
376376
if (currentEvent === undefined) {
377-
return UnknownEventPriority;
377+
return DefaultEventPriority;
378378
}
379379
return getEventPriority(currentEvent.type);
380380
}
@@ -414,21 +414,21 @@ export const scheduleMicrotask: any =
414414
.catch(handleErrorInNextTick)
415415
: scheduleTimeout; // TODO: Determine the best fallback here.
416416

417-
// TODO: Fix these types
418417
export const supportsFrameAlignedTask = true;
419418

420419
type FrameAlignedTask = {|
421-
rafNode: number,
420+
rafNode: AnimationFrameID,
422421
schedulerNode: number,
423422
task: function,
424423
|};
425424

426425
let currentTask: FrameAlignedTask | null = null;
427426
function performFrameAlignedWork() {
428-
if (currentTask != null) {
429-
const task = currentTask.task;
430-
localCancelAnimationFrame(currentTask.id);
431-
Scheduler.unstable_cancelCallback(currentTask.schedulerNode);
427+
const constCurrentTask = currentTask;
428+
if (constCurrentTask != null) {
429+
const task = constCurrentTask.task;
430+
localCancelAnimationFrame(constCurrentTask.rafNode);
431+
Scheduler.unstable_cancelCallback(constCurrentTask.schedulerNode);
432432
currentTask = null;
433433
if (task != null) {
434434
task();
@@ -461,9 +461,8 @@ export function scheduleFrameAlignedTask(task: any): any {
461461
return currentTask;
462462
}
463463

464-
export function cancelFrameAlignedTask(task: FrameAlignedTask) {
464+
export function cancelFrameAlignedTask(task: any) {
465465
Scheduler.unstable_cancelCallback(task.schedulerNode);
466-
task.schedulerNode = null;
467466
// We don't cancel the rAF in case it gets re-used later.
468467
// But clear the task so if it fires and shouldn't run, it won't.
469468
task.task = null;

packages/react-dom/src/__tests__/ReactDOMFiberAsync-test.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,8 @@ describe('ReactDOMFiberAsync', () => {
678678
window.event = 'test';
679679
setState(1);
680680

681-
// We should not schedule a rAF for default updates only.
682-
expect(global.requestAnimationFrameQueue).toBe(null);
681+
// We should schedule a rAF for default updates.
682+
expect(global.requestAnimationFrameQueue.length).toBe(1);
683683

684684
window.event = undefined;
685685
setState(2);
@@ -715,8 +715,8 @@ describe('ReactDOMFiberAsync', () => {
715715
window.event = 'test';
716716
setState(1);
717717

718-
// We should not schedule a rAF for default updates only.
719-
expect(global.requestAnimationFrameQueue).toBe(null);
718+
// We should schedule a rAF for default updates.
719+
expect(global.requestAnimationFrameQueue.length).toBe(1);
720720

721721
window.event = undefined;
722722
setState(2);
@@ -914,29 +914,27 @@ describe('ReactDOMFiberAsync', () => {
914914
expect(Scheduler).toHaveYielded(['Count: 0']);
915915

916916
window.event = undefined;
917+
console.log('set state');
917918
setState(1);
919+
//expect(global.requestAnimationFrameQueue.length).toBe(1);
918920
global.flushRequestAnimationFrameQueue();
919921
expect(Scheduler).toHaveYielded(['Count: 1']);
920922

921923
setState(2);
922924
setThrowing(true);
923-
925+
expect(global.requestAnimationFrameQueue.length).toBe(1);
924926
global.flushRequestAnimationFrameQueue();
925927
expect(Scheduler).toHaveYielded(['Count: 2', 'suspending']);
926928
expect(counterRef.current.textContent).toBe('Count: 1');
927929

928930
unsuspend();
929-
setThrowing(false);
930-
931-
// Should not be scheduled in a rAF.
931+
// Default update should be scheduled in a rAF.
932932
window.event = 'test';
933+
setThrowing(false);
933934
setState(2);
934935

935-
// TODO: This should not yield
936-
// global.flushRequestAnimationFrameQueue();
937-
// expect(Scheduler).toHaveYielded([]);
938-
939-
expect(Scheduler).toFlushAndYield(['Count: 2']);
936+
global.flushRequestAnimationFrameQueue();
937+
expect(Scheduler).toHaveYielded(['Count: 2']);
940938
expect(counterRef.current.textContent).toBe('Count: 2');
941939
});
942940
});

packages/react-dom/src/__tests__/ReactDOMRoot-test.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,17 +392,19 @@ describe('ReactDOMRoot', () => {
392392

393393
expect(container.textContent).toEqual('a');
394394

395-
// Set an event so this isn't flushed synchronously as an unknown update.
396-
window.event = 'test';
397-
398395
await act(async () => {
399396
root.render(<Foo value="b" />);
400397

401398
expect(Scheduler).toHaveYielded(['a']);
402399
expect(container.textContent).toEqual('a');
403400

404401
expect(Scheduler).toFlushAndYieldThrough(['b']);
405-
if (gate(flags => flags.allowConcurrentByDefault)) {
402+
if (
403+
gate(
404+
flags =>
405+
flags.allowConcurrentByDefault && !flags.enableFrameEndScheduling,
406+
)
407+
) {
406408
expect(container.textContent).toEqual('a');
407409
} else {
408410
expect(container.textContent).toEqual('b');

packages/react-reconciler/src/ReactEventPriorities.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import {enableNewReconciler} from 'shared/ReactFeatureFlags';
1111

1212
import {
13-
UnknownEventPriority as UnknownEventPriority_old,
1413
DiscreteEventPriority as DiscreteEventPriority_old,
1514
ContinuousEventPriority as ContinuousEventPriority_old,
1615
DefaultEventPriority as DefaultEventPriority_old,
@@ -22,7 +21,6 @@ import {
2221
} from './ReactEventPriorities.old';
2322

2423
import {
25-
UnknownEventPriority as UnknownEventPriority_new,
2624
DiscreteEventPriority as DiscreteEventPriority_new,
2725
ContinuousEventPriority as ContinuousEventPriority_new,
2826
DefaultEventPriority as DefaultEventPriority_new,
@@ -35,9 +33,6 @@ import {
3533

3634
export type EventPriority = number;
3735

38-
export const UnknownEventPriority: EventPriority = enableNewReconciler
39-
? (UnknownEventPriority_new: any)
40-
: (UnknownEventPriority_old: any);
4136
export const DiscreteEventPriority: EventPriority = enableNewReconciler
4237
? (DiscreteEventPriority_new: any)
4338
: (DiscreteEventPriority_old: any);

packages/react-reconciler/src/ReactFiberHooks.new.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,6 @@ function useMutableSource<Source, Snapshot>(
13131313
setSnapshot(maybeNewSnapshot);
13141314

13151315
const lane = requestUpdateLane(fiber);
1316-
// TODO: What to do about isUnknownEventPriority
13171316
markRootMutableRead(root, lane);
13181317
}
13191318
// If the source mutated between render and now,
@@ -1334,7 +1333,6 @@ function useMutableSource<Source, Snapshot>(
13341333

13351334
// Record a pending mutable source update with the same expiration time.
13361335
const lane = requestUpdateLane(fiber);
1337-
// TODO: What to do about isUnknownEventPriority
13381336
markRootMutableRead(root, lane);
13391337
} catch (error) {
13401338
// A selector might throw after a source mutation.

packages/react-reconciler/src/ReactFiberHooks.old.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,6 @@ function useMutableSource<Source, Snapshot>(
13131313
setSnapshot(maybeNewSnapshot);
13141314

13151315
const lane = requestUpdateLane(fiber);
1316-
// TODO: What to do about isUnknownEventPriority
13171316
markRootMutableRead(root, lane);
13181317
}
13191318
// If the source mutated between render and now,
@@ -1334,7 +1333,6 @@ function useMutableSource<Source, Snapshot>(
13341333

13351334
// Record a pending mutable source update with the same expiration time.
13361335
const lane = requestUpdateLane(fiber);
1337-
// TODO: What to do about isUnknownEventPriority
13381336
markRootMutableRead(root, lane);
13391337
} catch (error) {
13401338
// A selector might throw after a source mutation.

packages/react-reconciler/src/ReactFiberHotReloading.new.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ function scheduleFibersWithFamiliesRecursively(
314314
}
315315
if (needsRemount || needsRender) {
316316
const root = enqueueConcurrentRenderForLane(fiber, SyncLane);
317+
317318
if (root !== null) {
318319
scheduleUpdateOnFiber(
319320
root,

packages/react-reconciler/src/ReactFiberHotReloading.old.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ function scheduleFibersWithFamiliesRecursively(
314314
}
315315
if (needsRemount || needsRender) {
316316
const root = enqueueConcurrentRenderForLane(fiber, SyncLane);
317+
317318
if (root !== null) {
318319
scheduleUpdateOnFiber(
319320
root,

packages/react-reconciler/src/ReactFiberLane.new.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -483,11 +483,7 @@ export function includesBlockingLane(root: FiberRoot, lanes: Lanes): boolean {
483483
allowConcurrentByDefault &&
484484
(root.current.mode & ConcurrentUpdatesByDefaultMode) !== NoMode
485485
) {
486-
if (
487-
enableFrameEndScheduling &&
488-
(lanes & DefaultLane) !== NoLanes &&
489-
root.hasUnknownUpdates
490-
) {
486+
if (enableFrameEndScheduling && (lanes & DefaultLane) !== NoLanes) {
491487
// Unknown updates should flush synchronously, even in concurrent by default.
492488
return true;
493489
}
@@ -631,7 +627,6 @@ export function markRootUpdated(
631627
export function markRootSuspended(root: FiberRoot, suspendedLanes: Lanes) {
632628
root.suspendedLanes |= suspendedLanes;
633629
root.pingedLanes &= ~suspendedLanes;
634-
root.hasUnknownUpdates = false;
635630

636631
// The suspended lanes are no longer CPU-bound. Clear their expiration times.
637632
const expirationTimes = root.expirationTimes;
@@ -663,10 +658,6 @@ export function markRootFinished(root: FiberRoot, remainingLanes: Lanes) {
663658

664659
root.pendingLanes = remainingLanes;
665660

666-
if ((root.pendingLanes & DefaultLane) === NoLane) {
667-
root.hasUnknownUpdates = false;
668-
}
669-
670661
// Let's try everything again
671662
root.suspendedLanes = NoLanes;
672663
root.pingedLanes = NoLanes;

0 commit comments

Comments
 (0)