provider lifecycle hardenings

This commit is contained in:
Fabian Freund
2026-05-06 18:32:45 +02:00
parent d5f977a3d2
commit fee15cb8d2
25 changed files with 246 additions and 94 deletions
@@ -39,6 +39,10 @@ class WebExtensionsState extends _$WebExtensionsState {
: _imageCache = LRUCache(50, onEvict: (image) => image.dispose());
void _onExtensionUpdate(ExtensionDataEvent event) {
if (!ref.mounted) {
return;
}
final ExtensionDataEvent(:extensionId, :data) = event;
if (data != null) {
@@ -81,6 +85,11 @@ class WebExtensionsState extends _$WebExtensionsState {
final image = await tryDecodeImage(bytes);
if (!ref.mounted) {
image?.dispose();
return;
}
if (image != null) {
// set() will evict the old entry via onEvict callback, which handles disposal
_imageCache.set(extensionId, image);
@@ -185,13 +194,13 @@ class WebExtensionsState extends _$WebExtensionsState {
},
);
ref.onDispose(() async {
ref.onDispose(() {
// Dispose all cached images
_imageCache.clear();
// Cancel all stream subscriptions
for (final sub in subscriptions) {
await sub.cancel();
unawaited(sub.cancel());
}
});
@@ -62,7 +62,7 @@ final class WebExtensionsStateProvider
}
String _$webExtensionsStateHash() =>
r'13cbbea409b5b643eb6766689f6b23a4d1701204';
r'e067323e9a0a466e46e0c4d529667950ee62d4ca';
final class WebExtensionsStateFamily extends $Family
with