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] safeToRemove Callback Recreated on Parent Re-render #2801

Closed
custardcream98 opened this issue Sep 14, 2024 · 0 comments · Fixed by #2802
Closed

[BUG] safeToRemove Callback Recreated on Parent Re-render #2801

custardcream98 opened this issue Sep 14, 2024 · 0 comments · Fixed by #2802
Labels
bug Something isn't working

Comments

@custardcream98
Copy link
Contributor

1. Read the FAQs 👇

2. Describe the bug

The usePresence hook provides a safeToRemove callback. However, if the parent re-renders during the exit animation and I add safeToRemove to the useEffect dependency array, the function is recreated, causing the effect to trigger unnecessarily.

This happens despite #2431 wrapping the callback with the useCallback hook.

After looking into it, I found that the onExitComplete function in PresenceContext is being recreated unnecessarily. Take a look at the PR I'll be submitting.

3. IMPORTANT: Provide a CodeSandbox reproduction of the bug

https://codesandbox.io/p/sandbox/safetoremove-re-create-issue-nzvmfy

4. Steps to reproduce

Steps to reproduce the behavior:

  1. Go to codesandbox.
  2. Run the app and check the console log.

5. Expected behavior

The safeToRemove function should remain the same, regardless of whether the parent is re-rendered or not.

@custardcream98 custardcream98 added the bug Something isn't working label Sep 14, 2024
@custardcream98 custardcream98 changed the title [BUG] onExitComplete funciton in PresenceContext is being unnecessarily recreated [BUG] safeToRemove Callback Recreated on Parent Re-render Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant