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

onDeactivation callback is called on render in StrictMode #308

Open
Ke1sy opened this issue May 10, 2024 · 2 comments
Open

onDeactivation callback is called on render in StrictMode #308

Ke1sy opened this issue May 10, 2024 · 2 comments
Assignees

Comments

@Ke1sy
Copy link

Ke1sy commented May 10, 2024

I use the React.StrictMode in my application and onDeactivation callback for some logic.
I expect this callback to be called on unmounting or on disabling FocusLock, but in StrictMode it is called on render (it shouldn't happen), also I see that 'onActivation' also is called 2 times:
image

In comparison to it I am attaching the correct behaviour for not StrictMode:
image

Sandbox: https://codesandbox.io/p/sandbox/react-focus-lock-demo-forked-nlsfpv
Steps to reproduce this issue:

  1. open console
  2. click the button
  3. review the logs.

To see the expected behaviour, - just remove the <StrictMode> in App.js

It looks like this behaviour is broken when 'react-focus-lock' is used in the application with React v18.

@Ke1sy
Copy link
Author

Ke1sy commented May 10, 2024

@theKashey Please, review. Thanks!

@theKashey
Copy link
Owner

👍 that's a valid confusion

  • first activation callback is skipped because lock is not yet fully initialized (no ref assigned)
  • then deactivation is called via StrictMode rerunning effects
  • and then two activation callbacks called because there no prevention for double run

@theKashey theKashey self-assigned this May 11, 2024
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