mirror of
https://github.com/zebrajr/react.git
synced 2025-12-07 12:20:38 +01:00
* Rewrite ReactFiberScheduler Adds a new implementation of ReactFiberScheduler behind a feature flag. We will maintain both implementations in parallel until the new one is proven stable enough to replace the old one. The main difference between the implementations is that the new one is integrated with the Scheduler package's priority levels. * Conditionally add fields to FiberRoot Some fields only used by the old scheduler, and some by the new. * Add separate build that enables new scheduler * Re-enable skipped test If synchronous updates are scheduled by a passive effect, that work should be flushed synchronously, even if flushPassiveEffects is called inside batchedUpdates. * Passive effects have same priority as render * Revert ability to cancel the current callback React doesn't need this anyway because it never schedules callbacks if it's already rendering. * Revert change to FiberDebugPerf Turns out this isn't neccessary. * Fix ReactFiberScheduler dead code elimination Should initialize to nothing, then assign the exports conditionally, instead of initializing to the old exports and then reassigning to the new ones. * Don't yield before commit during sync error retry * Call Scheduler.flushAll unconditionally in tests Instead of wrapping in enableNewScheduler flag.
84 lines
2.2 KiB
JavaScript
84 lines
2.2 KiB
JavaScript
'use strict';
|
|
|
|
function captureAssertion(fn) {
|
|
// Trick to use a Jest matcher inside another Jest matcher. `fn` contains an
|
|
// assertion; if it throws, we capture the error and return it, so the stack
|
|
// trace presented to the user points to the original assertion in the
|
|
// test file.
|
|
try {
|
|
fn();
|
|
} catch (error) {
|
|
return {
|
|
pass: false,
|
|
message: () => error.message,
|
|
};
|
|
}
|
|
return {pass: true};
|
|
}
|
|
|
|
function assertYieldsWereCleared(Scheduler) {
|
|
const actualYields = Scheduler.unstable_clearYields();
|
|
if (actualYields.length !== 0) {
|
|
throw new Error(
|
|
'Log of yielded values is not empty. ' +
|
|
'Call expect(Scheduler).toHaveYielded(...) first.'
|
|
);
|
|
}
|
|
}
|
|
|
|
function toFlushAndYield(Scheduler, expectedYields) {
|
|
assertYieldsWereCleared(Scheduler);
|
|
Scheduler.unstable_flushWithoutYielding();
|
|
const actualYields = Scheduler.unstable_clearYields();
|
|
return captureAssertion(() => {
|
|
expect(actualYields).toEqual(expectedYields);
|
|
});
|
|
}
|
|
|
|
function toFlushAndYieldThrough(Scheduler, expectedYields) {
|
|
assertYieldsWereCleared(Scheduler);
|
|
Scheduler.unstable_flushNumberOfYields(expectedYields.length);
|
|
const actualYields = Scheduler.unstable_clearYields();
|
|
return captureAssertion(() => {
|
|
expect(actualYields).toEqual(expectedYields);
|
|
});
|
|
}
|
|
|
|
function toFlushWithoutYielding(Scheduler) {
|
|
return toFlushAndYield(Scheduler, []);
|
|
}
|
|
|
|
function toFlushExpired(Scheduler, expectedYields) {
|
|
assertYieldsWereCleared(Scheduler);
|
|
Scheduler.unstable_flushExpired();
|
|
const actualYields = Scheduler.unstable_clearYields();
|
|
return captureAssertion(() => {
|
|
expect(actualYields).toEqual(expectedYields);
|
|
});
|
|
}
|
|
|
|
function toHaveYielded(Scheduler, expectedYields) {
|
|
return captureAssertion(() => {
|
|
const actualYields = Scheduler.unstable_clearYields();
|
|
expect(actualYields).toEqual(expectedYields);
|
|
});
|
|
}
|
|
|
|
function toFlushAndThrow(Scheduler, ...rest) {
|
|
assertYieldsWereCleared(Scheduler);
|
|
return captureAssertion(() => {
|
|
expect(() => {
|
|
Scheduler.unstable_flushWithoutYielding();
|
|
}).toThrow(...rest);
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
toFlushAndYield,
|
|
toFlushAndYieldThrough,
|
|
toFlushWithoutYielding,
|
|
toFlushExpired,
|
|
toHaveYielded,
|
|
toFlushAndThrow,
|
|
};
|