Skip to content

Remove setState on unmounted component warning#3576

Merged
JoviDeCroock merged 1 commit intopreactjs:masterfrom
ekwoka:clean-warnings
Jun 21, 2022
Merged

Remove setState on unmounted component warning#3576
JoviDeCroock merged 1 commit intopreactjs:masterfrom
ekwoka:clean-warnings

Conversation

@ekwoka
Copy link
Contributor

@ekwoka ekwoka commented Jun 21, 2022

As discussed in #3470 this warning can cause unwarranted concern in users.

Following the path of React, where this warning was removed facebook/react#22114 (comment) it can likely be similarly removed from Preact.

Basically, Preact already checks if the component is unmounted, hence its ability to provide the warning, and most users that run into this implement anti-patterns to suppress the warning instead of addressing the actual issue being warned about.

The actual issue is less likely to be an indication of a real memory leak, and more likely to be just a single late update.

With all this in mind, it makes sense to also remove the warning here.

What this does:

  • Removes the warning for setting state after a component has unmounted
  • Removes test that checked for warning

Resolves #3470

Copy link
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.

Awesome, thank you!

@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.446% when pulling 7abb5ac on ekwoka:clean-warnings into 894f7ba on preactjs:master.

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.

Can't call "this.setState" on an unmounted component error.

3 participants

Comments