Repository: facebook/react
File: packages/react-server/src/ReactFlightServer.js (JavaScript)

Code before:
        error =
          reason === undefined
            ? new Error(
                'The render was aborted by the server without a reason.',
              )
            : typeof reason === 'object' &&
                reason !== null &&
                typeof reason.then === 'function'
              ? new Error(
                  'The render was aborted by the server with a promise.',
                )
              : reason;
      }
      abortListeners.forEach(callback => callback(error));
      abortListeners.clear();
    }
    if (request.destination !== null) {
      flushCompletedChunks(request, request.destination);
    }
  } catch (error) {
    logRecoverableError(request, error, null);
    fatalError(request, error);
  }
}

const haltSymbol = Symbol('halt');

// This is called to stop rendering without erroring. All unfinished work is represented Promises
// that never resolve.
export function halt(request: Request, reason: mixed): void {
  try {
    if (request.status === OPEN) {
      request.status = ABORTING;
    }
    request.fatalError = haltSymbol;
    const abortableTasks = request.abortableTasks;
    // We have tasks to abort. We'll emit one error row and then emit a reference
    // to that row from every row that's still remaining.
    if (abortableTasks.size > 0) {
      abortableTasks.forEach(task => haltTask(task, request));
      abortableTasks.clear();
    }
    const abortListeners = request.abortListeners;
    if (abortListeners.size > 0) {
      abortListeners.forEach(callback => callback(reason));
      abortListeners.clear();
    }
    if (request.destination !== null) {
      flushCompletedChunks(request, request.destination);
    }
    const onAllReady = request.onAllReady;

Review comment (bug):
this was a bug I landed earlier. it prevents the flush from ever completing because we don't actually have a new pending chunk here

Code after:
    fatalError(request, error);
  }
}

const haltSymbol = Symbol('halt');

// This is called to stop rendering without erroring. All unfinished work is represented Promises
// that never resolve.
export function halt(request: Request, reason: mixed): void {
  try {
    if (request.status === OPEN) {
      request.status = ABORTING;
    }
    request.fatalError = haltSymbol;
    const abortableTasks = request.abortableTasks;
    // We have tasks to abort. We'll emit one error row and then emit a reference
    // to that row from every row that's still remaining.
    if (abortableTasks.size > 0) {
      request.pendingChunks++;
      const errorId = request.nextChunkId++;
      emitBlockedChunk(request, errorId);
      abortableTasks.forEach(task => abortTask(task, request, errorId));
      abortableTasks.clear();
      allReady(request);
    }
    const abortListeners = request.abortListeners;
    if (abortListeners.size > 0) {
      abortListeners.forEach(callback => callback(reason));
      abortListeners.clear();
    }
    if (request.destination !== null) {
      flushCompletedChunks(request, request.destination);
    }
  } catch (error) {
    logRecoverableError(request, error, null);
    fatalError(request, error);
  }
}

function allReady(request: Request) {
  const onAllReady = request.onAllReady;
  onAllReady();
}