Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Flight] Track Owner on AsyncLocalStorage When Available (#28807)
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.
- Loading branch information
1 parent
0a0a3af
commit d5c3034
Showing
15 changed files
with
189 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/react-server/src/flight/ReactFlightCurrentOwner.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* 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 type {ReactComponentInfo} from 'shared/ReactTypes'; | ||
|
||
import { | ||
supportsComponentStorage, | ||
componentStorage, | ||
} from '../ReactFlightServerConfig'; | ||
|
||
let currentOwner: ReactComponentInfo | null = null; | ||
|
||
export function setCurrentOwner(componentInfo: null | ReactComponentInfo) { | ||
currentOwner = componentInfo; | ||
} | ||
|
||
export function resolveOwner(): null | ReactComponentInfo { | ||
if (currentOwner) return currentOwner; | ||
if (supportsComponentStorage) { | ||
const owner = componentStorage.getStore(); | ||
if (owner) return owner; | ||
} | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.