Skip to content

fix: don't import axios into RN SDK - #3853

Open
szuperaz wants to merge 1 commit into
V10from
fix-do-not-import-axios-directly
Open

szuperaz wants to merge 1 commit into
V10from
fix-do-not-import-axios-directly

Conversation

@szuperaz

@szuperaz szuperaz commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

https://linear.app/stream/issue/REACT-1225/ensure-stream-chat-js-parses-api-error-correctly-if-multiple-axios

Avoid importing axios from RN SDK. It can cause duplicate copies of Axios.

@Stream-SDK-Bot

Copy link
Copy Markdown
Contributor

SDK Size

title develop branch diff status
js_bundle_size 2033 KB 2014 KB -19551 B 🚀


if (!nativeMultipartRequest) {
return resolvedFallbackAdapter(config);
return Promise.reject(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to fall back to the default adapter, now it rejects. I think that’s fine (probably ?) since we can’t fall back without importing axios, but transformRequest also runs between the interceptor and the adapter, so the message probably shouldn’t only blame interceptors. Maybe something like “the request body changed after it was routed to the native uploader”.


it('rejects when an interceptor replaces the file body after it was routed natively', async () => {
const client = getTestClient();
preserveRequestData(client);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand ths properly, every test swaps transformRequest for a noop so nothing covers the real flow where the interceptor sees the body before the transform and the adapter sees it after.

Could we add one test that keeps the default transformRequest and goes through postForm with a FormData ? Like a complete flow override basically

installNativeMultipartAdapter(client);

expect(client.axiosInstance.defaults.adapter).toBe(defaultAdapter);
expect(client.axiosInstance.defaults.adapter).toEqual(['xhr', 'http', 'fetch']);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick

I think this is probably not needed, the referential equality should already cover everything.

Since this uses axios internals, it might break in the future (albeit super unlikely, cause half the internet probably relies on this :D )

szuperaz added a commit to GetStream/stream-chat-js that referenced this pull request Oct 13, 2026
…1909)

https://linear.app/stream/issue/REACT-1225/ensure-stream-chat-js-parses-api-error-correctly-if-multiple-axios

Noticed this while I was checking [duplicate message id
handling](#1907) in v10.
In RN SampleApp, this doesn't work correctly because SampleApp has two
copies of axios:
- One from `stream-chat` installed by SampleApp
- One from the SDK's `stream-chat` copy
- When RN calls `installNativeMultipartAdapter,` it replaces SampleApp's
axios adapter with the RN SDK's adapter copy and `error instanceof
AxiosError` will always return `false`, which meant errors weren't
parsed properly
- The root cause is that RN shouldn't import from `axios`, fixed here:
GetStream/stream-chat-react-native#3853
- Still, this fix makes sense regardless of RN fixed, stream-chat-js is
updated to do a more robust `isAxiosError(error)` check, instead of
relying on `instanceof`

This branch has not been deployed

No deployments
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