Skip to content

Conversation

@Joezo
Copy link
Contributor

@Joezo Joezo commented Mar 5, 2019

What does this PR do?

Prevents fetchData within useClientRequest from updating state when a request returns, if the component has unmounted.

Related issues

closes #54

Checklist

  • I have checked the contributing document
  • I have added or updated any relevant documentation
  • I have added or updated any relevant tests

@Joezo Joezo force-pushed the cancel-on-unmount branch from 3ab9028 to d067782 Compare March 5, 2019 15:42
@Joezo Joezo marked this pull request as ready for review March 6, 2019 10:16
@Joezo Joezo force-pushed the cancel-on-unmount branch from 73fcff1 to d887ae7 Compare March 6, 2019 10:25
@Joezo Joezo requested review from bmullan91 and jackdclark and removed request for bmullan91 March 6, 2019 10:35
jackdclark
jackdclark previously approved these changes Mar 6, 2019

const fetchDataPromise = fetchData()
unmount()
await fetchDataPromise
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

bmullan91
bmullan91 previously approved these changes Mar 6, 2019
Copy link
Contributor

@bmullan91 bmullan91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


const fetchDataPromise = fetchData()
unmount()
await fetchDataPromise
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this test it should resolve the result, right? We can then add a test that after unmount it resolves undefined:

const fetchDataPromise = fetchData()
unmount()
const firstResult = await fetchDataPromise // <- expected actual result
const secondResult = await fetchData() // <- expected undefined

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a test for that 👍

@Joezo Joezo dismissed stale reviews from bmullan91 and jackdclark via eb50f0f March 6, 2019 13:00
@Joezo Joezo merged commit 2766793 into master Mar 6, 2019
@Joezo Joezo deleted the cancel-on-unmount branch March 6, 2019 14:40
Joezo added a commit that referenced this pull request Mar 6, 2019
Prevents `fetchData` within `useClientRequest` from updating state when a request returns, if the component has unmounted.

closes #54

- [x] I have checked the [contributing document](../blob/master/CONTRIBUTING.md)
- [x] I have added or updated any relevant documentation
- [x] I have added or updated any relevant tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Requests are not cancelled on unmount

3 participants