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] На размонтированной кнопке вызывается setState #3901

Closed
SevereCloud opened this issue Dec 26, 2022 · 2 comments
Assignees
Labels
🔥 fix bounty https://vk.com/fixbounty type:bug

Comments

@SevereCloud
Copy link
Contributor

Варнинг генерируется preact при переключении между панелями

Can't call "this.setState" on an unmounted component. This is a no-op, but it indicates a memory leak in your application.

const onBlur = useCallback(
(event: FocusEvent<HTMLElement>) => {
event.stopPropagation();
setIsFocused(false);
},
[setIsFocused]
);

@SevereCloud SevereCloud added 🔥 fix bounty https://vk.com/fixbounty type:bug labels Dec 26, 2022
@levtsypanov
Copy link

levtsypanov commented May 19, 2023

Может надо добавить условие, проверяющее находится ли элемент в DOM-дереве, перед тем как вызывать функцию setState.

const onBlur = useCallback(
  (event: FocusEvent<HTMLElement>) => {
    event.stopPropagation();
    if (ref.current) { // добавлено условие проверки на существование элемента в DOM-дереве
      setIsFocused(false);
    }
  },
  [setIsFocused, ref]
);

@SevereCloud SevereCloud changed the title [Bug] При размонтировании кнопки вызывается onBlur [Bug] На размонтированной кнопке вызывается setState May 24, 2023
@BlackySoul BlackySoul self-assigned this Jan 23, 2024
@BlackySoul
Copy link
Contributor

Данный варнинг удален в react и preact

@BlackySoul BlackySoul closed this as not planned Won't fix, can't repro, duplicate, stale Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔥 fix bounty https://vk.com/fixbounty type:bug
Projects
Archived in project
Development

No branches or pull requests

3 participants