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

fix: use useRef for Host queue to improve stability #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

teaualune
Copy link

While using this library to build "overlay" widgets in our RN project, we discovered that some Portals did not unmount correctly.

For instance, our react-navigation based project has ScreenA containing OverlayA, which are implemented with Portal. When ScreenA is popped, we found that sometimes OverlayA is not unmounted, out of our expectation.

After some digging, it seems that the queue array in Host component might be one of the problem: since Host is a functional component, queue is re-initialized each time Host re-renders. According to the original implementation, queue is a class member, so it should become a RefObject after converting to functional component.

I utilized patch-package to create a hotfix for my project and the behavior becomes expected, so I created this PR to address the problem. This PR rewrites queue into a RefObject with useRef as well as extracts type definition of queue into IPortalAction.

@lucasjohnston
Copy link

For anyone looking for a patch: https://gist.github.com/lucasjohnston/5bf626fae923009ae1cf5a5db894842f

In the process of debugging our freezing issues I came across this thread and realised modals aren't unmounting properly as OP described.
Currently trying to fix my issue with a combination of this patch and using InteractionManager.runAfterInteractions().

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.

2 participants