From ce11eed11ac7bc87188a272d873c7742c407d401 Mon Sep 17 00:00:00 2001 From: cogwheel0 <172976095+cogwheel0@users.noreply.github.com> Date: Sat, 6 Dec 2025 20:35:24 +0530 Subject: [PATCH] fix(chat): prevent rapid invalidations with safe ref check --- lib/features/chat/providers/chat_providers.dart | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/features/chat/providers/chat_providers.dart b/lib/features/chat/providers/chat_providers.dart index 380e892..c123b15 100644 --- a/lib/features/chat/providers/chat_providers.dart +++ b/lib/features/chat/providers/chat_providers.dart @@ -1878,12 +1878,16 @@ Future _sendMessageInternal( // Adding a small delay to prevent rapid invalidations that could cause duplicates Future.delayed(const Duration(milliseconds: 100), () { try { - // Guard against using ref after widget disposal - if (ref.mounted == true) { + // Guard against using ref after provider disposal + // Only Ref has .mounted; WidgetRef/ProviderContainer don't support + // this check, so we proceed and let the underlying read operations + // handle any disposal gracefully. + final isMounted = ref is Ref ? ref.mounted : true; + if (isMounted) { refreshConversationsCache(ref); } } catch (_) { - // If ref doesn't support mounted or is disposed, skip + // If ref is disposed or invalid, skip } }); } catch (e) {