Skip to content

Commit f845f02

Browse files
authored
[core] Fix TypeError when setting user agent string in React Native (Azure#26612)
`Platform.constants` was introduced in React Native version v0.63. This PR adds a check before accessing the property. ### Packages impacted by this PR `@azure/core-rest-pipeline` ### Issues associated with this PR Azure#26609
1 parent 773ddc9 commit f845f02

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

sdk/core/core-rest-pipeline/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
### Bugs Fixed
1212

13+
- Fix a TypeError in React Native when `Platform.constants` is undefined [Issue #26609](https://github.com/Azure/azure-sdk-for-js/issues/26609)
14+
1315
### Other Changes
1416

1517
## 1.11.0 (2023-06-01)

sdk/core/core-rest-pipeline/src/util/userAgentPlatform.native.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ export function getHeaderName(): string {
1717
* @internal
1818
*/
1919
export function setPlatformSpecificData(map: Map<string, string>): void {
20-
const { major, minor, patch } = Platform.constants.reactNativeVersion;
21-
map.set("react-native", `${major}.${minor}.${patch}`);
20+
if (Platform.constants?.reactNativeVersion) {
21+
const { major, minor, patch } = Platform.constants.reactNativeVersion;
22+
map.set("react-native", `${major}.${minor}.${patch}`);
23+
}
2224
map.set("OS", `${Platform.OS}-${Platform.Version}`);
2325
}

0 commit comments

Comments
 (0)