Skip to content

Commit 111a306

Browse files
use expo fetch
1 parent 5d20916 commit 111a306

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

.changeset/many-fishes-camp.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/react-native': minor
3+
---
4+
5+
Added ability to use Expo's fetch API if available.

packages/react-native/src/sync/stream/ReactNativeRemote.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,24 @@ export const STREAMING_POST_TIMEOUT_MS = 30_000;
2727
* a polyfill.
2828
*/
2929
class ReactNativeFetchProvider extends FetchImplementationProvider {
30+
constructor(public logger: ILogger = DEFAULT_REMOTE_LOGGER) {
31+
super();
32+
}
33+
3034
getFetch(): FetchImplementation {
35+
/**
36+
* From Expo 52, Expo provides a fetch implementation which supports HTTP streams.
37+
* https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api
38+
*/
39+
try {
40+
const f = require('expo/fetch').fetch;
41+
if (f) {
42+
this.logger.debug('Using Expo fetch implementation');
43+
return f;
44+
}
45+
} catch (e) {
46+
// If expo is not installed, fallback
47+
}
3148
return fetch.bind(globalThis);
3249
}
3350
}
@@ -40,7 +57,7 @@ export class ReactNativeRemote extends AbstractRemote {
4057
) {
4158
super(connector, logger, {
4259
...(options ?? {}),
43-
fetchImplementation: options?.fetchImplementation ?? new ReactNativeFetchProvider()
60+
fetchImplementation: options?.fetchImplementation ?? new ReactNativeFetchProvider(logger)
4461
});
4562
}
4663

0 commit comments

Comments
 (0)