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

Function init

packages/react-server/src/ReactFlightServerConfigDebugNode.js:65–193  ·  view source on GitHub ↗
(
        asyncId: number,
        type: string,
        triggerAsyncId: number,
        resource: any,
      )

Source from the content-addressed store, hash-verified

63 if (__DEV__ && enableAsyncDebugInfo) {
64 createHook({
65 init(
66 asyncId: number,
67 type: string,
68 triggerAsyncId: number,
69 resource: any,
70 ): void {
71 const trigger = pendingOperations.get(triggerAsyncId);
72 let node: AsyncSequence;
73 if (type === 'PROMISE') {
74 const currentAsyncId = executionAsyncId();
75 if (currentAsyncId !== triggerAsyncId) {
76 // When you call .then() on a native Promise, or await/Promise.all() a thenable,
77 // then this intermediate Promise is created. We use this as our await point
78 if (trigger === undefined) {
79 // We don't track awaits on things that started outside our tracked scope.
80 return;
81 }
82 // If the thing we're waiting on is another Await we still track that sequence
83 // so that we can later pick the best stack trace in user space.
84 let stack = null;
85 let promiseRef: WeakRef<Promise<any>>;
86 if (
87 trigger.stack !== null &&
88 (trigger.tag === AWAIT_NODE ||
89 trigger.tag === UNRESOLVED_AWAIT_NODE)
90 ) {
91 // We already had a stack for an await. In a chain of awaits we'll only need one good stack.
92 // We mark it with an empty stack to signal to any await on this await that we have a stack.
93 stack = emptyStack;
94 if (resource._debugInfo !== undefined) {
95 // We may need to forward this debug info at the end so we need to retain this promise.
96 promiseRef = new WeakRef((resource: Promise<any>));
97 } else {
98 // Otherwise, we can just refer to the inner one since that's the one we'll log anyway.
99 promiseRef = trigger.promise;
100 }
101 } else {
102 promiseRef = new WeakRef((resource: Promise<any>));
103 const request = resolveRequest();
104 if (request === null) {
105 // We don't collect stacks for awaits that weren't in the scope of a specific render.
106 } else {
107 stack = parseStackTracePrivate(new Error(), 5);
108 if (stack !== null && !isAwaitInUserspace(request, stack)) {
109 // If this await was not done directly in user space, then clear the stack. We won't use it
110 // anyway. This lets future awaits on this await know that we still need to get their stacks
111 // until we find one in user space.
112 stack = null;
113 }
114 }
115 }
116 const current = pendingOperations.get(currentAsyncId);
117 node = ({
118 tag: UNRESOLVED_AWAIT_NODE,
119 owner: resolveOwner(),
120 stack: stack,
121 start: performance.now(),
122 end: -1.1, // set when resolved.

Callers 8

renderLazyComponentFunction · 0.70
retryNodeFunction · 0.70
renderElementFunction · 0.70
renderModelDestructiveFunction · 0.70
useReducerFunction · 0.70

Calls 6

resolveRequestFunction · 0.90
isAwaitInUserspaceFunction · 0.90
resolveOwnerFunction · 0.90
parseStackTracePrivateFunction · 0.85
setMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected