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

originalFocusedElement cannot be garbage collected when returnFocus is false #173

Closed
mariuslukose opened this issue Sep 22, 2021 · 1 comment
Assignees

Comments

@mariuslukose
Copy link

mariuslukose commented Sep 22, 2021

Description

  • onActivation handler in Lock.js file sets originalFocusedElement ref to document.activeElement (if it exists):
    originalFocusedElement.current = (
  • But it does not get reset in returnFocus handler if returnFocus prop isn't true (nor, apparently, anywhere else..):
    if (Boolean(shouldReturnFocus) && current && current.focus) {

Issue
If originalFocusedElement is removed from DOM, but Lock component is not, then that originalFocusedElement cannot be garbage collected causing a memory leak.

Maybe originalFocusedElement ref could be reset in returnFocus handler, even when returnFocus prop is false?

@theKashey
Copy link
Owner

Good catch. Let me refactor the code a little bit to make onDeactivation act as a proper destructor.

@theKashey theKashey self-assigned this Sep 26, 2021
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

No branches or pull requests

2 participants