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

Debounced function calls should be cleaned up on unmount #1322

Closed
domarmstrong opened this issue Sep 30, 2021 · 0 comments · Fixed by #1582 · May be fixed by OKEAMAH/zerion-wallet-extension#8, OKEAMAH/proof-of-humanity-web#12 or InfiniteLove2020/gutenberg#6

Comments

@domarmstrong
Copy link

  • downshift version: master

Problem description:

I'm getting some intermittent test failures from a status message being added to the document by a previous test due to a debounce not being cleaned up.

Suggested solution:

updateA11yStatus(

function useA11yMessageSetter(
  getA11yMessage,
  dependencyArray,
  {isInitialMount, highlightedIndex, items, environment, ...rest},
) {
  // Sets a11y status message on changes in state.
  useEffect(() => {
    if (isInitialMount || isReactNative) {
      return
    }

    updateA11yStatus(
      () =>
        getA11yMessage({
          highlightedIndex,
          highlightedItem: items[highlightedIndex],
          resultCount: items.length,
          ...rest,
        }),
      environment.document,
    )
    
    // cancel the debounced function in cleanup
    return () => updateA11yStatus.cancel()
    
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, dependencyArray)
}

This isn't a perfect solution as when there are multiple instances, one unmounting could affect calls made from another instance. You could either track the number of instances, or make the callbacks specific to each instance though.

@silviuaavram silviuaavram mentioned this issue Dec 19, 2022
Closed
10 tasks
@silviuaavram silviuaavram mentioned this issue Jul 15, 2023
Closed
7 tasks
silviuaavram added a commit that referenced this issue Mar 20, 2024
<!--
Thanks for your interest in the project. Bugs filed and PRs submitted are appreciated!

Please make sure that you are familiar with and follow the Code of Conduct for
this project (found in the CODE_OF_CONDUCT.md file).

Also, please make sure you're familiar with and follow the instructions in the
contributing guidelines (found in the CONTRIBUTING.md file).

If you're new to contributing to open source projects, you might find this free
video course helpful: http://kcd.im/pull-request

Please fill out the information below to expedite the review and (hopefully)
merge of your pull request!
-->

<!-- What changes are being made? (What feature/bug is being fixed here?) -->

**What**:
BREAKING CHANGE: Release Downshift v9.

<!-- Why are these changes necessary? -->

**Why**:
Release the changes in:
- #1580
- #1579
- #1583

Closes #1322.
Closes #1244.
Closes #1227
Closes #1225.
<!-- How were these changes implemented? -->

**How**:
Merged the PRs in this branch.
<!-- Have you done all of these things?  -->

**Checklist**:

<!-- add "N/A" to the end of each line that's irrelevant to your changes -->

<!-- to check an item, place an "x" in the box like so: "- [x] Documentation" -->

- [x] Documentation
- [x] Tests
- [x] TypeScript Types
- [ ] Flow Types
- [x] Ready to be merged
      <!-- In your opinion, is this ready to be merged as soon as it's reviewed? -->

<!-- feel free to add additional comments -->
mergify bot referenced this issue in SvenKirschbaum/musikbot-frontend Mar 22, 2024
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [downshift](https://downshift-js.com) ([source](https://togithub.com/downshift-js/downshift)) | [`^8.3.1` -> `^9.0.0`](https://renovatebot.com/diffs/npm/downshift/8.5.0/9.0.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/downshift/9.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/downshift/9.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/downshift/8.5.0/9.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/downshift/8.5.0/9.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>downshift-js/downshift (downshift)</summary>

### [`v9.0.0`](https://togithub.com/downshift-js/downshift/releases/tag/v9.0.0)

[Compare Source](https://togithub.com/downshift-js/downshift/compare/v8.5.0...v9.0.0)

##### Features

-   V9 ([#&#8203;1582](https://togithub.com/downshift-js/downshift/issues/1582)) ([5b0d503](https://togithub.com/downshift-js/downshift/commit/5b0d5031c1c11455ba18fa1516a259b4ed9357a1))

##### BREAKING CHANGES

-   Release Downshift v9.



**Why**:
Release the changes in:

-   [https://github.com/downshift-js/downshift/pull/1580](https://togithub.com/downshift-js/downshift/pull/1580)
-   [https://github.com/downshift-js/downshift/pull/1579](https://togithub.com/downshift-js/downshift/pull/1579)
-   [https://github.com/downshift-js/downshift/pull/1583](https://togithub.com/downshift-js/downshift/pull/1583)

Closes [https://github.com/downshift-js/downshift/issues/1322](https://togithub.com/downshift-js/downshift/issues/1322).
Closes [https://github.com/downshift-js/downshift/issues/1244](https://togithub.com/downshift-js/downshift/issues/1244).
Closes [https://github.com/downshift-js/downshift/issues/1227](https://togithub.com/downshift-js/downshift/issues/1227)
Closes [https://github.com/downshift-js/downshift/issues/1225](https://togithub.com/downshift-js/downshift/issues/1225).



**How**:
Merged the PRs in this branch.



**Checklist**:





-   \[x] Documentation
-   \[x] Tests
-   \[x] TypeScript Types
-   \[ ] Flow Types
-   \[x] Ready to be merged 



</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/SvenKirschbaum/musikbot-frontend).
guilhermespopolin referenced this issue in HedvigInsurance/racoon Mar 27, 2024
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [downshift](https://downshift-js.com) ([source](https://togithub.com/downshift-js/downshift)) | [`8.5.0` -> `9.0.0`](https://renovatebot.com/diffs/npm/downshift/8.5.0/9.0.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/downshift/9.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/downshift/9.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/downshift/8.5.0/9.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/downshift/8.5.0/9.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>downshift-js/downshift (downshift)</summary>

### [`v9.0.0`](https://togithub.com/downshift-js/downshift/releases/tag/v9.0.0)

[Compare Source](https://togithub.com/downshift-js/downshift/compare/v8.5.0...v9.0.0)

##### Features

-   V9 ([#&#8203;1582](https://togithub.com/downshift-js/downshift/issues/1582)) ([5b0d503](https://togithub.com/downshift-js/downshift/commit/5b0d5031c1c11455ba18fa1516a259b4ed9357a1))

##### BREAKING CHANGES

-   Release Downshift v9.

<!-- Why are these changes necessary? -->

**Why**:
Release the changes in:

-   [https://github.com/downshift-js/downshift/pull/1580](https://togithub.com/downshift-js/downshift/pull/1580)
-   [https://github.com/downshift-js/downshift/pull/1579](https://togithub.com/downshift-js/downshift/pull/1579)
-   [https://github.com/downshift-js/downshift/pull/1583](https://togithub.com/downshift-js/downshift/pull/1583)

Closes [https://github.com/downshift-js/downshift/issues/1322](https://togithub.com/downshift-js/downshift/issues/1322).
Closes [https://github.com/downshift-js/downshift/issues/1244](https://togithub.com/downshift-js/downshift/issues/1244).
Closes [https://github.com/downshift-js/downshift/issues/1227](https://togithub.com/downshift-js/downshift/issues/1227)
Closes [https://github.com/downshift-js/downshift/issues/1225](https://togithub.com/downshift-js/downshift/issues/1225).

<!-- How were these changes implemented? -->

**How**:
Merged the PRs in this branch.

<!-- Have you done all of these things?  -->

**Checklist**:

<!-- add "N/A" to the end of each line that's irrelevant to your changes -->

<!-- to check an item, place an "x" in the box like so: "- [x] Documentation" -->

-   \[x] Documentation
-   \[x] Tests
-   \[x] TypeScript Types
-   \[ ] Flow Types
-   \[x] Ready to be merged <!-- In your opinion, is this ready to be merged as soon as it's reviewed? -->

<!-- feel free to add additional comments -->

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 2pm every weekday" in timezone Europe/Stockholm, Automerge - "after 6am and before 2pm every weekday" in timezone Europe/Stockholm.

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/HedvigInsurance/racoon).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yNjkuMiIsInVwZGF0ZWRJblZlciI6IjM3LjI2OS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment