dillon1000/react
Commit
Browse files [Mock Scheduler] Mimic browser's advanceTime (#17967)
The mock Scheduler that we use in our tests has its own fake timer implementation. The `unstable_advanceTime` method advances the timeline. Currently, a call to `unstable_advanceTime` will also flush any pending expired work. But that's not how it works in the browser: when a timer fires, the corresponding task is added to the Scheduler queue. However, we will still wait until the next message event before flushing it. This commit changes `unstable_advanceTime` to more closely resemble the browser behavior, by removing the automatic flushing of expired work. ```js // Before this commit Scheduler.unstable_advanceTime(ms); // Equivalent behavior after this commit Scheduler.unstable_advanceTime(ms); Scheduler.unstable_flushExpired(); ``` The general principle is to prefer separate APIs for scheduling tasks and flushing them. This change does not affect any public APIs. `unstable_advanceTime` is only used by our own test suite. It is not used by `act`. However, we may need to update tests in www, like Relay's.
Changed paths5 files
First-parent comparisonpackages/react-dom/src/events/__tests__/ChangeEventPlugin-test.internal.js ModifiedM packages/react-reconciler/src/__tests__/ReactIncrementalUpdates-test.internal.js ModifiedM packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.internal.js ModifiedM packages/scheduler/src/__tests__/Scheduler-test.js ModifiedM packages/scheduler/src/forks/SchedulerHostConfig.mock.js ModifiedPatch
Files changed
Rendering syntax-highlighted changes…