react-native-google-places-autocomplete icon indicating copy to clipboard operation
react-native-google-places-autocomplete copied to clipboard

Error: Request has not been opened

Open Willham12 opened this issue 2 years ago • 15 comments

v2.5.3

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

Willham12 avatar Sep 28 '23 07:09 Willham12

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.

flogoerlich avatar Sep 29 '23 09:09 flogoerlich

Same issue

ArturoTorresMartinez avatar Oct 03 '23 18:10 ArturoTorresMartinez

Same problem

BrayhanV avatar Oct 04 '23 15:10 BrayhanV

any solution?

PrasanthDante03 avatar Oct 05 '23 12:10 PrasanthDante03

same problem here

Felipelpk avatar Oct 09 '23 15:10 Felipelpk

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

athaljen avatar Oct 27 '23 11:10 athaljen

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

Najeeb-Idrees avatar Dec 04 '23 16:12 Najeeb-Idrees

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

jeffreyvalle avatar Dec 19 '23 20:12 jeffreyvalle

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

nppull avatar Dec 20 '23 09:12 nppull

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.

jeffreyvalle avatar Dec 20 '23 18:12 jeffreyvalle

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

bjarheim avatar Jan 18 '24 12:01 bjarheim

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

Can you explain where to set debounce please !

biswajeet728 avatar Feb 22 '24 15:02 biswajeet728

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.

manibharathyr avatar Feb 23 '24 06:02 manibharathyr

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

karan-sps avatar Mar 13 '24 05:03 karan-sps

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?

Hassaan0 avatar Jun 24 '24 08:06 Hassaan0