FaridSafi / react-native-google-places-autocomplete

Customizable Google Places autocomplete component for iOS and Android React-Native apps
MIT License
2k stars 848 forks source link

Error: Request has not been opened #910

Closed Willham12 closed 1 month ago

Willham12 commented 11 months ago

v2.5.3

See https://github.com/FaridSafi/react-native-google-places-autocomplete/blob/master/GooglePlacesAutocomplete.js#L559

flogoerlich commented 11 months ago

image

"react-native": "0.72.5",

Same error here after upgrading the react native version.

I would highly appreciate any insights to this issue, thanks the awesome work.

ArturoTorresMartinez commented 11 months ago

Same issue

BrayhanV commented 11 months ago

Same problem

PrasanthDante03 commented 11 months ago

any solution?

Felipelpk commented 11 months ago

same problem here

athaljen commented 10 months ago

i fixed it by removing the line that throw Error.

Go to react-native>Libraries>Network>XMLHttpRequest.js Line 517

- throw new Error('Request has not been opened'); + console.warn('Request has not been opened');

then patch-package react-native that's all

Najeeb-Idrees commented 9 months ago

@FaridSafi : Any update? When this will be fixed inside the package?

jeffreyvalle commented 8 months ago

Update on this? Experiencing the same issue, is the solution really to remove the error logic itself?

nppull commented 8 months ago

My solution I am not use lib, I use url from google

https://maps.googleapis.com/maps/api/place/autocomplete/json ?input=Vict &language=fr &types=geocode &key=YOUR_API_KEY

https://developers.google.com/maps/documentation/places/web-service/autocomplete

jeffreyvalle commented 8 months ago

i fixed it by removing the line that throw Error.

Go to react-native>Libraries>Network>XMLHttpRequest.js Line 517

  • throw new Error('Request has not been opened'); + console.warn('Request has not been opened');

then patch-package react-native that's all

I recommend instead modifying GooglePlacesAutocomplete.js, right before request.send() on line 570 add an if-gate to catch any unopened requests before calling request.send(). The error is being caused by request.send() being called on a request that is not yet opened. You can check for this case and only send if the request is opened, or readyState === 1, with:

if (request.readyState === 1) {
        request.send();
} else {
        console.warn('google places autocomplete: attempt to send unopened request failed');
}

This way you at least don't have to alter the logic for all XMLHttpRequest(which I am personally uncomfortable with), just the offending GooglePlacesAutocomplete logic.

I did not spend time looking into why/how a single request is failing to set readyState = 1. Someone else may dig into that and solve the overall issue. On my end, only 1 request out of many was failing to set readyState = 1, causing the 'Request has not been opened' error. This only occurs after the user navigates away from the screen that contains the GooglePlacesAutocomplete component/import.

Go ahead and add a console log right before line 570 in GooglePlacesAutocomplete.js and see what you get, make sure to log out any request where request.readyState !== 1 so you catch requests that aren't open when they should be. If you're getting the error from a different line in GooglePlacesAutocomplete, I recommend doing the same console logging wherever the nearest request.send() is to your error, you may be able to find a solution to your problem.

Hope this helps, happy coding.

bjarheim commented 7 months ago

Setting debounce to more than 0 (eg. debounce={300}) fixed the issue for me.

biswajeet728 commented 6 months ago

Setting debounce to more than 0 (eg. debounce={300}) fixed the issue for me.

Can you explain where to set debounce please !

manibharathyr commented 6 months ago

Setting debounce to more than 0 (eg. debounce={300}) fixed the issue for me.

Can you explain where to set debounce please !

You can put the prop in GooglePlacesAutocomplete

<GooglePlacesAutocomplete debounce={300} />

But it doesn't work, still throws an error.

karan-sps commented 6 months ago

wrapping [ request.send(); ] everywhere with try catch block solved my crash in release.

Hassaan0 commented 2 months ago

Setting debounce to more than 0 (eg. debounce={300}) fixed the issue for me.

Thank you, the issue has been resolved for me. However, I'm curious as to why this problem occurred. I've been using 'react-native-google-places-autocomplete' for the past 6-7 months without any issues, and now it suddenly appeared. Could you provide some insight into why this might have happened?