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
If application root is reinitialized, update ActionSheet and Toast refs #1700
Conversation
Will this pull request be approved soon to fix both ActionSheet and Toast issues? |
If there's any additional information that I can provide to assist with this pull request, please let me know. Thank you! |
Is there an ETA on this PR? |
+1 |
3 similar comments
+1 |
+1 |
+1 |
@@ -14,12 +14,12 @@ class Root extends Component { | |||
{this.props.children} | |||
<Toast | |||
ref={c => { | |||
if (!Toast.toastInstance) Toast.toastInstance = c; | |||
if (c) Toast.toastInstance = c; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you don't need to check if c
is valid
. Just do the assignment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking a look at this @douglasjunior. Does GeekyAnts have a preference on how to handle the case where c
is null
? @akhil-geekyants @SupriyaKalghatgi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://reactjs.org/docs/refs-and-the-dom.html#callback-refs
React will call the ref callback with the DOM element when the component mounts, and call it with null when it unmounts. ref callbacks are invoked before componentDidMount or componentDidUpdate lifecycle hooks.
I think if the component has been unmounted, you should not keep the ref. This is memory leak.
@akhil-geekyants @douglasjunior @fredmon3 any updates? |
This week 💯 |
@SupriyaKalghatgi |
"native-base": "^2.8.1", to reproduce this issue follow these steps: actionsheet available in page 1, for the first actionsheet is working |
Having the same issue as @gogulanareshkw. |
This PR is related to issues #1397, #1315, #937.
There is potential that React Native may unmount and remount the root node of the application due to Android lifecycle events without clearing the JS execution environment. (This is possible even if native-base's
Root
is the top level component.) This results inactionSheetInstance
being invalid as it pointed to the previously mounted application root's ActionSheet component that was unmounted.This pull request updates the static
actionSheetInstance
andtoastInstance
refs regardless of what state they are in such that stale refs will be overwritten appropriately.According to the React Ref documentation:
Thus, there is a null check on
c
in the ref callbacks.