fix(chat): prevent rapid invalidations with safe ref check

This commit is contained in:
cogwheel0
2025-12-06 20:35:24 +05:30
parent 1380a84989
commit ce11eed11a

View File

@@ -1878,12 +1878,16 @@ Future<void> _sendMessageInternal(
// Adding a small delay to prevent rapid invalidations that could cause duplicates // Adding a small delay to prevent rapid invalidations that could cause duplicates
Future.delayed(const Duration(milliseconds: 100), () { Future.delayed(const Duration(milliseconds: 100), () {
try { try {
// Guard against using ref after widget disposal // Guard against using ref after provider disposal
if (ref.mounted == true) { // 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); refreshConversationsCache(ref);
} }
} catch (_) { } catch (_) {
// If ref doesn't support mounted or is disposed, skip // If ref is disposed or invalid, skip
} }
}); });
} catch (e) { } catch (e) {