Skip to content

Conversation

@gaearon
Copy link
Collaborator

@gaearon gaearon commented Jul 12, 2018

  1. Fixes getComponentName() for a few cases where it was incorrectly reading the type (a482fb4). We didn't notice because we rarely call it for anything other than user-defined components.
  2. Changes its signature to require just the type alone rather than the Fiber. This might seem like it makes the calling code longer. However we often already have the type destructured anyway when we call it. I also remember from writing some of that code that it was awkward to always have to pass a Fiber around when I only needed a type.
  3. This lets us remove two ad-hoc forks of getComponentName() that don't handle all the cases it does.

? type
: typeof type === 'function' ? type.displayName || type.name : null;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One fork down.

return type.displayName || type.name || 'Unknown';
}
};

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two forks down.

false,
'Received an unexpected object in getComponentName(). ' +
'This is likely a bug in React. Please file an issue.',
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Protect against passing Fibers by habit.

return 'ReactPortal';
return 'Portal';
case REACT_PROFILER_TYPE:
return `Profiler(${fiber.pendingProps.id})`;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you feel strongly about keeping this, I can add an optional props argument. I'm not sure this is important. I like that having a type is sufficient (which lets us use this utility in SSR, for example).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what this is used for and I see no comments anywhere from before?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's fine. I was just following the forward ref precedent. I think it's mildly useful, but not enough to warrant making the callsites more complicated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It provided a slightly more detailed entry in the component stack for Profiler components. I don't think it's very important, and I think we can drop this.

@pull-bot
Copy link

pull-bot commented Jul 12, 2018

ReactDOM: size: -0.0%, gzip: -0.0%

Details of bundled changes.

Comparing: 32f6f25...71590b7

