Skip to content

Commit 06460b6

Browse files
authored
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.
1 parent e64a8f4 commit 06460b6

File tree

1 file changed

+15
-33
lines changed

1 file changed

+15
-33
lines changed

packages/react-native-renderer/src/ReactFabricGlobalResponderHandler.js

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,24 @@
77
* @flow
88
*/
99

10-
// Module provided by RN:
11-
import {UIManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
12-
1310
const ReactFabricGlobalResponderHandler = {
1411
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+
}
3020

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+
);
4628
}
4729
},
4830
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy