mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
d5c303427e
Stacked on #28798. Add another AsyncLocalStorage to the FlightServerConfig. This context tracks data on a per component level. Currently the only thing we track is the owner in DEV. AsyncLocalStorage around each component comes with a performance cost so we only do it DEV. It's not generally a particularly safe operation because you can't necessarily associate side-effects with a component based on execution scope. It can be a lazy initializer or cache():ed code etc. We also don't support string refs anymore for a reason. However, it's good enough for optional dev only information like the owner.
28 lines
991 B
JavaScript
28 lines
991 B
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
*/
|
|
|
|
import {AsyncLocalStorage} from 'async_hooks';
|
|
|
|
import type {Request} from 'react-server/src/ReactFlightServer';
|
|
import type {ReactComponentInfo} from 'shared/ReactTypes';
|
|
|
|
export * from 'react-server-dom-esm/src/ReactFlightServerConfigESMBundler';
|
|
export * from 'react-dom-bindings/src/server/ReactFlightServerConfigDOM';
|
|
|
|
export const supportsRequestStorage = true;
|
|
export const requestStorage: AsyncLocalStorage<Request | void> =
|
|
new AsyncLocalStorage();
|
|
|
|
export const supportsComponentStorage = __DEV__;
|
|
export const componentStorage: AsyncLocalStorage<ReactComponentInfo | void> =
|
|
supportsComponentStorage ? new AsyncLocalStorage() : (null: any);
|
|
|
|
export {createHook as createAsyncHook, executionAsyncId} from 'async_hooks';
|
|
export * from '../ReactFlightServerConfigDebugNode';
|