@samitouri / QOS-React-2 / commits / 06460b6fb5

Remove unnecessary (and incorrect) code for compatibility with Paper in the Fabric version of GlobalResponderHandler (#26290)

## Summary I'm working on a refactor of the definition of `Instance` in Fabric and I came across this code that seemed to be for compatibility with Paper, but that it would actually throw an error in that case. In Paper, `stateNode` is an instance of `ReactNativeFiberHostComponent`, which doesn't have a `canonical` field. We try to access nested properties in that field in a couple of places here, which would throw a type error (cannot read property `_nativeTag` of `undefined`) if we actually happened to pass a reference to a Paper state node. In this line: ```javascript const isFabric = !!( fromOrToStateNode && fromOrToStateNode.canonical._internalInstanceHandle ); ``` If it wasn't Fabric, `fromOrToStateNode.canonical` would be undefined, and we don't check for that before accessing `fromOrToStateNode.canonical._internalInstanceHandle`. This means that we actually never use this logic in Paper or we would've seen the error. ## How did you test this change? Existing tests.

Rubén Norte committed Mar 3, 2023 at 23:39 UTC 06460b6fb51e99cfab840424a9514651488b2e99
1 file changed +15 -33
packages/react-native-renderer/src/ReactFabricGlobalResponderHandler.js
+15 -33
@@ -7,42 +7,24 @@
7 * @flow
8 */
9
10 -// Module provided by RN:
11 -import {UIManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
12 -
10 const ReactFabricGlobalResponderHandler = {
11 onChange: function (from: any, to: any, blockNativeResponder: boolean) {
15 - const fromOrTo = from || to;
16 - const fromOrToStateNode = fromOrTo && fromOrTo.stateNode;
17 - const isFabric = !!(
18 - fromOrToStateNode && fromOrToStateNode.canonical._internalInstanceHandle
19 - );
20 -
21 - if (isFabric) {
22 - if (from) {
23 - // equivalent to clearJSResponder
24 - nativeFabricUIManager.setIsJSResponder(
25 - from.stateNode.node,
26 - false,
27 - blockNativeResponder || false,
28 - );
29 - }
12 + if (from) {
13 + // equivalent to clearJSResponder
14 + nativeFabricUIManager.setIsJSResponder(
15 + from.stateNode.node,
16 + false,
17 + blockNativeResponder || false,
18 + );
19 + }
20
31 - if (to) {
32 - // equivalent to setJSResponder
33 - nativeFabricUIManager.setIsJSResponder(
34 - to.stateNode.node,
35 - true,
36 - blockNativeResponder || false,
37 - );
38 - }
39 - } else {
40 - if (to !== null) {
41 - const tag = to.stateNode.canonical._nativeTag;
42 - UIManager.setJSResponder(tag, blockNativeResponder);
43 - } else {
44 - UIManager.clearJSResponder();
45 - }
21 + if (to) {
22 + // equivalent to setJSResponder
23 + nativeFabricUIManager.setIsJSResponder(
24 + to.stateNode.node,
25 + true,
26 + blockNativeResponder || false,
27 + );
28 }
29 },
30 };