Skip to content

Commit 18d7574

Browse files
authored
Remove catch from Scheduler build (#20396)
Makes debugging errors harder. In this case, we can use `finally` instead.
1 parent 30dfb86 commit 18d7574

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

packages/scheduler/src/forks/SchedulerDOM.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -519,21 +519,25 @@ const performWorkUntilDeadline = () => {
519519
// the message event.
520520
deadline = currentTime + yieldInterval;
521521
const hasTimeRemaining = true;
522+
523+
// If a scheduler task throws, exit the current browser task so the
524+
// error can be observed.
525+
//
526+
// Intentionally not using a try-catch, since that makes some debugging
527+
// techniques harder. Instead, if `scheduledHostCallback` errors, then
528+
// `hasMoreWork` will remain true, and we'll continue the work loop.
529+
let hasMoreWork = true;
522530
try {
523-
const hasMoreWork = scheduledHostCallback(hasTimeRemaining, currentTime);
524-
if (!hasMoreWork) {
525-
isMessageLoopRunning = false;
526-
scheduledHostCallback = null;
527-
} else {
531+
hasMoreWork = scheduledHostCallback(hasTimeRemaining, currentTime);
532+
} finally {
533+
if (hasMoreWork) {
528534
// If there's more work, schedule the next message event at the end
529535
// of the preceding one.
530536
port.postMessage(null);
537+
} else {
538+
isMessageLoopRunning = false;
539+
scheduledHostCallback = null;
531540
}
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;
537541
}
538542
} else {
539543
isMessageLoopRunning = false;

packages/scheduler/src/forks/SchedulerPostTaskOnly.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -512,21 +512,25 @@ const performWorkUntilDeadline = () => {
512512
// the message event.
513513
deadline = currentTime + yieldInterval;
514514
const hasTimeRemaining = true;
515+
516+
// If a scheduler task throws, exit the current browser task so the
517+
// error can be observed.
518+
//
519+
// Intentionally not using a try-catch, since that makes some debugging
520+
// techniques harder. Instead, if `scheduledHostCallback` errors, then
521+
// `hasMoreWork` will remain true, and we'll continue the work loop.
522+
let hasMoreWork = true;
515523
try {
516-
const hasMoreWork = scheduledHostCallback(hasTimeRemaining, currentTime);
517-
if (!hasMoreWork) {
524+
hasMoreWork = scheduledHostCallback(hasTimeRemaining, currentTime);
525+
} finally {
526+
if (hasMoreWork) {
527+
// If there's more work, schedule the next browser task at the end of
528+
// the preceding one.
529+
postTask(performWorkUntilDeadline);
530+
} else {
518531
isTaskLoopRunning = false;
519532
scheduledHostCallback = null;
520-
} else {
521-
// If there's more work, schedule the next message event at the end
522-
// of the preceding one.
523-
postTask(performWorkUntilDeadline);
524533
}
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;
530534
}
531535
} else {
532536
isTaskLoopRunning = false;

0 commit comments

Comments
 (0)