react

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react.development.js -0.8% -0.1% 57.02 KB 56.54 KB 15.87 KB 15.86 KB UMD_DEV
react.development.js -0.9% -0.1% 51.21 KB 50.73 KB 14.04 KB 14.03 KB NODE_DEV
React-dev.js -1.0% -0.1% 48.83 KB 48.36 KB 13.31 KB 13.3 KB FB_WWW_DEV

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js 0.0% +0.1% 638.31 KB 638.56 KB 149.52 KB 149.62 KB UMD_DEV
react-dom.production.min.js -0.0% -0.0% 95.51 KB 95.5 KB 30.91 KB 30.9 KB UMD_PROD
react-dom.development.js 0.0% +0.1% 634.43 KB 634.69 KB 148.35 KB 148.44 KB NODE_DEV
react-dom.production.min.js -0.0% -0.0% 95.49 KB 95.48 KB 30.41 KB 30.4 KB NODE_PROD
react-dom-server.browser.development.js +1.2% +1.1% 100.82 KB 102.01 KB 26.72 KB 27.01 KB UMD_DEV
react-dom-server.browser.production.min.js 🔺+3.0% 🔺+2.2% 14.81 KB 15.25 KB 5.69 KB 5.81 KB UMD_PROD
react-dom-server.browser.development.js +1.2% +1.2% 96.95 KB 98.14 KB 25.77 KB 26.08 KB NODE_DEV
react-dom-server.browser.production.min.js 🔺+3.0% 🔺+2.3% 14.71 KB 15.15 KB 5.62 KB 5.75 KB NODE_PROD
react-dom-server.node.development.js +1.2% +1.1% 98.87 KB 100.06 KB 26.31 KB 26.61 KB NODE_DEV
react-dom-server.node.production.min.js 🔺+2.9% 🔺+2.2% 15.51 KB 15.96 KB 5.92 KB 6.05 KB NODE_PROD
ReactDOM-dev.js +0.1% +0.1% 640.7 KB 641.03 KB 146.68 KB 146.78 KB FB_WWW_DEV
ReactDOM-prod.js 0.0% -0.0% 276.29 KB 276.3 KB 51.69 KB 51.67 KB FB_WWW_PROD
ReactDOMServer-dev.js +1.3% +1.2% 98.04 KB 99.27 KB 25.31 KB 25.62 KB FB_WWW_DEV
ReactDOMServer-prod.js 🔺+2.8% 🔺+2.0% 31.97 KB 32.87 KB 7.78 KB 7.94 KB FB_WWW_PROD
react-dom.profiling.min.js -0.0% -0.0% 96.58 KB 96.57 KB 30.81 KB 30.8 KB NODE_PROFILING
ReactDOM-profiling.js 0.0% -0.0% 279.29 KB 279.3 KB 52.35 KB 52.33 KB FB_WWW_PROFILING

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-test-renderer.development.js +0.1% +0.1% 359.95 KB 360.2 KB 78.77 KB 78.86 KB UMD_DEV
react-test-renderer.production.min.js -0.0% -0.1% 48.57 KB 48.56 KB 14.97 KB 14.95 KB UMD_PROD
react-test-renderer.development.js +0.1% +0.1% 356.07 KB 356.32 KB 77.81 KB 77.9 KB NODE_DEV
react-test-renderer.production.min.js -0.0% -0.1% 48.28 KB 48.27 KB 14.79 KB 14.77 KB NODE_PROD
react-test-renderer-shallow.development.js +7.7% +6.8% 21.67 KB 23.34 KB 5.91 KB 6.31 KB UMD_DEV
react-test-renderer-shallow.development.js +9.9% +11.5% 16.86 KB 18.53 KB 4.61 KB 5.14 KB NODE_DEV
react-test-renderer-shallow.production.min.js -0.3% -1.1% 7.79 KB 7.77 KB 2.59 KB 2.56 KB NODE_PROD
ReactTestRenderer-dev.js +0.1% +0.1% 360.05 KB 360.37 KB 76.67 KB 76.77 KB FB_WWW_DEV
ReactShallowRenderer-dev.js +1.9% +2.5% 16.53 KB 16.84 KB 4.3 KB 4.41 KB FB_WWW_DEV

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js +0.1% +0.1% 423.08 KB 423.33 KB 95.32 KB 95.41 KB UMD_DEV
react-art.production.min.js -0.0% -0.1% 82.68 KB 82.67 KB 25.49 KB 25.47 KB UMD_PROD
react-art.development.js +0.1% +0.1% 355.63 KB 355.88 KB 78.26 KB 78.34 KB NODE_DEV
react-art.production.min.js -0.0% 🔺+0.1% 47.66 KB 47.65 KB 14.85 KB 14.87 KB NODE_PROD
ReactART-dev.js +0.1% +0.1% 344.74 KB 345.07 KB 73.04 KB 73.14 KB FB_WWW_DEV
ReactART-prod.js 0.0% -0.0% 147.23 KB 147.23 KB 24.93 KB 24.92 KB FB_WWW_PROD

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-dev.js +0.1% +0.1% 478.31 KB 478.6 KB 105.71 KB 105.82 KB RN_FB_DEV
ReactNativeRenderer-prod.js 0.0% -0.0% 212.26 KB 212.27 KB 36.92 KB 36.91 KB RN_FB_PROD
ReactNativeRenderer-dev.js +0.1% +0.1% 478.04 KB 478.34 KB 105.65 KB 105.76 KB RN_OSS_DEV
ReactNativeRenderer-prod.js 0.0% -0.1% 202.11 KB 202.11 KB 35.34 KB 35.32 KB RN_OSS_PROD
ReactFabric-dev.js +0.1% +0.1% 468.53 KB 468.83 KB 103.29 KB 103.39 KB RN_FB_DEV
ReactFabric-prod.js 0.0% -0.0% 193.03 KB 193.03 KB 33.76 KB 33.74 KB RN_FB_PROD
ReactFabric-dev.js +0.1% +0.1% 468.57 KB 468.86 KB 103.3 KB 103.41 KB RN_OSS_DEV
ReactFabric-prod.js 0.0% -0.0% 193.07 KB 193.07 KB 33.77 KB 33.76 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js 0.0% -0.0% 205.23 KB 205.23 KB 36.02 KB 36 KB RN_OSS_PROFILING
ReactFabric-profiling.js 0.0% -0.0% 195.84 KB 195.84 KB 34.38 KB 34.36 KB RN_OSS_PROFILING
ReactNativeRenderer-profiling.js 0.0% -0.0% 215.35 KB 215.35 KB 37.61 KB 37.6 KB RN_FB_PROFILING
ReactFabric-profiling.js 0.0% -0.0% 195.8 KB 195.8 KB 34.36 KB 34.34 KB RN_FB_PROFILING

Generated by 🚫 dangerJS

Copy link
Contributor

@bvaughn bvaughn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice cleanup! Thanks for removing those forks.

return 'ReactPortal';
return 'Portal';
case REACT_PROFILER_TYPE:
return `Profiler(${fiber.pendingProps.id})`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's fine. I was just following the forward ref precedent. I think it's mildly useful, but not enough to warrant making the callsites more complicated.

@bvaughn bvaughn merged commit e6076ec into facebook:master Jul 12, 2018
@gaearon gaearon deleted the getcomponname branch July 12, 2018 14:32
NMinhNguyen referenced this pull request in enzymejs/react-shallow-renderer Jan 29, 2020
* Fix getComponentName() for types with nested $$typeof

* Temporarily remove Profiler ID from messages

* Change getComponentName() signature to take just type

It doesn't actually need the whole Fiber.

* Remove getComponentName() forks in isomorphic and SSR

* Remove unnecessary .type access where we already have a type

* Remove unused type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants