[MBL-19897][All] Fix inbox list not refreshing after screen rotation on details screen#3633
Conversation
…on details screen Move sharedEvents subscription from onViewCreated to onCreate so the fragment is always listening even when its view hasn't been recreated yet (back stack lazy view inflation after rotation). Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
There was a problem hiding this comment.
Review Summary
This PR fixes a legitimate bug in InboxFragment where calling lifecycleScope.collectOneOffEvents(sharedEvents.events, …) inside onViewCreated could create duplicate subscriptions each time the fragment's view was destroyed and recreated (e.g., returning from the details screen via back-press). Since lifecycleScope is bound to the Fragment lifecycle (not the View lifecycle), the coroutine launched on each onViewCreated call was never cancelled on view destruction, resulting in N concurrent subscribers after N view recreations.
Moving the subscription to onCreate is the correct fix — it is called exactly once per Fragment instance, ensuring a single subscription for the lifetime of the fragment.
The handler handleSharedViewModelAction only calls viewModel.invalidateCache() and viewModel.refresh() — pure ViewModel operations with no dependency on the View — so it is safe to start collecting before onViewCreated.
Issues Found
-
Same bug exists in
InboxDetailsFragment—libs/pandautils/src/main/java/com/instructure/pandautils/features/inbox/details/InboxDetailsFragment.kt, line 79// onCreateView — called every time the view is (re)created lifecycleScope.collectOneOffEvents(sharedEvents.events, ::handleSharedViewModelAction)InboxDetailsFragmentstill subscribes tosharedEvents.eventsvialifecycleScopeinsideonCreateView. If that fragment's view is ever recreated while the fragment instance survives (e.g., configuration change withretainInstance, or back-stack behaviour depending on navigation setup), duplicate subscriptions will accumulate in the same way. Consider moving this call to anonCreateoverride inInboxDetailsFragmentas well, consistent with the fix applied here.
Overall: The change is minimal, targeted, and correct. No concerns with the modified code itself.
🧪 Unit Test Results✅ 📱 Parent App
✅ 📱 Student App
✅ 📱 Teacher App
✅ 🌅 Horizon
✅ 📦 Submodules
📊 Summary
Last updated: Wed, 08 Apr 2026 07:38:55 GMT |
📊 Code Coverage Report✅ Student
✅ Teacher
✅ Pandautils
📈 Overall Average
|
Test plan:
refs: MBL-19897
affects: Student, Teacher, Parent
release note: Fixed inbox list not updating after performing operations on the conversation details screen following a screen rotation.