MCPcopy
hub / github.com/facebook/react / abort

Function abort

packages/react-server/src/ReactFlightServer.js:6128–6197  ·  view source on GitHub ↗
(request: Request, reason: mixed)

Source from the content-addressed store, hash-verified

6126}
6127
6128export function abort(request: Request, reason: mixed): void {
6129 // We define any status below OPEN as OPEN equivalent
6130 if (request.status > OPEN) {
6131 return;
6132 }
6133 try {
6134 request.status = ABORTING;
6135 if (
6136 enableProfilerTimer &&
6137 (enableComponentPerformanceTrack || enableAsyncDebugInfo)
6138 ) {
6139 request.abortTime = performance.now();
6140 }
6141 request.cacheController.abort(reason);
6142 const abortableTasks = request.abortableTasks;
6143 if (abortableTasks.size > 0) {
6144 if (enableHalt && request.type === PRERENDER) {
6145 // When prerendering with halt semantics we simply halt the task
6146 // and leave the reference unfulfilled.
6147 abortableTasks.forEach(task => haltTask(task, request));
6148 scheduleWork(() => finishHalt(request, abortableTasks));
6149 } else if (
6150 enablePostpone &&
6151 typeof reason === 'object' &&
6152 reason !== null &&
6153 (reason: any).$$typeof === REACT_POSTPONE_TYPE
6154 ) {
6155 const postponeInstance: Postpone = (reason: any);
6156 logPostpone(request, postponeInstance.message, null);
6157 // When rendering we produce a shared postpone chunk and then
6158 // fulfill each task with a reference to that chunk.
6159 const errorId = request.nextChunkId++;
6160 request.fatalError = errorId;
6161 request.pendingChunks++;
6162 emitPostponeChunk(request, errorId, postponeInstance);
6163 abortableTasks.forEach(task => abortTask(task, request, errorId));
6164 scheduleWork(() => finishAbort(request, abortableTasks, errorId));
6165 } else {
6166 const error =
6167 reason === undefined
6168 ? new Error(
6169 'The render was aborted by the server without a reason.',
6170 )
6171 : typeof reason === 'object' &&
6172 reason !== null &&
6173 typeof reason.then === 'function'
6174 ? new Error(
6175 'The render was aborted by the server with a promise.',
6176 )
6177 : reason;
6178 const digest = logRecoverableError(request, error, null);
6179 // When rendering we produce a shared error chunk and then
6180 // fulfill each task with a reference to that chunk.
6181 const errorId = request.nextChunkId++;
6182 request.fatalError = errorId;
6183 request.pendingChunks++;
6184 emitErrorChunk(request, errorId, digest, error, false, null);
6185 abortableTasks.forEach(task => abortTask(task, request, errorId));

Callers 15

errorFunction · 0.90
renderToReadableStreamFunction · 0.90
listenerFunction · 0.90
onAllReadyFunction · 0.90
prerenderFunction · 0.90
errorFunction · 0.90
renderToReadableStreamFunction · 0.90
listenerFunction · 0.90
onAllReadyFunction · 0.90
prerenderFunction · 0.90
createCancelHandlerFunction · 0.90
onErrorFunction · 0.90

Calls 14

scheduleWorkFunction · 0.90
haltTaskFunction · 0.85
finishHaltFunction · 0.85
emitPostponeChunkFunction · 0.85
finishAbortFunction · 0.85
emitErrorChunkFunction · 0.85
flushCompletedChunksFunction · 0.85
logPostponeFunction · 0.70
abortTaskFunction · 0.70
logRecoverableErrorFunction · 0.70
fatalErrorFunction · 0.70
abortMethod · 0.65

Tested by

no test coverage detected