Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update react-native-netinfo patch #49631

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1609,10 +1609,10 @@ index 095dd3b..596ace1 100644
+{"version":3,"names":["NetInfoStateType","exports","NetInfoCellularGeneration"],"sources":["types.ts"],"sourcesContent":["/**\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @format\n */\n\nexport enum NetInfoStateType {\n unknown = 'unknown',\n none = 'none',\n cellular = 'cellular',\n wifi = 'wifi',\n bluetooth = 'bluetooth',\n ethernet = 'ethernet',\n wimax = 'wimax',\n vpn = 'vpn',\n other = 'other',\n}\n\nexport type NetInfoMethodType = 'HEAD' | 'GET';\n\nexport enum NetInfoCellularGeneration {\n '2g' = '2g',\n '3g' = '3g',\n '4g' = '4g',\n '5g' = '5g',\n}\n\nexport interface NetInfoConnectedDetails {\n isConnectionExpensive: boolean;\n}\n\ninterface NetInfoConnectedState<\n T extends NetInfoStateType,\n D extends Record<string, unknown> = Record<string, unknown>,\n> {\n type: T;\n isConnected: true;\n isInternetReachable: boolean | null;\n details: D & NetInfoConnectedDetails;\n isWifiEnabled?: boolean;\n}\n\ninterface NetInfoDisconnectedState<T extends NetInfoStateType> {\n type: T;\n isConnected: false;\n isInternetReachable: false;\n details: null;\n isWifiEnabled?: boolean;\n}\n\nexport interface NetInfoUnknownState {\n type: NetInfoStateType.unknown;\n isConnected: boolean | null;\n isInternetReachable: null;\n details: null;\n isWifiEnabled?: boolean;\n}\n\nexport type NetInfoNoConnectionState =\n NetInfoDisconnectedState<NetInfoStateType.none>;\nexport type NetInfoDisconnectedStates =\n | NetInfoUnknownState\n | NetInfoNoConnectionState;\n\nexport type NetInfoCellularState = NetInfoConnectedState<\n NetInfoStateType.cellular,\n {\n cellularGeneration: NetInfoCellularGeneration | null;\n carrier: string | null;\n }\n>;\nexport type NetInfoWifiState = NetInfoConnectedState<\n NetInfoStateType.wifi,\n {\n ssid: string | null;\n bssid: string | null;\n strength: number | null;\n ipAddress: string | null;\n subnet: string | null;\n frequency: number | null;\n linkSpeed: number | null;\n rxLinkSpeed: number | null;\n txLinkSpeed: number | null;\n }\n>;\nexport type NetInfoBluetoothState =\n NetInfoConnectedState<NetInfoStateType.bluetooth>;\nexport type NetInfoEthernetState = NetInfoConnectedState<\n NetInfoStateType.ethernet,\n {\n ipAddress: string | null;\n subnet: string | null;\n }\n>;\nexport type NetInfoWimaxState = NetInfoConnectedState<NetInfoStateType.wimax>;\nexport type NetInfoVpnState = NetInfoConnectedState<NetInfoStateType.vpn>;\nexport type NetInfoOtherState = NetInfoConnectedState<NetInfoStateType.other>;\nexport type NetInfoConnectedStates =\n | NetInfoCellularState\n | NetInfoWifiState\n | NetInfoBluetoothState\n | NetInfoEthernetState\n | NetInfoWimaxState\n | NetInfoVpnState\n | NetInfoOtherState;\n\nexport type NetInfoState = NetInfoDisconnectedStates | NetInfoConnectedStates;\n\nexport type NetInfoChangeHandler = (state: NetInfoState) => void;\nexport type NetInfoSubscription = () => void;\n\nexport interface NetInfoConfiguration {\n reachabilityUrl: string;\n reachabilityMethod?: NetInfoMethodType;\n reachabilityHeaders?: Record<string, string>;\n reachabilityTest: (response: Response) => Promise<boolean>;\n reachabilityLongTimeout: number;\n reachabilityShortTimeout: number;\n reachabilityRequestTimeout: number;\n reachabilityShouldRun: () => boolean;\n shouldFetchWiFiSSID: boolean;\n useNativeReachability: boolean;\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAPA,IASYA,gBAAgB,GAAAC,OAAA,CAAAD,gBAAA,0BAAhBA,gBAAgB;EAAhBA,gBAAgB;EAAhBA,gBAAgB;EAAhBA,gBAAgB;EAAhBA,gBAAgB;EAAhBA,gBAAgB;EAAhBA,gBAAgB;EAAhBA,gBAAgB;EAAhBA,gBAAgB;EAAhBA,gBAAgB;EAAA,OAAhBA,gBAAgB;AAAA;AAAA,IAchBE,yBAAyB,GAAAD,OAAA,CAAAC,yBAAA,0BAAzBA,yBAAyB;EAAzBA,yBAAyB;EAAzBA,yBAAyB;EAAzBA,yBAAyB;EAAzBA,yBAAyB;EAAA,OAAzBA,yBAAyB;AAAA"}
\ No newline at end of file
diff --git a/node_modules/@react-native-community/netinfo/lib/module/index.js b/node_modules/@react-native-community/netinfo/lib/module/index.js
index 147c72e..5de4e7c 100644
index 147c72e..3574e44 100644
--- a/node_modules/@react-native-community/netinfo/lib/module/index.js
+++ b/node_modules/@react-native-community/netinfo/lib/module/index.js
@@ -6,20 +6,26 @@
@@ -6,20 +6,27 @@
*
* @format
*/
Expand All @@ -1638,11 +1638,12 @@ index 147c72e..5de4e7c 100644
+
+// Track ongoing requests
+let isRequestInProgress = false;
+let requestQueue = [];
+
/**
* Configures the library with the given configuration. Note that calling this will stop all
* previously added listeners from being called again. It is best to call this right when your
@@ -27,23 +33,20 @@ const createState = () => {
@@ -27,23 +34,20 @@ const createState = () => {
*
* @param configuration The new configuration to set.
*/
Expand All @@ -1669,7 +1670,7 @@ index 147c72e..5de4e7c 100644
/**
* Returns a `Promise` that resolves to a `NetInfoState` object.
* This function operates on the global singleton instance configured using `configure()`
@@ -52,27 +55,33 @@ export function configure(configuration) {
@@ -52,27 +56,41 @@ export function configure(configuration) {
*
* @returns A Promise which contains the current connection state.
*/
Expand All @@ -1694,20 +1695,28 @@ index 147c72e..5de4e7c 100644
}

