Fix priority inference of next level of work (#15478)
Bugfix for `inferPriorityFromExpirationTime` function. It happened to work in our existing tests because we use virtual time. Flow would have caught this if expiration times were an opaque type. We should consider that in the future. (The downside of opaque types is that all operations would have to go through helper functions, which may or may not get inlined by Closure.)
Andrew Clark committed
Apr 23, 2019 at 16:41 UTC
ce126fbb231f9110151b4c93cff765fd882a9f64
2 files changed
+19
-3
packages/react-reconciler/src/ReactFiberExpirationTime.js
+3
-3
@@ -111,14 +111,14 @@ export function inferPriorityFromExpirationTime(
111
return IdlePriority;
112
}
113
const msUntil =
114
- msToExpirationTime(expirationTime) - msToExpirationTime(currentTime);
114
+ expirationTimeToMs(expirationTime) - expirationTimeToMs(currentTime);
115
if (msUntil <= 0) {
116
return ImmediatePriority;
117
}
118
- if (msUntil <= HIGH_PRIORITY_EXPIRATION) {
118
+ if (msUntil <= HIGH_PRIORITY_EXPIRATION + HIGH_PRIORITY_BATCH_SIZE) {
119
return UserBlockingPriority;
120
}
121
- if (msUntil <= LOW_PRIORITY_EXPIRATION) {
121
+ if (msUntil <= LOW_PRIORITY_EXPIRATION + LOW_PRIORITY_BATCH_SIZE) {
122
return NormalPriority;
123
}
124
packages/react-reconciler/src/__tests__/ReactSchedulerIntegration-test.internal.js
+16
@@ -150,6 +150,22 @@ describe('ReactSchedulerIntegration', () => {
150
]);
151
});
152
153
+ it('after completing a level of work, infers priority of the next batch based on its expiration time', () => {
154
+ function App({label}) {
155
+ Scheduler.yieldValue(`${label} [${getCurrentPriorityAsString()}]`);
156
+ return label;
157
+ }
158
+
159
+ // Schedule two separate updates at different priorities
160
+ runWithPriority(UserBlockingPriority, () => {
161
+ ReactNoop.render(<App label="A" />);
162
+ });
163
+ ReactNoop.render(<App label="B" />);
164
+
165
+ // The second update should run at normal priority
166
+ expect(Scheduler).toFlushAndYield(['A [UserBlocking]', 'B [Normal]']);
167
+ });
168
+
169
// TODO
170
it.skip('passive effects have render priority even if they are flushed early', () => {});
171
});