Skip to content

Commit 187cbc1

Browse files
authored
fix(networking): add XHRInterceptor path for RN 0.80 (#1563)
With the release of React Native 0.80, XHRInterceptor path got changed, again. This is an extension of RN 0.79 support PR #1556
1 parent c0a2e10 commit 187cbc1

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

lib/reactotron-react-native/src/plugins/networking.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,25 @@ import type { ReactotronCore, Plugin } from "reactotron-core-client"
33
// Attempt to require XHRInterceptor using static paths
44
let XHRInterceptorModule
55
try {
6-
// Try the new path first (for RN >= 0.79)
7-
// Yay breaking changes :( https://github.com/facebook/react-native/releases/tag/v0.79.0#:~:text=APIs%3A%20Move-,XHRInterceptor,-API%20to%20src
8-
XHRInterceptorModule = require("react-native/src/private/inspector/XHRInterceptor")
6+
// Try path first (for RN >= 0.80)
7+
XHRInterceptorModule = require("react-native/src/private/devsupport/devmenu/elementinspector/XHRInterceptor")
98
} catch (e) {
109
try {
11-
// Fallback to the old path (for RN < 0.79)
12-
XHRInterceptorModule = require("react-native/Libraries/Network/XHRInterceptor")
10+
// Try path for RN 0.79
11+
// Yay breaking changes :( https://github.com/facebook/react-native/releases/tag/v0.79.0#:~:text=APIs%3A%20Move-,XHRInterceptor,-API%20to%20src
12+
XHRInterceptorModule = require("react-native/src/private/inspector/XHRInterceptor")
1313
} catch (e2) {
14-
console.error("Reactotron: Failed to require XHRInterceptor from both known paths.", e, e2)
15-
console.warn(
16-
"Reactotron: XHRInterceptor could not be loaded. Network monitoring will be disabled."
17-
)
18-
// Assign a dummy object later if checks fail
19-
XHRInterceptorModule = null // Indicate failure to require
14+
try {
15+
// Fallback to the old path (for RN < 0.79)
16+
XHRInterceptorModule = require("react-native/Libraries/Network/XHRInterceptor")
17+
} catch (e3) {
18+
console.error("Reactotron: Failed to require XHRInterceptor from all known paths.", e, e2, e3)
19+
console.warn(
20+
"Reactotron: XHRInterceptor could not be loaded. Network monitoring will be disabled."
21+
)
22+
// Assign a dummy object later if checks fail
23+
XHRInterceptorModule = null // Indicate failure to require
24+
}
2025
}
2126
}
2227

0 commit comments

Comments
 (0)