Skip to content

Commit 60a157e

Browse files
authored
fix(network-activity-plugin): avoid Metro optional dependency overlay for Nitro (callstackincubator#273)
## Summary Move `react-native-nitro-fetch` resolution to module initialization so the network activity plugin reads the optional dependency once before React Native finishes initializing. ## Context It's supposed to provide a workaround for Metro 0.82 bug, where optional dependencies required at run-time, after react-native is initialized, will show the error overlay. The changes done are moving the require time to before react-native is fully initialized, just like we do currently for `react-native-sse`, so the error overlay is never displayed. This keeps the existing fallback behavior for apps that do not install `react-native-nitro-fetch`, but avoids re-running the optional require from the nitro inspector enable path. ## Proposed Testing Scenario 1. Run an app that includes `@rozenite/network-activity-plugin` without installing `react-native-nitro-fetch`. 2. Start and stop network recording multiple times after the app has already initialized. 3. Confirm the app does not show the Metro error overlay for the missing optional nitro dependency. 4. Run an app that does install `react-native-nitro-fetch` and verify network recording still works for nitro-backed requests.
1 parent ea2d273 commit 60a157e

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

.changeset/five-owls-relax.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@rozenite/network-activity-plugin': patch
3+
---
4+
5+
Resolve the optional `react-native-nitro-fetch` dependency before React Native finishes initializing so Metro 0.82 does not show an error overlay when the package is not installed.
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import type { NitroModule } from './nitro-network-inspector';
22

3-
export const getNitroModule = (): NitroModule | null => {
3+
const nitroModule = (() => {
44
try {
55
return require('react-native-nitro-fetch') as NitroModule;
66
} catch {
77
return null;
88
}
9+
})();
10+
11+
export const getNitroModule = (): NitroModule | null => {
12+
return nitroModule;
913
};

0 commit comments

Comments
 (0)