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

Adds displayName to EventComponent and EventTarget #15268

Merged
merged 6 commits into from
Apr 3, 2019

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Mar 30, 2019

Follow up to #15267. Adds the displayName field to EventComponent and EventTarget objects to provide this information from components using the experimental event API. This also adds support for the event API components showing in getComponentName.

Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

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

Any reason we don’t do it the way we normally do? By adding to getComponentName. Tools like DevTools can vendor that code.

@trueadm
Copy link
Contributor Author

trueadm commented Mar 30, 2019

@gaearon I could add support for this in getComponentName too, but the names aren't internal to React and are user-defined. Given the modules live in user-space, I thought this would be the simplest approach.

@sizebot
Copy link

sizebot commented Mar 30, 2019

React: size: 0.0%, gzip: -0.0%

ReactDOM: size: 🔺+0.2%, gzip: 🔺+0.2%

Details of bundled changes.

Comparing: 6a1e6b2...3cc723a

react

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react.development.js +0.7% +0.5% 101.38 KB 102.08 KB 26.3 KB 26.43 KB UMD_DEV
react.production.min.js 0.0% -0.0% 12.04 KB 12.04 KB 4.62 KB 4.62 KB UMD_PROD
react.development.js +1.1% +0.7% 63.92 KB 64.63 KB 17.2 KB 17.31 KB NODE_DEV
React-dev.js +1.1% +0.7% 62.25 KB 62.91 KB 16.5 KB 16.62 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.1% +0.1% 814.15 KB 814.76 KB 184.02 KB 184.14 KB UMD_DEV
react-dom.production.min.js 🔺+0.2% 🔺+0.2% 105.11 KB 105.31 KB 33.97 KB 34.03 KB UMD_PROD
react-dom.profiling.min.js +0.2% +0.2% 108.08 KB 108.29 KB 34.61 KB 34.69 KB UMD_PROFILING
react-dom.development.js +0.1% +0.1% 808.54 KB 809.15 KB 182.43 KB 182.54 KB NODE_DEV
react-dom.production.min.js 🔺+0.2% 🔺+0.1% 105.08 KB 105.29 KB 33.47 KB 33.52 KB NODE_PROD
react-dom.profiling.min.js +0.2% +0.2% 108.18 KB 108.39 KB 34.08 KB 34.14 KB NODE_PROFILING
ReactDOM-dev.js +0.1% +0.1% 833.38 KB 833.94 KB 184.1 KB 184.2 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.1% 🔺+0.1% 331.29 KB 331.72 KB 60.97 KB 61.06 KB FB_WWW_PROD
ReactDOM-profiling.js +0.1% +0.1% 337.74 KB 338.17 KB 62.34 KB 62.42 KB FB_WWW_PROFILING
react-dom-unstable-fire.development.js +0.1% +0.1% 814.5 KB 815.11 KB 184.17 KB 184.29 KB UMD_DEV
react-dom-unstable-fire.production.min.js 🔺+0.2% 🔺+0.2% 105.12 KB 105.33 KB 33.98 KB 34.04 KB UMD_PROD
react-dom-unstable-fire.profiling.min.js +0.2% +0.2% 108.1 KB 108.3 KB 34.61 KB 34.7 KB UMD_PROFILING
react-dom-unstable-fire.development.js +0.1% +0.1% 808.89 KB 809.5 KB 182.57 KB 182.68 KB NODE_DEV
react-dom-unstable-fire.production.min.js 🔺+0.2% 🔺+0.1% 105.1 KB 105.3 KB 33.48 KB 33.53 KB NODE_PROD
react-dom-unstable-fire.profiling.min.js +0.2% +0.2% 108.2 KB 108.4 KB 34.08 KB 34.15 KB NODE_PROFILING
ReactFire-dev.js +0.1% +0.1% 832.59 KB 833.15 KB 184.03 KB 184.13 KB FB_WWW_DEV
ReactFire-prod.js 🔺+0.1% 🔺+0.1% 319.95 KB 320.38 KB 58.62 KB 58.69 KB FB_WWW_PROD
ReactFire-profiling.js +0.1% +0.1% 326.35 KB 326.78 KB 60.02 KB 60.09 KB FB_WWW_PROFILING
react-dom-test-utils.development.js 0.0% 0.0% 47.21 KB 47.21 KB 12.91 KB 12.91 KB NODE_DEV
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.74 KB 60.74 KB 15.84 KB 15.84 KB UMD_DEV
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.41 KB 60.41 KB 15.72 KB 15.71 KB NODE_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 10.42 KB 10.42 KB 3.57 KB 3.56 KB NODE_PROD
react-dom-server.browser.development.js +0.5% +0.3% 134.78 KB 135.49 KB 35.51 KB 35.62 KB UMD_DEV
react-dom-server.browser.production.min.js 🔺+1.0% 🔺+0.7% 19.05 KB 19.24 KB 7.18 KB 7.24 KB UMD_PROD
react-dom-server.browser.development.js +0.5% +0.4% 130.91 KB 131.62 KB 34.57 KB 34.69 KB NODE_DEV
react-dom-server.browser.production.min.js 🔺+1.0% 🔺+0.8% 18.98 KB 19.17 KB 7.17 KB 7.23 KB NODE_PROD
ReactDOMServer-dev.js +0.5% +0.3% 133.22 KB 133.88 KB 34.32 KB 34.43 KB FB_WWW_DEV
ReactDOMServer-prod.js 🔺+0.9% 🔺+0.8% 46.19 KB 46.62 KB 10.63 KB 10.71 KB FB_WWW_PROD
react-dom-server.node.development.js +0.5% +0.4% 132.86 KB 133.56 KB 35.12 KB 35.24 KB NODE_DEV
react-dom-server.node.production.min.js 🔺+1.0% 🔺+0.7% 19.84 KB 20.03 KB 7.48 KB 7.53 KB NODE_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.66 KB 3.66 KB 1.45 KB 1.45 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.1% 1.21 KB 1.21 KB 706 B 705 B UMD_PROD
react-dom-unstable-fizz.node.development.js 0.0% +0.1% 3.74 KB 3.74 KB 1.43 KB 1.43 KB NODE_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.2% 1.1 KB 1.1 KB 666 B 667 B NODE_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js +0.1% +0.1% 568.43 KB 569.13 KB 122.57 KB 122.71 KB UMD_DEV
react-art.production.min.js 🔺+0.2% 🔺+0.2% 96.8 KB 97.01 KB 29.68 KB 29.75 KB UMD_PROD
react-art.development.js +0.1% +0.1% 499.34 KB 500.04 KB 105.21 KB 105.33 KB NODE_DEV
react-art.production.min.js 🔺+0.3% 🔺+0.3% 61.81 KB 62.01 KB 18.92 KB 18.96 KB NODE_PROD
ReactART-dev.js +0.1% +0.1% 509.24 KB 509.9 KB 104.48 KB 104.59 KB FB_WWW_DEV
ReactART-prod.js 🔺+0.2% 🔺+0.2% 197.31 KB 197.74 KB 33.38 KB 33.45 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% 630.49 KB 631.15 KB 134.33 KB 134.44 KB RN_FB_DEV
ReactNativeRenderer-prod.js 🔺+0.2% 🔺+0.2% 246.06 KB 246.58 KB 43.03 KB 43.13 KB RN_FB_PROD
ReactNativeRenderer-profiling.js +0.2% +0.2% 252.31 KB 252.82 KB 44.38 KB 44.48 KB RN_FB_PROFILING
ReactNativeRenderer-dev.js +0.1% +0.1% 630.4 KB 631.06 KB 134.29 KB 134.41 KB RN_OSS_DEV
ReactNativeRenderer-prod.js 🔺+0.2% 🔺+0.2% 246.07 KB 246.59 KB 43.03 KB 43.13 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js +0.2% +0.2% 252.33 KB 252.84 KB 44.38 KB 44.47 KB RN_OSS_PROFILING
ReactFabric-dev.js +0.1% +0.1% 619.34 KB 620 KB 131.68 KB 131.79 KB RN_FB_DEV
ReactFabric-prod.js 🔺+0.2% 🔺+0.2% 239.46 KB 239.98 KB 41.77 KB 41.86 KB RN_FB_PROD
ReactFabric-profiling.js +0.2% +0.2% 244.8 KB 245.32 KB 43.09 KB 43.18 KB RN_FB_PROFILING
ReactFabric-dev.js +0.1% +0.1% 619.25 KB 619.91 KB 131.63 KB 131.75 KB RN_OSS_DEV
ReactFabric-prod.js 🔺+0.2% 🔺+0.2% 239.47 KB 239.99 KB 41.76 KB 41.86 KB RN_OSS_PROD
ReactFabric-profiling.js +0.2% +0.2% 244.81 KB 245.33 KB 43.08 KB 43.18 KB RN_OSS_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% 510.07 KB 510.68 KB 107.16 KB 107.24 KB UMD_DEV
react-test-renderer.production.min.js 🔺+0.3% 🔺+0.4% 62.75 KB 62.96 KB 19.12 KB 19.2 KB UMD_PROD
react-test-renderer.development.js +0.1% +0.1% 505.59 KB 506.2 KB 106 KB 106.09 KB NODE_DEV
react-test-renderer.production.min.js 🔺+0.3% 🔺+0.3% 62.44 KB 62.64 KB 18.96 KB 19.01 KB NODE_PROD
ReactTestRenderer-dev.js +0.1% +0.1% 516.73 KB 517.29 KB 105.77 KB 105.85 KB FB_WWW_DEV
react-test-renderer-shallow.development.js +2.2% +1.6% 38.98 KB 39.85 KB 9.81 KB 9.96 KB UMD_DEV
react-test-renderer-shallow.production.min.js 🔺+2.4% 🔺+2.4% 11.42 KB 11.7 KB 3.5 KB 3.59 KB UMD_PROD
react-test-renderer-shallow.development.js +2.6% +2.0% 33.2 KB 34.08 KB 8.41 KB 8.58 KB NODE_DEV
react-test-renderer-shallow.production.min.js 🔺+2.4% 🔺+2.0% 11.61 KB 11.89 KB 3.63 KB 3.7 KB NODE_PROD
ReactShallowRenderer-dev.js +2.5% +2.0% 32.98 KB 33.82 KB 8.24 KB 8.4 KB FB_WWW_DEV

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js +0.1% +0.1% 499.54 KB 500.24 KB 104.03 KB 104.14 KB NODE_DEV
react-reconciler.production.min.js 🔺+0.3% 🔺+0.3% 62.99 KB 63.2 KB 18.74 KB 18.79 KB NODE_PROD
react-reconciler-persistent.development.js +0.1% +0.1% 497.43 KB 498.13 KB 103.16 KB 103.28 KB NODE_DEV
react-reconciler-persistent.production.min.js 🔺+0.3% 🔺+0.2% 63 KB 63.21 KB 18.75 KB 18.79 KB NODE_PROD
react-reconciler-reflection.development.js +5.5% +3.2% 15.79 KB 16.66 KB 4.91 KB 5.07 KB NODE_DEV

