Skip to content

Commit da1900d

Browse files
committed
Wrap fake ReactPromise in a real Promise to allow it to forward debugInfo
1 parent 30b12a3 commit da1900d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

packages/react-client/src/ReactFlightClient.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,27 @@ ReactPromise.prototype.then = function <T>(
266266
initializeModuleChunk(chunk);
267267
break;
268268
}
269+
if (__DEV__ && enableAsyncDebugInfo) {
270+
// Because only native Promises get picked up when we're awaiting we need to wrap
271+
// this in a native Promise in DEV. This means that these callbacks are no longer sync
272+
// but the lazy initialization is still sync and the .value can be inspected after,
273+
// allowing it to be read synchronously anyway.
274+
const resolveCallback = resolve;
275+
const rejectCallback = reject;
276+
const wrapperPromise: Promise<T> = new Promise((res, rej) => {
277+
resolve = value => {
278+
// $FlowFixMe
279+
wrapperPromise._debugInfo = this._debugInfo;
280+
res(value);
281+
};
282+
reject = reason => {
283+
// $FlowFixMe
284+
wrapperPromise._debugInfo = this._debugInfo;
285+
rej(reason);
286+
};
287+
});
288+
wrapperPromise.then(resolveCallback, rejectCallback);
289+
}
269290
// The status might have changed after initialization.
270291
switch (chunk.status) {
271292
case INITIALIZED:

0 commit comments

Comments
 (0)