expo 57.0.4 → 57.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,7 @@ buildscript {
10
10
  }
11
11
 
12
12
  group = 'host.exp.exponent'
13
- version = '57.0.4'
13
+ version = '57.0.5'
14
14
 
15
15
  expoModule {
16
16
  // We can't prebuild the module because it depends on the generated files.
@@ -21,7 +21,7 @@ android {
21
21
  namespace "expo.core"
22
22
  defaultConfig {
23
23
  versionCode 1
24
- versionName "57.0.4"
24
+ versionName "57.0.5"
25
25
  consumerProguardFiles("proguard-rules.pro")
26
26
  }
27
27
  testOptions {
@@ -4,6 +4,7 @@ package expo.modules.fetch
4
4
 
5
5
  import android.util.Log
6
6
  import com.facebook.react.bridge.ReactContext
7
+ import com.facebook.react.modules.blob.BlobModule
7
8
  import com.facebook.react.modules.network.CookieJarContainer
8
9
  import com.facebook.react.modules.network.ForwardingCookieHandler
9
10
  import com.facebook.react.modules.network.OkHttpClientProvider
@@ -49,6 +50,13 @@ class ExpoFetchModule : Module() {
49
50
  cookieJarContainer.setCookieJar(JavaNetCookieJar(cookieHandler))
50
51
  }
51
52
 
53
+ // TODO(kudo,20260706): remove this when we install expo-blob as globalThis.Blob
54
+ AsyncFunction("unstable_createBlobData") { data: ByteArray ->
55
+ val blobModule = reactContext.getNativeModule(BlobModule::class.java)
56
+ ?: throw FetchBlobModuleUnavailableException()
57
+ return@AsyncFunction blobModule.store(data)
58
+ }
59
+
52
60
  OnDestroy {
53
61
  cookieHandler.destroy()
54
62
  cookieJarContainer.removeCookieJar()
@@ -15,3 +15,9 @@ internal class FetchAndroidContextLostException :
15
15
 
16
16
  internal class FetchRedirectException :
17
17
  CodedException("Redirect is not allowed when redirect mode is 'error'")
18
+
19
+ internal class FetchBlobModuleUnavailableException :
20
+ CodedException(
21
+ "Unable to store the response body as a blob because React Native's BlobModule is not available. " +
22
+ "Make sure your app includes the React Native blob support or read the body with arrayBuffer() instead"
23
+ )
@@ -21,9 +21,6 @@ export declare class FetchResponse extends ConcreteNativeResponse implements Res
21
21
  get bodyUsed(): boolean;
22
22
  get headers(): Headers;
23
23
  get ok(): boolean;
24
- /**
25
- * This method is not currently supported by react-native's Blob constructor.
26
- */
27
24
  blob(): Promise<Blob>;
28
25
  formData(): Promise<UniversalFormData>;
29
26
  json(): Promise<any>;
@@ -1 +1 @@
1
- {"version":3,"file":"FetchResponse.d.ts","sourceRoot":"","sources":["../../../src/winter/fetch/FetchResponse.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEzE,QAAA,MAAM,sBAAsB,EAAqC,OAAO,cAAc,CAAC;AACvF,MAAM,MAAM,gCAAgC,GAAG,MAAM,IAAI,CAAC;AAI1D,KAAK,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AACvE,KAAK,iBAAiB,GAAG,UAAU,CAAC,QAAQ,GAAG,UAAU,CAAC;AAW1D,QAAA,MAAM,QAAQ,eAAgC,CAAC;AAqI/C;;GAEG;AACH,qBAAa,aAAc,SAAQ,sBAAuB,YAAW,QAAQ;IAM/D,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IALjD,OAAO,CAAC,CAAC,QAAQ,CAAC,CAGhB;gBAE2B,oBAAoB,EAAE,gCAAgC;IAQnF,IAAa,WAAW,IAAI,iBAAiB,CAE5C;IAED,IAAa,MAAM,IAAI,MAAM,CAE5B;IAED,IAAa,UAAU,IAAI,MAAM,CAEhC;IAED,IAAa,GAAG,IAAI,MAAM,CAEzB;IAED,IAAa,UAAU,IAAI,OAAO,CAEjC;IAED,IAAI,IAAI,IAAI,SAAS,CAEpB;IAED,IAAI,IAAI,IAAI,cAAc,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,GAAG,IAAI,CA0EzD;IAED,IAAa,QAAQ,IAAI,OAAO,CAE/B;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,EAAE,IAAI,OAAO,CAEhB;IAED;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAMrB,QAAQ,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAgBtC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC;IAMpB,KAAK,IAAI,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IAKhC,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC;IAanC,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAatC,QAAQ,IAAI,MAAM;IAIlB,MAAM,IAAI,MAAM;IAShB,KAAK,IAAI,aAAa;IAgDtB,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,QAAQ,CAQd;CACH"}
1
+ {"version":3,"file":"FetchResponse.d.ts","sourceRoot":"","sources":["../../../src/winter/fetch/FetchResponse.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGzE,QAAA,MAAM,sBAAsB,EAAqC,OAAO,cAAc,CAAC;AACvF,MAAM,MAAM,gCAAgC,GAAG,MAAM,IAAI,CAAC;AAI1D,KAAK,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AACvE,KAAK,iBAAiB,GAAG,UAAU,CAAC,QAAQ,GAAG,UAAU,CAAC;AAW1D,QAAA,MAAM,QAAQ,eAAgC,CAAC;AAuI/C;;GAEG;AACH,qBAAa,aAAc,SAAQ,sBAAuB,YAAW,QAAQ;IAM/D,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IALjD,OAAO,CAAC,CAAC,QAAQ,CAAC,CAGhB;gBAE2B,oBAAoB,EAAE,gCAAgC;IAQnF,IAAa,WAAW,IAAI,iBAAiB,CAE5C;IAED,IAAa,MAAM,IAAI,MAAM,CAE5B;IAED,IAAa,UAAU,IAAI,MAAM,CAEhC;IAED,IAAa,GAAG,IAAI,MAAM,CAEzB;IAED,IAAa,UAAU,IAAI,OAAO,CAEjC;IAED,IAAI,IAAI,IAAI,SAAS,CAEpB;IAED,IAAI,IAAI,IAAI,cAAc,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,GAAG,IAAI,CA0EzD;IAED,IAAa,QAAQ,IAAI,OAAO,CAE/B;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,EAAE,IAAI,OAAO,CAEhB;IAEK,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAkBrB,QAAQ,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAgBtC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC;IAMpB,KAAK,IAAI,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IAKhC,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC;IAanC,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAatC,QAAQ,IAAI,MAAM;IAIlB,MAAM,IAAI,MAAM;IAShB,KAAK,IAAI,aAAa;IAgDtB,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,QAAQ,CAQd;CACH"}
@@ -0,0 +1,8 @@
1
+ export declare function isReactNativeBlobGlobal(): boolean;
2
+ /**
3
+ * react-native's `Blob` cannot be created from binary data in JS, so store the
4
+ * bytes in its native blob store and reference them, like XHR responses do.
5
+ * TODO(kudo,20260706): remove this when we install expo-blob as globalThis.Blob
6
+ */
7
+ export declare function createReactNativeBlobAsync(buffer: ArrayBuffer, type: string): Promise<Blob>;
8
+ //# sourceMappingURL=createBlob.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createBlob.d.ts","sourceRoot":"","sources":["../../../src/winter/fetch/createBlob.ts"],"names":[],"mappings":"AAEA,wBAAgB,uBAAuB,IAAI,OAAO,CAMjD;AAED;;;;GAIG;AACH,wBAAsB,0BAA0B,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAUjG"}
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "@expo/dom-webview": "~57.0.0",
3
- "@expo/fingerprint": "~0.20.3",
4
- "@expo/metro-runtime": "~57.0.3",
3
+ "@expo/fingerprint": "~0.20.4",
4
+ "@expo/metro-runtime": "~57.0.4",
5
5
  "@expo/vector-icons": "^15.0.2",
6
- "@expo/ui": "~57.0.4",
6
+ "@expo/ui": "~57.0.5",
7
7
  "@react-native-async-storage/async-storage": "2.2.0",
8
8
  "@react-native-community/datetimepicker": "9.1.0",
9
9
  "@react-native-masked-view/masked-view": "0.3.2",
@@ -17,30 +17,31 @@
17
17
  "expo-analytics-amplitude": "~11.3.0",
18
18
  "expo-app-auth": "~11.1.0",
19
19
  "expo-app-loader-provider": "~8.0.0",
20
- "expo-app-metrics": "~57.0.2",
20
+ "expo-app-metrics": "~57.0.3",
21
21
  "expo-apple-authentication": "~57.0.0",
22
22
  "expo-application": "~57.0.0",
23
- "expo-asset": "~57.0.3",
24
- "expo-audio": "~57.0.0",
23
+ "expo-asset": "~57.0.4",
24
+ "expo-audio": "~57.0.1",
25
25
  "expo-auth-session": "~57.0.2",
26
- "expo-background-fetch": "~57.0.2",
27
- "expo-background-task": "~57.0.2",
26
+ "expo-background-fetch": "~57.0.3",
27
+ "expo-background-task": "~57.0.3",
28
28
  "expo-battery": "~57.0.0",
29
- "expo-blur": "~57.0.0",
29
+ "expo-blur": "~57.0.1",
30
30
  "expo-brightness": "~57.0.0",
31
- "expo-brownfield": "~57.0.3",
32
- "expo-build-properties": "~57.0.3",
31
+ "expo-brownfield": "~57.0.4",
32
+ "expo-build-properties": "~57.0.4",
33
33
  "expo-calendar": "~57.0.0",
34
34
  "expo-camera": "~57.0.1",
35
35
  "expo-cellular": "~57.0.0",
36
36
  "expo-checkbox": "~57.0.0",
37
37
  "expo-clipboard": "~57.0.0",
38
- "expo-constants": "~57.0.3",
38
+ "expo-constants": "~57.0.4",
39
39
  "expo-contacts": "~57.0.0",
40
40
  "expo-crypto": "~57.0.0",
41
- "expo-dev-client": "~57.0.5",
41
+ "expo-dev-client": "~57.0.6",
42
42
  "expo-device": "~57.0.0",
43
43
  "expo-document-picker": "~57.0.0",
44
+ "expo-eas-client": "~57.0.0",
44
45
  "expo-file-system": "~57.0.0",
45
46
  "expo-font": "~57.0.0",
46
47
  "expo-gl": "~57.0.1",
@@ -49,53 +50,53 @@
49
50
  "expo-haptics": "~57.0.0",
50
51
  "expo-image": "~57.0.0",
51
52
  "expo-image-loader": "~57.0.0",
52
- "expo-image-manipulator": "~57.0.2",
53
- "expo-image-picker": "~57.0.2",
53
+ "expo-image-manipulator": "~57.0.3",
54
+ "expo-image-picker": "~57.0.3",
54
55
  "expo-intent-launcher": "~57.0.0",
55
- "expo-insights": "~57.0.2",
56
+ "expo-insights": "~57.0.3",
56
57
  "expo-keep-awake": "~57.0.0",
57
58
  "expo-linear-gradient": "~57.0.0",
58
59
  "expo-linking": "~57.0.2",
59
60
  "expo-local-authentication": "~57.0.0",
60
61
  "expo-localization": "~57.0.0",
61
- "expo-location": "~57.0.2",
62
+ "expo-location": "~57.0.3",
62
63
  "expo-mail-composer": "~57.0.0",
63
64
  "expo-manifests": "~57.0.0",
64
65
  "expo-maps": "~57.0.0",
65
66
  "expo-mcp": "~0.2.1",
66
67
  "expo-media-library": "~57.0.1",
67
68
  "expo-mesh-gradient": "~57.0.0",
68
- "expo-module-template": "~57.0.2",
69
- "expo-modules-core": "~57.0.3",
69
+ "expo-module-template": "~57.0.3",
70
+ "expo-modules-core": "~57.0.4",
70
71
  "expo-navigation-bar": "~57.0.1",
71
72
  "expo-network": "~57.0.0",
72
- "expo-notifications": "~57.0.3",
73
- "expo-observe": "~57.0.4",
73
+ "expo-notifications": "~57.0.4",
74
+ "expo-observe": "~57.0.5",
74
75
  "expo-print": "~57.0.0",
75
76
  "expo-live-photo": "~57.0.0",
76
- "expo-router": "~57.0.4",
77
+ "expo-router": "~57.0.5",
77
78
  "expo-screen-capture": "~57.0.0",
78
79
  "expo-screen-orientation": "~57.0.0",
79
80
  "expo-secure-store": "~57.0.0",
80
81
  "expo-sensors": "~57.0.1",
81
82
  "expo-server": "~57.0.0",
82
- "expo-sharing": "~57.0.3",
83
+ "expo-sharing": "~57.0.4",
83
84
  "expo-sms": "~57.0.0",
84
85
  "expo-speech": "~57.0.0",
85
- "expo-splash-screen": "~57.0.2",
86
+ "expo-splash-screen": "~57.0.3",
86
87
  "expo-sqlite": "~57.0.0",
87
88
  "expo-status-bar": "~57.0.0",
88
89
  "expo-store-review": "~57.0.0",
89
90
  "expo-symbols": "~57.0.0",
90
91
  "expo-system-ui": "~57.0.0",
91
- "expo-task-manager": "~57.0.2",
92
+ "expo-task-manager": "~57.0.3",
92
93
  "expo-tracking-transparency": "~57.0.0",
93
- "expo-updates": "~57.0.6",
94
+ "expo-updates": "~57.0.7",
94
95
  "expo-video-thumbnails": "~57.0.0",
95
96
  "expo-video": "~57.0.0",
96
97
  "expo-web-browser": "~57.0.0",
97
- "expo-widgets": "~57.0.3",
98
- "jest-expo": "~57.0.1",
98
+ "expo-widgets": "~57.0.4",
99
+ "jest-expo": "~57.0.2",
99
100
  "lottie-react-native": "~7.3.8",
100
101
  "react": "19.2.3",
101
102
  "react-dom": "19.2.3",
@@ -43,20 +43,25 @@
43
43
 
44
44
  // Resolve the React runtime scheduler so ExpoModulesJSI can dispatch work onto
45
45
  // the JS thread. Doing it here (rather than inside the xcframework) keeps
46
- // React-runtimescheduler symbols out of the prebuilt ExpoModulesJSI.framework
47
- // important for source-built RN, where those symbols are hidden after link
46
+ // React-runtimescheduler symbols out of the prebuilt ExpoModulesJSI.framework.
47
+ // That matters for source-built RN, where those symbols are hidden after link
48
48
  // and unreachable via -undefined dynamic_lookup.
49
49
  //
50
+ // The handle references the scheduler weakly, so dispatching after the React
51
+ // instance tore it down (e.g. on reload) drops the task instead of calling
52
+ // into freed memory. See `EXReactSchedulerDispatch.h`.
53
+ //
50
54
  // If RN didn't install a RuntimeSchedulerBinding for some reason, pass nullptr
51
- // for both AppContext.setRuntime falls back to a synchronous no-op scheduler
55
+ // for both. AppContext.setRuntime falls back to a synchronous no-op scheduler
52
56
  // so the app still launches; modules that require async dispatch can gate on
53
57
  // `JavaScriptRuntime.supportsAsyncScheduling`.
54
58
  auto binding = facebook::react::RuntimeSchedulerBinding::getBinding(runtime);
55
59
  auto scheduler = binding ? binding->getRuntimeScheduler() : nullptr;
60
+ void *schedulerHandle = expo::createReactSchedulerHandle(scheduler);
56
61
 
57
62
  [_appContext setRuntime:&runtime
58
- scheduler:scheduler.get()
59
- dispatch:scheduler ? reinterpret_cast<const void *>(&expo::dispatchOnReactScheduler) : nullptr];
63
+ scheduler:schedulerHandle
64
+ dispatch:schedulerHandle ? reinterpret_cast<const void *>(&expo::dispatchOnReactScheduler) : nullptr];
60
65
  [_appContext setHostWrapper:[[EXHostWrapper alloc] initWithHost:host]];
61
66
 
62
67
  [_appContext registerNativeModules];
@@ -24,6 +24,19 @@ public final class ExpoFetchModule: Module {
24
24
  urlSession.invalidateAndCancel()
25
25
  }
26
26
 
27
+ // TODO(kudo,20260706): remove this when we install expo-blob as globalThis.Blob
28
+ AsyncFunction("unstable_createBlobData") { (data: Data) -> String in
29
+ guard let blobManager: NSObject = self.appContext?.nativeModule(named: "BlobModule") else {
30
+ throw FetchBlobModuleUnavailableException()
31
+ }
32
+ let store = NSSelectorFromString("store:")
33
+ guard blobManager.responds(to: store),
34
+ let blobId = blobManager.perform(store, with: data as NSData)?.takeUnretainedValue() as? String else {
35
+ throw FetchBlobModuleUnavailableException()
36
+ }
37
+ return blobId
38
+ }
39
+
27
40
  // swiftlint:disable:next closure_body_length
28
41
  Class(NativeResponse.self) {
29
42
  Constructor {
@@ -19,3 +19,10 @@ internal final class FetchRedirectException: Exception {
19
19
  "Redirect is not allowed when redirect mode is 'error'"
20
20
  }
21
21
  }
22
+
23
+ internal final class FetchBlobModuleUnavailableException: Exception {
24
+ override var reason: String {
25
+ "Unable to store the response body as a blob because React Native's BlobModule is not available. " +
26
+ "Make sure your app includes the React Native blob support (React-RCTBlob) or read the body with arrayBuffer() instead"
27
+ }
28
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo",
3
- "version": "57.0.4",
3
+ "version": "57.0.5",
4
4
  "description": "The Expo SDK",
5
5
  "main": "src/Expo.ts",
6
6
  "module": "src/Expo.ts",
@@ -68,25 +68,25 @@
68
68
  "homepage": "https://github.com/expo/expo/tree/main/packages/expo",
69
69
  "dependencies": {
70
70
  "@babel/runtime": "^7.20.0",
71
- "@expo/cli": "^57.0.6",
72
- "@expo/config": "~57.0.3",
73
- "@expo/config-plugins": "~57.0.3",
71
+ "@expo/cli": "^57.0.7",
72
+ "@expo/config": "~57.0.4",
73
+ "@expo/config-plugins": "~57.0.4",
74
74
  "@expo/devtools": "~57.0.0",
75
75
  "@expo/dom-webview": "~57.0.0",
76
- "@expo/fingerprint": "^0.20.3",
77
- "@expo/local-build-cache-provider": "^57.0.2",
76
+ "@expo/fingerprint": "^0.20.4",
77
+ "@expo/local-build-cache-provider": "^57.0.3",
78
78
  "@expo/log-box": "^57.0.0",
79
79
  "@expo/metro": "~56.0.0",
80
- "@expo/metro-config": "~57.0.3",
80
+ "@expo/metro-config": "~57.0.4",
81
81
  "@ungap/structured-clone": "^1.3.0",
82
82
  "babel-preset-expo": "~57.0.2",
83
- "expo-asset": "~57.0.3",
84
- "expo-constants": "~57.0.3",
83
+ "expo-asset": "~57.0.4",
84
+ "expo-constants": "~57.0.4",
85
85
  "expo-file-system": "~57.0.0",
86
86
  "expo-font": "~57.0.0",
87
87
  "expo-keep-awake": "~57.0.0",
88
- "expo-modules-autolinking": "~57.0.5",
89
- "expo-modules-core": "~57.0.3",
88
+ "expo-modules-autolinking": "~57.0.6",
89
+ "expo-modules-core": "~57.0.4",
90
90
  "pretty-format": "^29.7.0",
91
91
  "react-refresh": "^0.14.2",
92
92
  "whatwg-url-minimum": "^0.1.2"
@@ -100,9 +100,9 @@
100
100
  "react-native": "0.86.0",
101
101
  "rimraf": "^6.1.2",
102
102
  "web-streams-polyfill": "^3.3.2",
103
- "@expo/metro-runtime": "57.0.3",
104
- "expo-updates": "57.0.6",
105
- "@expo/dom-webview": "57.0.0"
103
+ "@expo/dom-webview": "57.0.0",
104
+ "@expo/metro-runtime": "57.0.4",
105
+ "expo-updates": "57.0.7"
106
106
  },
107
107
  "peerDependencies": {
108
108
  "@expo/dom-webview": "*",
@@ -139,7 +139,7 @@
139
139
  "scripts/resolveAppEntry.js"
140
140
  ]
141
141
  },
142
- "gitHead": "b31bd70c8873eee2894bc5cc3b3460abca0cdea0",
142
+ "gitHead": "70af1caf83d8a324b46e02e18cd5c8c4e310da20",
143
143
  "scripts": {
144
144
  "build": "tsc",
145
145
  "clean": "rimraf build",
@@ -1,5 +1,6 @@
1
1
  import { ExpoFetchModule } from './ExpoFetchModule';
2
2
  import type { NativeHeadersType, NativeResponse } from './NativeRequest';
3
+ import { createReactNativeBlobAsync, isReactNativeBlobGlobal } from './createBlob';
3
4
 
4
5
  const ConcreteNativeResponse = ExpoFetchModule.NativeResponse as typeof NativeResponse;
5
6
  export type AbortSubscriptionCleanupFunction = () => void;
@@ -20,6 +21,8 @@ interface ResponseMetadata {
20
21
 
21
22
  const stateKey = Symbol('FetchResponse.state');
22
23
 
24
+ let hasWarnedAboutReactNativeBlob = false;
25
+
23
26
  interface ConsumptionWrapper {
24
27
  stream: ReadableStream<Uint8Array<ArrayBuffer>>;
25
28
  // Stops the wrapper from marking its body as consumed. Called by clone()
@@ -280,13 +283,22 @@ export class FetchResponse extends ConcreteNativeResponse implements Response {
280
283
  return this.status >= 200 && this.status < 300;
281
284
  }
282
285
 
283
- /**
284
- * This method is not currently supported by react-native's Blob constructor.
285
- */
286
286
  async blob(): Promise<Blob> {
287
287
  this.checkBodyUsedError('blob');
288
+ const type = this.headers.get('content-type') ?? '';
288
289
  const buffer = await this.arrayBuffer();
289
- return new Blob([buffer]);
290
+
291
+ if (isReactNativeBlobGlobal()) {
292
+ if (__DEV__ && !hasWarnedAboutReactNativeBlob) {
293
+ hasWarnedAboutReactNativeBlob = true;
294
+ console.warn(
295
+ "Response.blob() is using React Native's Blob, which copies the response into the native blob store and reads it back through base64 encoding. This may be slow for large responses. Add the `expo-blob` package to your app to avoid the performance overhead."
296
+ );
297
+ }
298
+ return createReactNativeBlobAsync(buffer, type);
299
+ }
300
+
301
+ return new Blob([buffer], { type });
290
302
  }
291
303
 
292
304
  async formData(): Promise<UniversalFormData> {
@@ -0,0 +1,88 @@
1
+ import { FetchResponse } from '../FetchResponse';
2
+
3
+ jest.mock('../ExpoFetchModule', () => {
4
+ const helloWorld = new TextEncoder().encode('hello world');
5
+
6
+ class StubNativeResponse {
7
+ // Getters on the prototype, like the real native binding, so super.x works.
8
+ get _rawHeaders(): [string, string][] {
9
+ return [['content-type', 'text/plain']];
10
+ }
11
+
12
+ addListener() {}
13
+ removeListener() {}
14
+ removeAllListeners() {}
15
+
16
+ async arrayBuffer(): Promise<ArrayBuffer> {
17
+ return helloWorld.buffer.slice(
18
+ helloWorld.byteOffset,
19
+ helloWorld.byteOffset + helloWorld.byteLength
20
+ ) as ArrayBuffer;
21
+ }
22
+ }
23
+
24
+ return {
25
+ ExpoFetchModule: {
26
+ NativeResponse: StubNativeResponse,
27
+ unstable_createBlobData: jest.fn(async () => 'mock-blob-id'),
28
+ },
29
+ };
30
+ });
31
+
32
+ describe('FetchResponse blob() with react-native Blob', () => {
33
+ const originalBlob = globalThis.Blob;
34
+ const RNBlob = require('react-native/Libraries/Blob/Blob').default;
35
+ const { ExpoFetchModule } = require('../ExpoFetchModule');
36
+
37
+ beforeEach(() => {
38
+ globalThis.Blob = RNBlob;
39
+ ExpoFetchModule.unstable_createBlobData.mockClear();
40
+ });
41
+
42
+ afterEach(() => {
43
+ globalThis.Blob = originalBlob;
44
+ });
45
+
46
+ function makeResponse(): FetchResponse {
47
+ return new FetchResponse(() => {});
48
+ }
49
+
50
+ it('should warn about the performance overhead only once', async () => {
51
+ const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
52
+
53
+ try {
54
+ await makeResponse().blob();
55
+ await makeResponse().blob();
56
+
57
+ expect(warnSpy).toHaveBeenCalledTimes(1);
58
+ expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('expo-blob'));
59
+ } finally {
60
+ warnSpy.mockRestore();
61
+ }
62
+ });
63
+
64
+ it('should return a react-native blob backed by the native blob store', async () => {
65
+ const response = makeResponse();
66
+ const blob = await response.blob();
67
+
68
+ expect(blob).toBeInstanceOf(RNBlob);
69
+ expect((blob as any).data.blobId).toBe('mock-blob-id');
70
+ expect(blob.size).toBe(11);
71
+ expect(blob.type).toBe('text/plain');
72
+ });
73
+
74
+ it('should store the body bytes in the native blob store', async () => {
75
+ const response = makeResponse();
76
+ await response.blob();
77
+
78
+ expect(ExpoFetchModule.unstable_createBlobData).toHaveBeenCalledTimes(1);
79
+ const bytes = ExpoFetchModule.unstable_createBlobData.mock.calls[0][0] as Uint8Array;
80
+ expect(new TextDecoder().decode(bytes)).toBe('hello world');
81
+ });
82
+
83
+ it('should reject a second blob() call with TypeError', async () => {
84
+ const response = makeResponse();
85
+ await response.blob();
86
+ await expect(response.blob()).rejects.toThrow(TypeError);
87
+ });
88
+ });
@@ -89,6 +89,7 @@ jest.mock('../ExpoFetchModule', () => {
89
89
  ExpoFetchModule: {
90
90
  NativeRequest: StubNativeRequest,
91
91
  NativeResponse: StubNativeResponse,
92
+ unstable_createBlobData: jest.fn(async () => 'mock-blob-id'),
92
93
  },
93
94
  };
94
95
  });
@@ -254,6 +255,15 @@ describe('FetchResponse', () => {
254
255
  });
255
256
  });
256
257
 
258
+ describe('blob()', () => {
259
+ it('should create a blob with type from the content-type header', async () => {
260
+ const response = makeResponse();
261
+ const blob = await response.blob();
262
+ expect(blob.size).toBe(11);
263
+ expect(blob.type).toBe('text/plain');
264
+ });
265
+ });
266
+
257
267
  describe('body methods', () => {
258
268
  it('rejects a second arrayBuffer() call with TypeError', async () => {
259
269
  const response = makeResponse();
@@ -0,0 +1,26 @@
1
+ import { ExpoFetchModule } from './ExpoFetchModule';
2
+
3
+ export function isReactNativeBlobGlobal(): boolean {
4
+ try {
5
+ return globalThis.Blob === require('react-native/Libraries/Blob/Blob').default;
6
+ } catch {
7
+ return false;
8
+ }
9
+ }
10
+
11
+ /**
12
+ * react-native's `Blob` cannot be created from binary data in JS, so store the
13
+ * bytes in its native blob store and reference them, like XHR responses do.
14
+ * TODO(kudo,20260706): remove this when we install expo-blob as globalThis.Blob
15
+ */
16
+ export async function createReactNativeBlobAsync(buffer: ArrayBuffer, type: string): Promise<Blob> {
17
+ const BlobManager = require('react-native/Libraries/Blob/BlobManager').default;
18
+ const blobId: string = await ExpoFetchModule.unstable_createBlobData(new Uint8Array(buffer));
19
+ return BlobManager.createFromOptions({
20
+ blobId,
21
+ offset: 0,
22
+ size: buffer.byteLength,
23
+ type,
24
+ lastModified: Date.now(),
25
+ });
26
+ }
package/template.tgz CHANGED
Binary file