Skip to content

Commit ce26a04

Browse files
committed
Remove catch from Scheduler build
Makes debugging errors harder. In this case, we can use `finally` instead.
1 parent 30dfb86 commit ce26a04

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

packages/scheduler/src/forks/SchedulerDOM.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,13 @@ const performWorkUntilDeadline = () => {
519519
// the message event.
520520
deadline = currentTime + yieldInterval;
521521
const hasTimeRemaining = true;
522+
523+
// Use a variable to track whether something task throws, instead of a try-
524+
// catch, since that makes some debugging techniques harder.
525+
let didError = true;
522526
try {
523527
const hasMoreWork = scheduledHostCallback(hasTimeRemaining, currentTime);
528+
didError = false;
524529
if (!hasMoreWork) {
525530
isMessageLoopRunning = false;
526531
scheduledHostCallback = null;
@@ -529,11 +534,12 @@ const performWorkUntilDeadline = () => {
529534
// of the preceding one.
530535
port.postMessage(null);
531536
}
532-
} catch (error) {
533-
// If a scheduler task throws, exit the current browser task so the
534-
// error can be observed.
535-
port.postMessage(null);
536-
throw error;
537+
} finally {
538+
if (didError) {
539+
// If a scheduler task throws, exit the current browser task so the
540+
// error can be observed.
541+
port.postMessage(null);
542+
}
537543
}
538544
} else {
539545
isMessageLoopRunning = false;

packages/scheduler/src/forks/SchedulerPostTaskOnly.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -512,21 +512,27 @@ const performWorkUntilDeadline = () => {
512512
// the message event.
513513
deadline = currentTime + yieldInterval;
514514
const hasTimeRemaining = true;
515+
516+
// Use a variable to track whether something task throws, instead of a try-
517+
// catch, since that makes some debugging techniques harder.
518+
let didError = true;
515519
try {
516520
const hasMoreWork = scheduledHostCallback(hasTimeRemaining, currentTime);
521+
didError = false;
517522
if (!hasMoreWork) {
518523
isTaskLoopRunning = false;
519524
scheduledHostCallback = null;
520525
} else {
521-
// If there's more work, schedule the next message event at the end
522-
// of the preceding one.
526+
// If there's more work, schedule the next browser task at the end of
527+
// the preceding one.
528+
postTask(performWorkUntilDeadline);
529+
}
530+
} finally {
531+
if (didError) {
532+
// If a scheduler task throws, exit the current browser task so the
533+
// error can be observed.
523534
postTask(performWorkUntilDeadline);
524535
}
525-
} catch (error) {
526-
// If a scheduler task throws, exit the current browser task so the
527-
// error can be observed.
528-
postTask(performWorkUntilDeadline);
529-
throw error;
530536
}
531537
} else {
532538
isTaskLoopRunning = false;

0 commit comments

Comments
 (0)