Skip to content

Fix rn81 api warnings#123

Merged
alexbrazier merged 5 commits into
alexbrazier:masterfrom
ignaciotcrespo:fix-RN81-API-warnings
Mar 6, 2026
Merged

Fix rn81 api warnings#123
alexbrazier merged 5 commits into
alexbrazier:masterfrom
ignaciotcrespo:fix-RN81-API-warnings

Conversation

@ignaciotcrespo

Copy link
Copy Markdown
Contributor

Replace dependency on React Native's internal XHRInterceptor with a custom implementation that directly patches XMLHttpRequest prototype.

This fixes the deprecation warning in React Native 0.81+:

WARN The package .../node_modules/react-native contains an invalid package.json configuration.
Consider raising this issue with the package maintainer(s).
Reason: The resolution for ".../node_modules/react-native/src/private/inspector/XHRInterceptor" defined in "exports" is .../node_modules/react-native/src/private/inspector/XHRInterceptor.js, however this file does not exist.
Falling back to file-based resolution.

The new implementation:

  • Patches XMLHttpRequest.prototype.open, send, setRequestHeader
  • Captures response headers and body via onreadystatechange
  • Properly restores original methods when interception is disabled
  • Maintains the same callback API for compatibility with Logger.ts
  • Works across all React Native versions without version-specific paths

Tested in my app, all http requests are captured properly.

The previous implementation overrode onreadystatechange directly,
which failed when handlers were set after send() was called.

This fix uses addEventListener('readystatechange', ...) instead,
which reliably captures responses regardless of when other handlers
are attached.

fix: implement custom XHRInterceptor to avoid RN private API warnings

Replace dependency on React Native's internal XHRInterceptor with a
custom implementation that directly patches XMLHttpRequest prototype.

This fixes the deprecation warning in React Native 0.80+:
"Deep imports from the 'react-native' package are deprecated"

The new implementation:
- Patches XMLHttpRequest.prototype.open, send, setRequestHeader
- Captures response headers and body via onreadystatechange
- Properly restores original methods when interception is disabled
- Maintains the same callback API for compatibility with Logger.ts
- Works across all React Native versions without version-specific paths
@alexbrazier alexbrazier closed this Mar 6, 2026
@alexbrazier alexbrazier reopened this Mar 6, 2026
@alexbrazier

Copy link
Copy Markdown
Owner

Thanks for the PR @ignaciotcrespo and sorry for the slow response to look into it. It seems to be working well for me so I've pushed a couple of updates and happy to release soon. Let me know if you face any issues with the updates.

@alexbrazier alexbrazier merged commit db30e12 into alexbrazier:master Mar 6, 2026
4 checks passed
@ignaciotcrespo ignaciotcrespo deleted the fix-RN81-API-warnings branch March 7, 2026 23:49
@PrajTS

PrajTS commented Apr 16, 2026

Copy link
Copy Markdown

@alexbrazier Can you please release this?

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.

3 participants