Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Change Profiler prop names #2699

Merged
merged 3 commits into from Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@

- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott
- [react] feat: Update peer dependencies for `react` and `react-dom` (#2694)
- [react] ref: Change Profiler prop names (#2699)

## 5.18.0

Expand Down
16 changes: 8 additions & 8 deletions packages/react/src/profiler.tsx
Expand Up @@ -83,9 +83,9 @@ export type ProfilerProps = {
// in certain environments.
disabled?: boolean;
// If time component is on page should be displayed as spans. True by default.
hasRenderSpan?: boolean;
includeRender?: boolean;
// If component updates should be displayed as spans. True by default.
hasUpdateSpan?: boolean;
includeUpdates?: boolean;
// props given to component being profiled.
updateProps: { [key: string]: any };
};
Expand All @@ -104,8 +104,8 @@ class Profiler extends React.Component<ProfilerProps> {

public static defaultProps: Partial<ProfilerProps> = {
disabled: false,
hasRenderSpan: true,
hasUpdateSpan: true,
includeRender: true,
includeUpdates: true,
};

public constructor(props: ProfilerProps) {
Expand All @@ -130,11 +130,11 @@ class Profiler extends React.Component<ProfilerProps> {
this.mountActivity = null;
}

public componentDidUpdate({ updateProps, hasUpdateSpan = true }: ProfilerProps): void {
public componentDidUpdate({ updateProps, includeUpdates = true }: ProfilerProps): void {
// Only generate an update span if hasUpdateSpan is true, if there is a valid mountSpan,
// and if the updateProps have changed. It is ok to not do a deep equality check here as it is expensive.
// We are just trying to give baseline clues for further investigation.
if (hasUpdateSpan && this.mountSpan && updateProps !== this.props.updateProps) {
if (includeUpdates && this.mountSpan && updateProps !== this.props.updateProps) {
// See what props haved changed between the previous props, and the current props. This is
// set as data on the span. We just store the prop keys as the values could be potenially very large.
const changedProps = Object.keys(updateProps).filter(k => updateProps[k] !== this.props.updateProps[k]);
Expand All @@ -158,9 +158,9 @@ class Profiler extends React.Component<ProfilerProps> {
// If a component is unmounted, we can say it is no longer on the screen.
// This means we can finish the span representing the component render.
public componentWillUnmount(): void {
const { name, hasRenderSpan = true } = this.props;
const { name, includeRender = true } = this.props;

if (this.mountSpan && hasRenderSpan) {
if (this.mountSpan && includeRender) {
// If we were able to obtain the spanId of the mount activity, we should set the
// next activity as a child to the component mount activity.
this.mountSpan.startChild({
Expand Down
4 changes: 2 additions & 2 deletions packages/react/test/profiler.test.tsx
Expand Up @@ -120,7 +120,7 @@ describe('withProfiler', () => {
});

it('is not created if hasRenderSpan is false', () => {
const ProfiledComponent = withProfiler(() => <h1>Testing</h1>, { hasRenderSpan: false });
const ProfiledComponent = withProfiler(() => <h1>Testing</h1>, { includeRender: false });
expect(mockStartChild).toHaveBeenCalledTimes(0);

const component = render(<ProfiledComponent />);
Expand Down Expand Up @@ -165,7 +165,7 @@ describe('withProfiler', () => {

it('does not get created if hasUpdateSpan is false', () => {
const ProfiledComponent = withProfiler((props: { num: number }) => <div>{props.num}</div>, {
hasUpdateSpan: false,
includeUpdates: false,
});
const { rerender } = render(<ProfiledComponent num={0} />);
expect(mockStartChild).toHaveBeenCalledTimes(0);
Expand Down