Skip to content
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

Fix priority inference of next level of work #15478

Merged
merged 1 commit into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/react-reconciler/src/ReactFiberExpirationTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ export function inferPriorityFromExpirationTime(
return IdlePriority;
}
const msUntil =
msToExpirationTime(expirationTime) - msToExpirationTime(currentTime);
expirationTimeToMs(expirationTime) - expirationTimeToMs(currentTime);
if (msUntil <= 0) {
return ImmediatePriority;
}
if (msUntil <= HIGH_PRIORITY_EXPIRATION) {
if (msUntil <= HIGH_PRIORITY_EXPIRATION + HIGH_PRIORITY_BATCH_SIZE) {
return UserBlockingPriority;
}
if (msUntil <= LOW_PRIORITY_EXPIRATION) {
if (msUntil <= LOW_PRIORITY_EXPIRATION + LOW_PRIORITY_BATCH_SIZE) {
return NormalPriority;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,22 @@ describe('ReactSchedulerIntegration', () => {
]);
});

it('after completing a level of work, infers priority of the next batch based on its expiration time', () => {
function App({label}) {
Scheduler.yieldValue(`${label} [${getCurrentPriorityAsString()}]`);
return label;
}

// Schedule two separate updates at different priorities
runWithPriority(UserBlockingPriority, () => {
ReactNoop.render(<App label="A" />);
});
ReactNoop.render(<App label="B" />);

// The second update should run at normal priority
expect(Scheduler).toFlushAndYield(['A [UserBlocking]', 'B [Normal]']);
});

// TODO
it.skip('passive effects have render priority even if they are flushed early', () => {});
});