Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions src/renderers/shared/fiber/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,19 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
let nextUnitOfWork : ?Fiber = null;
let nextPriorityLevel : PriorityLevel = NoWork;

// The next errors we need to handle before next item of work.
let nextTrappedErrors : Array<TrappedError> | null = null;

// Linked list of roots with scheduled work on them.
let nextScheduledRoot : ?FiberRoot = null;
let lastScheduledRoot : ?FiberRoot = null;

function findNextUnitOfWork() {
if (nextTrappedErrors) {
// While we have errors, we can't perform any normal work.
return null;
}

// Clear out roots with no more work on them.
while (nextScheduledRoot && nextScheduledRoot.current.pendingWorkPriority === NoWork) {
nextScheduledRoot.isScheduled = false;
Expand Down Expand Up @@ -204,10 +212,7 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
}
}

// Now that the tree has been committed, we can handle errors.
if (allTrappedErrors) {
handleErrors(allTrappedErrors);
}
nextTrappedErrors = allTrappedErrors;
}

function resetWorkPriority(workInProgress : Fiber) {
Expand Down Expand Up @@ -377,7 +382,10 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
throw error;
}
const trappedError = trapError(failedUnitOfWork, error);
handleErrors([trappedError]);
nextTrappedErrors = [trappedError];
}
if (nextTrappedErrors) {
handleErrors();
}
}

Expand Down Expand Up @@ -444,7 +452,10 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
throw error;
}
const trappedError = trapError(failedUnitOfWork, error);
handleErrors([trappedError]);
nextTrappedErrors = [trappedError];
}
if (nextTrappedErrors) {
handleErrors();
}
}

Expand Down Expand Up @@ -498,8 +509,7 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
return root;
}

function handleErrors(initialTrappedErrors : Array<TrappedError>) : void {
let nextTrappedErrors = initialTrappedErrors;
function handleErrors() : void {
let firstUncaughtError = null;

// In each phase, we will attempt to pass errors to boundaries and re-render them.
Expand Down Expand Up @@ -543,8 +553,6 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
let fiber = cloneFiber(root.current, priority);
try {
while (fiber) {
// TODO: this is the only place where we recurse and it's unfortunate.
// (This may potentially get us into handleErrors() again.)
fiber = performUnitOfWork(fiber, true);
}
} catch (nextError) {
Expand Down