Generated by 🚫 dangerJS

@bvaughn
Copy link
Contributor

bvaughn commented Mar 30, 2019

Any reason we don’t do it the way we normally do? By adding to getComponentName. Tools like DevTools can vendor that code.

The problem with this, as described in #15267, is that there isn't sufficient information for EventComponent tags to identify them any more specifically. This would hamstring DevTools ability to later show which events a component is subscribed to.

I would normally have suggested we maybe add an enum or something to the EventComponent target too, except as Dominic points out- we expect to support third party events. We could still use an enum/tag, and just allow for an optional displayName for third part events (like we do for components).

Technically we don't need the displayName attribute (or any change) for the EventTarget though, since we can uniquely identify that by the elementType.type. Although it sounds like the plan is to support third party targets too, in which case- we would want to support an optional displayName on those as well.

@trueadm
Copy link
Contributor Author

trueadm commented Mar 30, 2019

Yep, as Brian said, the issue here is third party usage. I've updated the getComponentName implementation to understand the built-in REACT_EVENT_TARGET_TOUCH_HIT, otherwise it falls back to using displayName (which is now optional).

@trueadm
Copy link
Contributor Author

trueadm commented Apr 2, 2019

I can confirm after testing locally that we want to keep the getComponentName logic. It does indeed help debugging component stack traces, otherwise you get unknown appear for the event API components.

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.

Would be nice to have test coverage for the REACT_EVENT_TARGET_TYPE type (falling back to displayName etc.)

Overall this seems okay to me, given the goals. Couple of minor suggestions but accepting to unblock later.

packages/shared/getComponentName.js Outdated Show resolved Hide resolved
@trueadm trueadm merged commit 89064fe into facebook:master Apr 3, 2019
@trueadm trueadm deleted the add-display-name branch April 3, 2019 11:24
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.

6 participants