Skip to content

Commit

Permalink
Improve display names of root components in React Profiler
Browse files Browse the repository at this point in the history
Summary:
Changelog:
[General][Added] - Added `debugName` parameter to `renderApplication` to use as the display name for the React root tree

Reviewed By: rickhanlonii

Differential Revision: D26637787

fbshipit-source-id: 3ddc037573f4434101a9d3dcb5592a127193481c
  • Loading branch information
rubennorte authored and facebook-github-bot committed Feb 25, 2021
1 parent 468bc62 commit eeb36f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions Libraries/ReactNative/AppRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const AppRegistry = {
showArchitectureIndicator,
scopedPerformanceLogger,
appKey === 'LogBox',
appKey,
);
},
};
Expand Down
13 changes: 12 additions & 1 deletion Libraries/ReactNative/renderApplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ function renderApplication<Props: Object>(
showArchitectureIndicator?: boolean,
scopedPerformanceLogger?: IPerformanceLogger,
isLogBox?: boolean,
debugName?: string,
) {
invariant(rootTag, 'Expect to have a valid rootTag, instead got ', rootTag);

const performanceLogger = scopedPerformanceLogger ?? GlobalPerformanceLogger;

const renderable = (
let renderable = (
<PerformanceLoggerContext.Provider value={performanceLogger}>
<AppContainer
rootTag={rootTag}
Expand All @@ -47,6 +48,16 @@ function renderApplication<Props: Object>(
</PerformanceLoggerContext.Provider>
);

if (__DEV__ && debugName) {
const RootComponentWithMeaningfulName = ({children}) => children;
RootComponentWithMeaningfulName.displayName = `${debugName}(RootComponent)`;
renderable = (
<RootComponentWithMeaningfulName>
{renderable}
</RootComponentWithMeaningfulName>
);
}

performanceLogger.startTimespan('renderApplication_React_render');
performanceLogger.setExtra('usedReactFabric', fabric ? '1' : '0');

Expand Down

0 comments on commit eeb36f4

Please sign in to comment.