Skip to content

Commit 2ba9670

Browse files
committed
Enable hooks globally when the flag is on
This is a DEV only feature.
1 parent 72a432c commit 2ba9670

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

packages/react-server/src/ReactFlightServer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ import {
7070
requestStorage,
7171
prepareHostDispatcher,
7272
createHints,
73+
initAsyncDebugInfo,
7374
} from './ReactFlightServerConfig';
7475

7576
import {
@@ -117,6 +118,8 @@ import binaryToComparableString from 'shared/binaryToComparableString';
117118

118119
import {SuspenseException, getSuspendedThenable} from './ReactFlightThenable';
119120

121+
initAsyncDebugInfo();
122+
120123
const ObjectPrototype = Object.prototype;
121124

122125
type JSONValue =

packages/react-server/src/ReactFlightServerConfigDebugNode.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,25 @@
88
*/
99

1010
import {createAsyncHook} from './ReactFlightServerConfig';
11+
import {enableAsyncDebugInfo} from 'shared/ReactFeatureFlags';
12+
13+
// Initialize the tracing of async operations.
14+
// We do this globally since the async work can potentially eagerly
15+
// start before the first request and once requests start they can interleave.
16+
// In theory we could enable and disable using a ref count of active requests
17+
// but given that typically this is just a live server, it doesn't really matter.
18+
export function initAsyncDebugInfo(): void {
19+
if (__DEV__ && enableAsyncDebugInfo) {
20+
createAsyncHook({
21+
init(asyncId: number, type: string, triggerAsyncId: number): void {
22+
// TODO
23+
},
24+
promiseResolve(asyncId: number): void {
25+
// TODO
26+
},
27+
destroy(asyncId: number): void {
28+
// TODO
29+
},
30+
}).enable();
31+
}
32+
}

packages/react-server/src/ReactFlightServerConfigDebugNoop.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
*/
99

1010
// Exported for runtimes that don't support Promise instrumentation for async debugging.
11+
export function initAsyncDebugInfo(): void {}

0 commit comments

Comments
 (0)