Skip to content

Commit

Permalink
Enable hooks globally when the flag is on
Browse files Browse the repository at this point in the history
This is a DEV only feature.
  • Loading branch information
sebmarkbage committed Dec 15, 2023
1 parent 72a432c commit 2ba9670
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import {
requestStorage,
prepareHostDispatcher,
createHints,
initAsyncDebugInfo,
} from './ReactFlightServerConfig';

import {
Expand Down Expand Up @@ -117,6 +118,8 @@ import binaryToComparableString from 'shared/binaryToComparableString';

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

initAsyncDebugInfo();

const ObjectPrototype = Object.prototype;

type JSONValue =
Expand Down
22 changes: 22 additions & 0 deletions packages/react-server/src/ReactFlightServerConfigDebugNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,25 @@
*/

import {createAsyncHook} from './ReactFlightServerConfig';
import {enableAsyncDebugInfo} from 'shared/ReactFeatureFlags';

// Initialize the tracing of async operations.
// We do this globally since the async work can potentially eagerly
// start before the first request and once requests start they can interleave.
// In theory we could enable and disable using a ref count of active requests
// but given that typically this is just a live server, it doesn't really matter.
export function initAsyncDebugInfo(): void {
if (__DEV__ && enableAsyncDebugInfo) {
createAsyncHook({
init(asyncId: number, type: string, triggerAsyncId: number): void {
// TODO
},
promiseResolve(asyncId: number): void {
// TODO
},
destroy(asyncId: number): void {
// TODO
},
}).enable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
*/

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

0 comments on commit 2ba9670

Please sign in to comment.