Skip to content

fix(network-activity-plugin): isolate react-native-nitro-fetch into separate bundle chunk#260

Merged
V3RON merged 1 commit into
mainfrom
fix/nitro-fetch-optional-dep-chunk
May 11, 2026
Merged

fix(network-activity-plugin): isolate react-native-nitro-fetch into separate bundle chunk#260
V3RON merged 1 commit into
mainfrom
fix/nitro-fetch-optional-dep-chunk

Conversation

@V3RON
Copy link
Copy Markdown
Contributor

@V3RON V3RON commented May 11, 2026

Problem

Metro has a known issue (facebook/metro#836) where optional require() calls fail to resolve correctly even when wrapped in try/catch. This caused react-native-nitro-fetch — an optional dependency — to break bundling in some Metro configurations.

Solution

Follows the same pattern already in place for react-native-sse / event-source.ts:

  • Extract the require('react-native-nitro-fetch') call from nitro-network-inspector.ts into a dedicated get-nitro-module.ts file.
  • Add get-nitro-module.ts to Vite's manualChunks so Rollup emits it as a separate bundle chunk.

Metro loads each chunk independently, which sidesteps the optional-dependency resolution bug.

Changes

  • src/react-native/nitro-fetch/get-nitro-module.ts — new file with the isolated getNitroModule getter
  • nitro-network-inspector.ts — removes loadNitroModule, imports from the new file; exports NitroModule type
  • vite.config.ts — adds get-nitro-module.ts to manualChunks
  • .changeset/nitro-fetch-optional-dep-chunk.md — patch changeset

…eparate bundle chunk

Mitigates facebook/metro#836 where Metro fails to
resolve optional dependencies even when wrapped in try/catch. Moves the
`require('react-native-nitro-fetch')` call into a dedicated `get-nitro-module.ts`
file so Vite can split it into its own chunk, matching the existing pattern
used for `react-native-sse` / `event-source.ts`.
@V3RON V3RON merged commit 9cea370 into main May 11, 2026
4 checks passed
@V3RON V3RON deleted the fix/nitro-fetch-optional-dep-chunk branch May 11, 2026 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant