react-native-navigation icon indicating copy to clipboard operation
react-native-navigation copied to clipboard

iOS: Navigation.pop promise doesn't resolve and componentWillUnmount doesn't run as expected

Open Caundy opened this issue 2 years ago • 7 comments

🐛 Bug Report

I ran into an issue where an ActivityIndicator displayed in a FlatList prevents a screen Navigation.push'ed on top and then Navigation.pop'ped from properly unmounting - Navigation.pop promise doesn't resolve and componentWillUnmount doesn't run.

I have compiled my initial findings in this comment: https://github.com/wix/react-native-navigation/issues/5348#issuecomment-1088695792

As described in the linked comment, Navigation.pop promise doesn't resolve unless some additional actions are performed and componentWillUnmount of the popped screen doesn't run.

I have also prepared a minimal reproducible example, which can be found here: https://github.com/Caundy/rnn-unmount-bug-reproduction

Have you read the Contributing Guidelines on issues?

Yes.

To Reproduce

  1. Clone the repository at https://github.com/Caundy/rnn-unmount-bug-reproduction
  2. run yarn
  3. run cd ios && pod install
  4. run cd .. && npx react-native run-ios
  5. After the app has started, press on the Open item 0's details
  6. On the Detail screen, press Go back, which triggers Navigation.pop with Detail screen's componentId as an argument
  7. Observe Navigation.pop not resolving and code in componentWillUnmount of the Detail screen not running (which would be expected at this point)
  8. Once again, press on the Open item 0's details, which Navigation.push'es the Detail screen into the stack
  9. Observe Navigation.pop resolving and componentWillUnmount running of the previously popped screen running

Additionally, this behaviour can't be observed when using the topBar's back button to dismiss the Detail screen.

Expected behavior

Navigation.pop should resolve or reject and componentWillUnmount should run, regardless of whether an ActivityIndicator is present or not in the underlying screen's FlatList. I am not 100% clear on the actual cause of this behaviour but having an ActivityIndicator appears to allow reproducing it reliably.

Actual Behavior

In the provided scenario, Navigation.pop doesn't resolve or reject and componentWillUnmount of the popped screen doesn't run unless additional actions are taken.

Your Environment

  • React Native Navigation version: "^7.26.0"
  • React Native version: "0.63.4"
  • Platform(s) (iOS, Android, or both?): iOS
  • Device info (Simulator/Device? OS version? Debug/Release?): simulator and physical device (i.e. iPhone 8+ running iOS 15.1)

Reproducible Demo

https://github.com/Caundy/rnn-unmount-bug-reproduction

Are you willing to resolve this issue by submitting a Pull Request?

  • ✖️   Yes, I have the time, and I know how to start.
  • ✖️   Yes, I have the time, but I don't know how to start. I would need guidance.
  • ✅   No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

Caundy avatar Apr 07 '22 10:04 Caundy

Running into the same issue myself. In my case I am trying to run a cleanup in a useEffect with an empty dependency array, and it doesn't run sometimes whenever I pop. However, it does run when I go back to the same screen, but it runs after the new instance of the same screen mounts, meaning it runs too late.

hmust92 avatar Apr 15 '22 11:04 hmust92

@Caundy Any workarounds you might have figured out for this?

hmust92 avatar Apr 15 '22 11:04 hmust92

@hmust92 Sorry for the delay, you've probably tackled this already :)

Given that the cause appeared to have been the ActivityIndicator's animation or its presence, I simply made sure it's not being rendered in the FlatList's footer when opening the details screen that runs some cleanup code on unmount.

Not happy with having to use that type of workaround but it does get the job done

Caundy avatar Apr 28 '22 08:04 Caundy

any update on this? I'm having the same issue.

  1. if I swipe the screen to go back it will trigger componentWillUnMount
  2. if I call Navigation.Pop() it not trigger componentWillUnMount

RZulfikri avatar Jun 28 '22 08:06 RZulfikri

++++++++

sam-houle1 avatar Nov 14 '22 20:11 sam-houle1

I have same issue with RN 0.70.6 & react-native-navigation 7.32.1. any update?

hoangnguyen8895 avatar Apr 20 '23 07:04 hoangnguyen8895