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

Function performWork

packages/react-server/src/ReactFizzServer.js:5414–5470  ·  view source on GitHub ↗
(request: Request)

Source from the content-addressed store, hash-verified

5412}
5413
5414export function performWork(request: Request): void {
5415 if (request.status === CLOSED || request.status === CLOSING) {
5416 return;
5417 }
5418 const prevContext = getActiveContext();
5419 const prevDispatcher = ReactSharedInternals.H;
5420 ReactSharedInternals.H = HooksDispatcher;
5421 const prevAsyncDispatcher = ReactSharedInternals.A;
5422 ReactSharedInternals.A = DefaultAsyncDispatcher;
5423
5424 const prevRequest = currentRequest;
5425 currentRequest = request;
5426
5427 let prevGetCurrentStackImpl = null;
5428 if (__DEV__) {
5429 prevGetCurrentStackImpl = ReactSharedInternals.getCurrentStack;
5430 ReactSharedInternals.getCurrentStack = getCurrentStackInDEV;
5431 }
5432 const prevResumableState = currentResumableState;
5433 setCurrentResumableState(request.resumableState);
5434 try {
5435 const pingedTasks = request.pingedTasks;
5436 let i;
5437 for (i = 0; i < pingedTasks.length; i++) {
5438 const task = pingedTasks[i];
5439 retryTask(request, task);
5440 }
5441 pingedTasks.splice(0, i);
5442 if (request.destination !== null) {
5443 flushCompletedQueues(request, request.destination);
5444 }
5445 } catch (error) {
5446 const errorInfo: ThrownInfo = {};
5447 logRecoverableError(request, error, errorInfo, null);
5448 fatalError(request, error, errorInfo, null);
5449 } finally {
5450 setCurrentResumableState(prevResumableState);
5451
5452 ReactSharedInternals.H = prevDispatcher;
5453 ReactSharedInternals.A = prevAsyncDispatcher;
5454
5455 if (__DEV__) {
5456 ReactSharedInternals.getCurrentStack = prevGetCurrentStackImpl;
5457 }
5458 if (prevDispatcher === HooksDispatcher) {
5459 // This means that we were in a reentrant work loop. This could happen
5460 // in a renderer that supports synchronous work like renderToString,
5461 // when it's called from within another renderer.
5462 // Normally we don't bother switching the contexts to their root/default
5463 // values when leaving because we'll likely need the same or similar
5464 // context again. However, when we're inside a synchronous loop like this
5465 // we'll to restore the context to what it was before returning.
5466 switchContext(prevContext);
5467 }
5468 currentRequest = prevRequest;
5469 }
5470}
5471

Callers 3

renderNextChunkFunction · 0.90
pingTaskFunction · 0.70
startWorkFunction · 0.70

Calls 6

getActiveContextFunction · 0.90
switchContextFunction · 0.90
flushCompletedQueuesFunction · 0.85
retryTaskFunction · 0.70
logRecoverableErrorFunction · 0.70
fatalErrorFunction · 0.70

Tested by

no test coverage detected