Skip to content

Commit 84639ab

Browse files
authored
Guard against reused fibers in React Native commands (#21837)
1 parent c549bc4 commit 84639ab

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

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

+10-12
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,14 @@ function dispatchCommand(handle: any, command: string, args: Array<any>) {
160160
'native component. Use React.forwardRef to get access to the underlying native component',
161161
);
162162
}
163-
164163
return;
165164
}
166165

167-
if (handle._internalInstanceHandle) {
168-
nativeFabricUIManager.dispatchCommand(
169-
handle._internalInstanceHandle.stateNode.node,
170-
command,
171-
args,
172-
);
166+
if (handle._internalInstanceHandle != null) {
167+
const {stateNode} = handle._internalInstanceHandle;
168+
if (stateNode != null) {
169+
nativeFabricUIManager.dispatchCommand(stateNode.node, command, args);
170+
}
173171
} else {
174172
UIManager.dispatchViewManagerCommand(handle._nativeTag, command, args);
175173
}
@@ -186,11 +184,11 @@ function sendAccessibilityEvent(handle: any, eventType: string) {
186184
return;
187185
}
188186

189-
if (handle._internalInstanceHandle) {
190-
nativeFabricUIManager.sendAccessibilityEvent(
191-
handle._internalInstanceHandle.stateNode.node,
192-
eventType,
193-
);
187+
if (handle._internalInstanceHandle != null) {
188+
const {stateNode} = handle._internalInstanceHandle;
189+
if (stateNode != null) {
190+
nativeFabricUIManager.sendAccessibilityEvent(stateNode.node, eventType);
191+
}
194192
} else {
195193
legacySendAccessibilityEvent(handle._nativeTag, eventType);
196194
}

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

+10-11
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,11 @@ function dispatchCommand(handle: any, command: string, args: Array<any>) {
160160
return;
161161
}
162162

163-
if (handle._internalInstanceHandle) {
164-
nativeFabricUIManager.dispatchCommand(
165-
handle._internalInstanceHandle.stateNode.node,
166-
command,
167-
args,
168-
);
163+
if (handle._internalInstanceHandle != null) {
164+
const {stateNode} = handle._internalInstanceHandle;
165+
if (stateNode != null) {
166+
nativeFabricUIManager.dispatchCommand(stateNode.node, command, args);
167+
}
169168
} else {
170169
UIManager.dispatchViewManagerCommand(handle._nativeTag, command, args);
171170
}
@@ -182,11 +181,11 @@ function sendAccessibilityEvent(handle: any, eventType: string) {
182181
return;
183182
}
184183

185-
if (handle._internalInstanceHandle) {
186-
nativeFabricUIManager.sendAccessibilityEvent(
187-
handle._internalInstanceHandle.stateNode.node,
188-
eventType,
189-
);
184+
if (handle._internalInstanceHandle != null) {
185+
const {stateNode} = handle._internalInstanceHandle;
186+
if (stateNode != null) {
187+
nativeFabricUIManager.sendAccessibilityEvent(stateNode.node, eventType);
188+
}
190189
} else {
191190
legacySendAccessibilityEvent(handle._nativeTag, eventType);
192191
}

0 commit comments

Comments
 (0)