Skip to content

Commit

Permalink
remove enableSchedulerYield flag, can rely on origin trial token instead
Browse files Browse the repository at this point in the history
  • Loading branch information
noahlemen committed Jul 11, 2023
1 parent 213adc9 commit 7b7e193
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 15 deletions.
1 change: 0 additions & 1 deletion packages/scheduler/src/SchedulerFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ export const enableIsInputPendingContinuous = false;
export const frameYieldMs = 5;
export const continuousYieldMs = 50;
export const maxYieldMs = 300;
export const enableSchedulerYield = false;
71 changes: 66 additions & 5 deletions packages/scheduler/src/__tests__/SchedulerPostTask-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ describe('SchedulerPostTask', () => {

scheduler.yield = function ({priority, signal}) {
const id = idCounter++;
log(
`Post Task ${id} [${priority === undefined ? '<default>' : priority}]`,
);
log(`Yield ${id} [${priority === undefined ? '<default>' : priority}]`);
const controller = signal._controller;
let callback;

Expand Down Expand Up @@ -196,7 +194,7 @@ describe('SchedulerPostTask', () => {
'Task 0 Fired',
'A',
'Yield at 5ms',
'Post Task 1 [user-visible]',
'Yield 1 [user-visible]',
]);

runtime.flushTasks();
Expand Down Expand Up @@ -339,7 +337,7 @@ describe('SchedulerPostTask', () => {

// The continuation should be scheduled in a separate macrotask even
// though there's time remaining.
'Post Task 1 [user-visible]',
'Yield 1 [user-visible]',
]);

// No time has elapsed
Expand All @@ -348,4 +346,67 @@ describe('SchedulerPostTask', () => {
runtime.flushTasks();
runtime.assertLog(['Task 1 Fired', 'Continuation Task']);
});

describe('falls back to postTask for scheduling continuations when scheduler.yield is not available', () => {
beforeEach(() => {
delete global.scheduler.yield;
});

it('task with continuation', () => {
scheduleCallback(NormalPriority, () => {
runtime.log('A');
while (!Scheduler.unstable_shouldYield()) {
runtime.advanceTime(1);
}
runtime.log(`Yield at ${performance.now()}ms`);
return () => {
runtime.log('Continuation');
};
});
runtime.assertLog(['Post Task 0 [user-visible]']);

runtime.flushTasks();
runtime.assertLog([
'Task 0 Fired',
'A',
'Yield at 5ms',
'Post Task 1 [user-visible]',
]);

runtime.flushTasks();
runtime.assertLog(['Task 1 Fired', 'Continuation']);
});

it('yielding continues in a new task regardless of how much time is remaining', () => {
scheduleCallback(NormalPriority, () => {
runtime.log('Original Task');
runtime.log('shouldYield: ' + shouldYield());
runtime.log('Return a continuation');
return () => {
runtime.log('Continuation Task');
};
});
runtime.assertLog(['Post Task 0 [user-visible]']);

runtime.flushTasks();
runtime.assertLog([
'Task 0 Fired',
'Original Task',
// Immediately before returning a continuation, `shouldYield` returns
// false, which means there must be time remaining in the frame.
'shouldYield: false',
'Return a continuation',

// The continuation should be scheduled in a separate macrotask even
// though there's time remaining.
'Post Task 1 [user-visible]',
]);

// No time has elapsed
expect(performance.now()).toBe(0);

runtime.flushTasks();
runtime.assertLog(['Task 1 Fired', 'Continuation Task']);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@
// with the __VARIANT__ set to `true`, and once set to `false`.

export const enableProfiling = __VARIANT__;
export const enableSchedulerYield = __VARIANT__;
6 changes: 1 addition & 5 deletions packages/scheduler/src/forks/SchedulerFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@
* @flow
*/

const {
enableProfiling: enableProfilingFeatureFlag,
enableSchedulerYield: enableSchedulerYieldFeatureFlag,
} =
const {enableProfiling: enableProfilingFeatureFlag} =
// $FlowFixMe[cannot-resolve-module]
require('SchedulerFeatureFlags');

export const enableSchedulerDebugging = true;
export const enableProfiling: boolean =
__PROFILE__ && enableProfilingFeatureFlag;
export const enableSchedulerYield = enableSchedulerYieldFeatureFlag;
export const enableIsInputPending = true;
export const enableIsInputPendingContinuous = true;
export const frameYieldMs = 5;
Expand Down
4 changes: 1 addition & 3 deletions packages/scheduler/src/forks/SchedulerPostTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

import type {PriorityLevel} from '../SchedulerPriorities';

import {enableSchedulerYield} from '../SchedulerFeatureFlags';

declare class TaskController {
constructor(priority?: string): TaskController;
signal: mixed;
Expand Down Expand Up @@ -149,7 +147,7 @@ function runTask<T>(
continuation,
);

if (enableSchedulerYield && scheduler.yield !== undefined) {
if (scheduler.yield !== undefined) {
scheduler
.yield(continuationOptions)
.then(nextTask)
Expand Down

0 comments on commit 7b7e193

Please sign in to comment.