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

Bug Report - Debounce is just delaying requests, not really debouncing them #918

Open
3 of 4 tasks
iuricernov opened this issue Nov 16, 2023 · 4 comments
Open
3 of 4 tasks
Labels

Comments

@iuricernov
Copy link

iuricernov commented Nov 16, 2023

Describe the bug

The debounce feature is just delaying the execution of the request code, and not eliminating the unnecessary requests.

For example, if I set a debounce interval and type "Los Angeles" quick enough on the field, it is doing 11 requests ("L", "Lo", "Los", ..., "Los Angeles") after an interval. The expected behavior for a debounced operation would be to do only one request ("Los Angeles") after the interval.

Reproduction - (required - issue will be closed without this)

To reproduce:

  • Add a GooglePlacesAutocomplete inside your app, with debounce of ~200ms
  • Use Flipper (or some alternative) to monitor the API calls done by the app
  • Type "Los Angeles" quick on the auto complete field
  • Notice that Flipper will show 11 calls to Google API: "L", "Lo", "Los", "Los ", "Los A", ...
  • The expected would be only one call with "Los Angeles" after the last letter was typed, and the debounce time was passed.

Additional context

  • Library Version: 2.5.1

  • React Native Version: not relevant

  • iOS

  • Android

  • Web

If you are using expo please indicate here:

  • I am using expo

Fix

This is happening because we are calling _.debounce many times with different contexts. I fixed it using setTimeout on my own fork:
https://github.com/iuricernov/react-native-google-places-autocomplete/tree/debounce-fix

The diff that fixes the issue:
master...iuricernov:react-native-google-places-autocomplete:debounce-fix

@FacundoLastra
Copy link

hi! i tested the fix, and work fine! thanks!

@luannt102
Copy link

Thanks @iuricernov This fix is ​​working fine.

@alianza
Copy link

alianza commented Jul 2, 2024

Thanks @iuricernov. I don't understand why this hasn't been fixed yet.

@rick89
Copy link

rick89 commented Nov 29, 2024

Hello, any idea when this fix will be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants