Skip to content

Conversation

elicwhite
Copy link
Member

@elicwhite elicwhite commented Nov 9, 2019

In React Native we want to try making the event target and currentTarget equal to a React Instance instead of a reactTag. This is needed to clean up some of the logic in ScrollResponder, TextInput, and TextInputState. This also will let these core components become compatible with Fabric.

There is precedent here as target and currentTarget on ReactDOM are HTMLElements that have .focus and .blur methods for example.

This API is behind a FeatureFlag that we can use to run an experiment internally.

It is worth noting that this will be a breaking change to ReactNative when rolled out. When searching the Facebook codebase I surprisingly found essentially no callsites referencing target/currentTarget except for our core components. That gives me some confidence that this breaking change is acceptable and doesn't require a different approach like putting the instance in a different key on the event.

The purpose of this experiment is to validate that assumption.

Note: This PR doesn't have any logic to change currentTarget. I haven't investigated that one yet to know how to change that. Is that reasonable to do in a separate PR or do you think it should be part of the same one?

Test Plan

I did a local sync and ran these changes in the Facebook repo and tested this in both Fabric and Paper with the flag turned on and off. ScrollResponder and TextInput logic didn't throw any exceptions, was correctly handling target being both a number and instance.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 9, 2019

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 43fad6e:

Sandbox Source
sad-merkle-k76g4 Configuration

@sizebot
Copy link

sizebot commented Nov 9, 2019

Details of bundled changes.

Comparing: 01bce8c...43fad6e

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-dev.js 0.0% 0.0% 748.6 KB 748.85 KB 158.38 KB 158.42 KB RN_FB_DEV
ReactNativeRenderer-prod.js 🔺+0.1% 🔺+0.1% 277.22 KB 277.36 KB 47.36 KB 47.42 KB RN_FB_PROD
ReactNativeRenderer-profiling.js 0.0% +0.1% 286.18 KB 286.32 KB 49.08 KB 49.14 KB RN_FB_PROFILING
ReactFabric-dev.js 0.0% 0.0% 754.1 KB 754.4 KB 159.2 KB 159.25 KB RN_FB_DEV
ReactFabric-prod.js 🔺+0.1% 🔺+0.1% 268.91 KB 269.07 KB 45.94 KB 46 KB RN_FB_PROD
ReactFabric-profiling.js +0.1% +0.1% 279.04 KB 279.21 KB 47.81 KB 47.88 KB RN_FB_PROFILING
ReactNativeRenderer-dev.js 0.0% 0.0% 748.45 KB 748.68 KB 158.29 KB 158.34 KB RN_OSS_DEV
ReactNativeRenderer-prod.js -0.0% -0.0% 277.26 KB 277.21 KB 47.38 KB 47.37 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js -0.0% -0.0% 286.22 KB 286.17 KB 49.11 KB 49.09 KB RN_OSS_PROFILING
ReactFabric-dev.js 0.0% 0.0% 753.94 KB 754.21 KB 159.13 KB 159.17 KB RN_OSS_DEV
ReactFabric-prod.js -0.0% -0.0% 268.94 KB 268.9 KB 45.95 KB 45.95 KB RN_OSS_PROD
ReactFabric-profiling.js -0.0% -0.0% 279.08 KB 279.04 KB 47.83 KB 47.83 KB RN_OSS_PROFILING

Size changes (stable)

Generated by 🚫 dangerJS against 43fad6e

@sizebot
Copy link

sizebot commented Nov 9, 2019

Details of bundled changes.

Comparing: 01bce8c...43fad6e

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactFabric-prod.js 🔺+0.1% 🔺+0.1% 268.92 KB 269.09 KB 45.94 KB 46.01 KB RN_FB_PROD
ReactNativeRenderer-dev.js 0.0% 0.0% 748.47 KB 748.69 KB 158.3 KB 158.35 KB RN_OSS_DEV
ReactFabric-profiling.js +0.1% +0.1% 279.05 KB 279.22 KB 47.82 KB 47.89 KB RN_FB_PROFILING
ReactNativeRenderer-prod.js 🔺+0.1% 🔺+0.1% 277.23 KB 277.37 KB 47.37 KB 47.43 KB RN_FB_PROD
ReactNativeRenderer-profiling.js 0.0% +0.1% 286.19 KB 286.33 KB 49.09 KB 49.15 KB RN_FB_PROFILING
ReactFabric-dev.js 0.0% 0.0% 753.96 KB 754.23 KB 159.13 KB 159.18 KB RN_OSS_DEV
ReactFabric-prod.js -0.0% -0.0% 268.96 KB 268.92 KB 45.96 KB 45.96 KB RN_OSS_PROD
ReactFabric-profiling.js -0.0% -0.0% 279.09 KB 279.05 KB 47.84 KB 47.83 KB RN_OSS_PROFILING
ReactFabric-dev.js 0.0% 0.0% 754.11 KB 754.41 KB 159.2 KB 159.26 KB RN_FB_DEV
ReactNativeRenderer-prod.js -0.0% -0.0% 277.28 KB 277.23 KB 47.39 KB 47.38 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js -0.0% -0.0% 286.24 KB 286.19 KB 49.12 KB 49.1 KB RN_OSS_PROFILING
ReactNativeRenderer-dev.js 0.0% 0.0% 748.62 KB 748.86 KB 158.38 KB 158.43 KB RN_FB_DEV

Size changes (experimental)

Generated by 🚫 dangerJS against 43fad6e

@elicwhite
Copy link
Member Author

This PR depends on #17344 to change the flow types to allow null as the target.

@elicwhite
Copy link
Member Author

currentTarget will be changed in this stacked PR that I will be able to send once this is merged: https://github.com/TheSavior/react/pull/1/files

@elicwhite elicwhite merged commit 2c6ea0b into facebook:master Nov 11, 2019
@elicwhite elicwhite deleted the native-event-target branch November 11, 2019 22:00
elicwhite added a commit to elicwhite/react that referenced this pull request Dec 19, 2019
…cebook#17323)

* [Native] Add FeatureFlag to dispatch events with instance targets

* Prettier
elicwhite added a commit to elicwhite/react that referenced this pull request Jan 8, 2020
…cebook#17323)

* [Native] Add FeatureFlag to dispatch events with instance targets

* Prettier
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.

4 participants