GeezerVison is showing github.com — Remove wasteful checks from `shouldYield` · react/react@9abc278
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react/src/__tests__/ReactProfiler-test.internal.js +3-7Lines changed: 3 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2481,15 +2481,11 @@ describe('Profiler', () => { | 2481 | 2481 | // Errors that happen inside of a subscriber should throw, | 2482 | 2482 | throwInOnWorkStarted = true; | 2483 | 2483 | expect(Scheduler).toFlushAndThrow('Expected error onWorkStarted'); | 2484 | | - // Rendering was interrupted by the error that was thrown | 2485 | | - expect(Scheduler).toHaveYielded([]); | 2486 | | - // Rendering continues in the next task | 2487 | | - expect(Scheduler).toFlushAndYield(['Component:text']); | 2488 | 2484 | throwInOnWorkStarted = false; | | 2485 | + // Rendering was interrupted by the error that was thrown, then | | 2486 | + // continued and finished in the next task. | | 2487 | + expect(Scheduler).toHaveYielded(['Component:text']); | 2489 | 2488 | expect(onWorkStarted).toHaveBeenCalled(); | 2490 | | - | 2491 | | - // But the React work should have still been processed. | 2492 | | - expect(Scheduler).toFlushAndYield([]); | 2493 | 2489 | const tree = renderer.toTree(); | 2494 | 2490 | expect(tree.type).toBe(Component); | 2495 | 2491 | expect(tree.props.children).toBe('text'); | |
Collapse file Copy file name to clipboardExpand all lines: packages/scheduler/src/Scheduler.js +1-16Lines changed: 1 addition & 16 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -393,21 +393,6 @@ function unstable_getCurrentPriorityLevel() { | 393 | 393 | return currentPriorityLevel; | 394 | 394 | } | 395 | 395 |
| 396 | | -function unstable_shouldYield() { | 397 | | - const currentTime = getCurrentTime(); | 398 | | - advanceTimers(currentTime); | 399 | | - const firstTask = peek(taskQueue); | 400 | | - return ( | 401 | | - (firstTask !== currentTask && | 402 | | - currentTask !== null && | 403 | | - firstTask !== null && | 404 | | - firstTask.callback !== null && | 405 | | - firstTask.startTime <= currentTime && | 406 | | - firstTask.expirationTime < currentTask.expirationTime) || | 407 | | - shouldYieldToHost() | 408 | | - ); | 409 | | -} | 410 | | - | 411 | 396 | const unstable_requestPaint = requestPaint; | 412 | 397 |
| 413 | 398 | export { | @@ -422,7 +407,7 @@ export { | 422 | 407 | unstable_cancelCallback, | 423 | 408 | unstable_wrapCallback, | 424 | 409 | unstable_getCurrentPriorityLevel, | 425 | | - unstable_shouldYield, | | 410 | + shouldYieldToHost as unstable_shouldYield, | 426 | 411 | unstable_requestPaint, | 427 | 412 | unstable_continueExecution, | 428 | 413 | unstable_pauseExecution, | |
Collapse file Copy file name to clipboardExpand all lines: packages/scheduler/src/__tests__/Scheduler-test.js +6-7Lines changed: 6 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -249,7 +249,7 @@ describe('Scheduler', () => { | 249 | 249 | }); | 250 | 250 |
| 251 | 251 | it( | 252 | | - 'continuations are interrupted by higher priority work scheduled ' + | | 252 | + 'continuations do not block higher priority work scheduled ' + | 253 | 253 | 'inside an executing callback', | 254 | 254 | () => { | 255 | 255 | const tasks = [ | @@ -272,8 +272,8 @@ describe('Scheduler', () => { | 272 | 272 | Scheduler.unstable_yieldValue('High pri'); | 273 | 273 | }); | 274 | 274 | } | 275 | | - if (tasks.length > 0 && shouldYield()) { | 276 | | - Scheduler.unstable_yieldValue('Yield!'); | | 275 | + if (tasks.length > 0) { | | 276 | + // Return a continuation | 277 | 277 | return work; | 278 | 278 | } | 279 | 279 | } | @@ -283,9 +283,8 @@ describe('Scheduler', () => { | 283 | 283 | 'A', | 284 | 284 | 'B', | 285 | 285 | 'Schedule high pri', | 286 | | - // Even though there's time left in the frame, the low pri callback | 287 | | - // should yield to the high pri callback | 288 | | - 'Yield!', | | 286 | + // The high pri callback should fire before the continuation of the | | 287 | + // lower pri work | 289 | 288 | 'High pri', | 290 | 289 | // Continue low pri work | 291 | 290 | 'C', | @@ -662,7 +661,7 @@ describe('Scheduler', () => { | 662 | 661 | const [label, ms] = task; | 663 | 662 | Scheduler.unstable_advanceTime(ms); | 664 | 663 | Scheduler.unstable_yieldValue(label); | 665 | | - if (tasks.length > 0 && shouldYield()) { | | 664 | + if (tasks.length > 0) { | 666 | 665 | return work; | 667 | 666 | } | 668 | 667 | } | |
|