@samitouri / QOS-React-2 / commits / 18d7574ae2

Remove `catch` from Scheduler build (#20396)

Makes debugging errors harder. In this case, we can use `finally` instead.

Andrew Clark committed Dec 7, 2020 at 13:10 UTC 18d7574ae297a24d53fe418e9008e969c29ffba2
2 files changed +29 -21
packages/scheduler/src/forks/SchedulerDOM.js
+14 -10
@@ -519,21 +519,25 @@ const performWorkUntilDeadline = () => {
519 // the message event.
520 deadline = currentTime + yieldInterval;
521 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;
530 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) {
534 // If there's more work, schedule the next message event at the end
535 // of the preceding one.
536 port.postMessage(null);
537 + } else {
538 + isMessageLoopRunning = false;
539 + scheduledHostCallback = null;
540 }
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;
541 }
542 } else {
543 isMessageLoopRunning = false;
packages/scheduler/src/forks/SchedulerPostTaskOnly.js
+15 -11
@@ -512,21 +512,25 @@ const performWorkUntilDeadline = () => {
512 // the message event.
513 deadline = currentTime + yieldInterval;
514 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;
523 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 {
531 isTaskLoopRunning = false;
532 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);
533 }
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;
534 }
535 } else {
536 isTaskLoopRunning = false;