- return _state._fetchCurrentState();
+ // If a request is already in progress, return a promise that will resolve when the current request finishes
+ if (isRequestInProgress) {
+ return _state.latest(); // Return the latest state if a request is already in progress
+ return new Promise((resolve) => {
+ requestQueue.push(resolve);
+ });
+ }
+
+ isRequestInProgress = true;
+ return _state._fetchCurrentState().finally(() => {
+
+ return _state._fetchCurrentState().then((result) => {
+ requestQueue.forEach((resolve) => resolve(result));
+ requestQueue = [];
+ return result;
+ }).finally(() => {
+ isRequestInProgress = false;
+ });
}
+
/**
* Subscribe to the global singleton's connection information. The callback is called with a parameter of type
* [`NetInfoState`](README.md#netinfostate) whenever the connection state changes. Your listener
@@ -84,18 +93,16 @@ export function refresh() {
@@ -84,18 +102,16 @@ export function refresh() {
*
* @returns A function which can be called to unsubscribe.
*/
Expand All @@ -1727,7 +1736,7 @@ index 147c72e..5de4e7c 100644
/**
* A React Hook into this library's singleton which updates when the connection state changes.
*
@@ -103,12 +110,10 @@ export function addEventListener(listener) {
@@ -103,12 +119,10 @@ export function addEventListener(listener) {
*
* @returns The connection state.
*/
Expand All @@ -1740,23 +1749,23 @@ index 147c72e..5de4e7c 100644
const [netInfo, setNetInfo] = useState({
type: Types.NetInfoStateType.unknown,
isConnected: null,
@@ -120,6 +125,7 @@ export function useNetInfo(configuration) {
@@ -120,6 +134,7 @@ export function useNetInfo(configuration) {
}, []);
return netInfo;
}
+
/**
* A React Hook which manages an isolated instance of the network info manager.
* This is not a hook into a singleton shared state. NetInfo.configure, NetInfo.addEventListener,
@@ -129,7 +135,6 @@ export function useNetInfo(configuration) {
@@ -129,7 +144,6 @@ export function useNetInfo(configuration) {
*
* @returns the netInfo state and a refresh function
*/
-
export function useNetInfoInstance(isPaused = false, configuration) {
const [networkInfoManager, setNetworkInfoManager] = useState();
const [netInfo, setNetInfo] = useState({
@@ -142,8 +147,8 @@ export function useNetInfoInstance(isPaused = false, configuration) {
@@ -142,8 +156,8 @@ export function useNetInfoInstance(isPaused = false, configuration) {
if (isPaused) {
return;
}
Expand Down
Loading