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

Function createTask

packages/react-server/src/ReactFlightServer.js:2556–2662  ·  view source on GitHub ↗
(
  request: Request,
  model: ReactClientValue,
  keyPath: null | string,
  implicitSlot: boolean,
  formatContext: FormatContext,
  abortSet: Set<Task>,
  lastTimestamp: number, // Profiling-only
  debugOwner: null | ReactComponentInfo, // DEV-only
  debugStack: null | Error, // DEV-only
  debugTask: null | ConsoleTask, // DEV-only
)

Source from the content-addressed store, hash-verified

2554}
2555
2556function createTask(
2557 request: Request,
2558 model: ReactClientValue,
2559 keyPath: null | string,
2560 implicitSlot: boolean,
2561 formatContext: FormatContext,
2562 abortSet: Set<Task>,
2563 lastTimestamp: number, // Profiling-only
2564 debugOwner: null | ReactComponentInfo, // DEV-only
2565 debugStack: null | Error, // DEV-only
2566 debugTask: null | ConsoleTask, // DEV-only
2567): Task {
2568 request.pendingChunks++;
2569 const id = request.nextChunkId++;
2570 if (typeof model === 'object' && model !== null) {
2571 // If we're about to write this into a new task we can assign it an ID early so that
2572 // any other references can refer to the value we're about to write.
2573 if (keyPath !== null || implicitSlot) {
2574 // If we're in some kind of context we can't necessarily reuse this object depending
2575 // what parent components are used.
2576 } else {
2577 request.writtenObjects.set(model, serializeByValueID(id));
2578 }
2579 }
2580 const task: Task = (({
2581 id,
2582 status: PENDING,
2583 model,
2584 keyPath,
2585 implicitSlot,
2586 formatContext: formatContext,
2587 ping: () => pingTask(request, task),
2588 toJSON: function (
2589 this:
2590 | {+[key: string | number]: ReactClientValue}
2591 | $ReadOnlyArray<ReactClientValue>,
2592 parentPropertyName: string,
2593 value: ReactClientValue,
2594 ): ReactJSONValue {
2595 const parent = this;
2596 // Make sure that `parent[parentPropertyName]` wasn't JSONified before `value` was passed to us
2597 if (__DEV__) {
2598 // $FlowFixMe[incompatible-use]
2599 const originalValue = parent[parentPropertyName];
2600 if (
2601 typeof originalValue === 'object' &&
2602 originalValue !== value &&
2603 !(originalValue instanceof Date)
2604 ) {
2605 // Call with the server component as the currently rendering component
2606 // for context.
2607 callWithDebugContextInDEV(request, task, () => {
2608 if (objectName(originalValue) !== 'Object') {
2609 const jsxParentType = jsxChildrenParents.get(parent);
2610 if (typeof jsxParentType === 'string') {
2611 console.error(
2612 '%s objects cannot be rendered as text children. Try formatting it using toString().%s',
2613 objectName(originalValue),

Callers 15

ReactJSXElement.jsFile · 0.85
jsxDEVFunction · 0.85
createElementFunction · 0.85
RequestInstanceFunction · 0.85
serializeThenableFunction · 0.85
serializeReadableStreamFunction · 0.85
serializeAsyncIterableFunction · 0.85
deferTaskFunction · 0.85
outlineTaskFunction · 0.85

Calls 10

objectNameFunction · 0.90
renderModelFunction · 0.85
setMethod · 0.80
addMethod · 0.80
serializeByValueIDFunction · 0.70
pingTaskFunction · 0.70
getMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected