Skip to content

fix useEffect regression by using invokeCleanup in unmount#2542

Merged
marvinhagemeister merged 1 commit intopreactjs:masterfrom
fuzetsu:fix-effect-cleanup-regression
May 18, 2020
Merged

fix useEffect regression by using invokeCleanup in unmount#2542
marvinhagemeister merged 1 commit intopreactjs:masterfrom
fuzetsu:fix-effect-cleanup-regression

Conversation

@fuzetsu
Copy link
Copy Markdown
Contributor

@fuzetsu fuzetsu commented May 18, 2020

This fixes a regression caused by #2494

The unmount hook cleanup wasn't using invokeCleanup so it was relying on non functions never being assigned to _cleanup in the first place.

In my project upgrading to 10.4.2 caused a useEffect like this to crash:

useEffect(async () => {
  await apiCall()
}, [])

Perhaps not a recommended usage since the typescript types would disallow it.. but still.

The promise ends up as the _cleanup and it is of course truthy causing the component to crash when unmounted.

I wrote a quick test to validate this, but not sure if I did in the best way 🤔 advice would be appreciated there.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 99.798% when pulling 46706f6 on fuzetsu:fix-effect-cleanup-regression into 9c0b8e3 on preactjs:master.

@fuzetsu fuzetsu changed the title use invokeCleanup in unmount fix useEffect regression by using invokeCleanup in unmount May 18, 2020
Copy link
Copy Markdown
Member

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

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

Looks good to me! Also good that we reuse that variable, I missed that my bad 😅

Copy link
Copy Markdown
Member

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

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

Good catch! We'll publish a patch release shortly.

@marvinhagemeister marvinhagemeister merged commit de38e27 into preactjs:master May 18, 2020
@fuzetsu fuzetsu deleted the fix-effect-cleanup-regression branch May 18, 2020 22:36
@developit developit mentioned this pull request May 18, 2020
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.

4 participants