From 68a0214222a95b066a402f6bd25bf1b6c01576a9 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 22 May 2026 11:02:37 +0000 Subject: [PATCH] fix(storage): defer binding dispatches until public storage clear completes EnsembleStorage.clear() called clearPublicStorage() without awaiting; binding listeners re-evaluate expressions by reading GetStorage, so notifications could run while keys still existed and refresh the UI from stale values. Co-authored-by: Sharjeel Yunus --- modules/ensemble/lib/framework/data_context.dart | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/ensemble/lib/framework/data_context.dart b/modules/ensemble/lib/framework/data_context.dart index d964e69ac..ea7d1a1f7 100644 --- a/modules/ensemble/lib/framework/data_context.dart +++ b/modules/ensemble/lib/framework/data_context.dart @@ -800,10 +800,14 @@ class EnsembleStorage with Invokable { void clear() { final keys = ensembleStorageClearDispatchKeys(StorageManager().getKeys()); - StorageManager().clearPublicStorage(); - for (final key in keys) { - ScreenController().dispatchStorageChanges(context, key, null); - } + // clearPublicStorage is async; binding listeners re-evaluate by reading + // GetStorage. Dispatch only after removal completes so eval() does not + // observe stale persisted values (see PR discussion on #2227). + unawaited(StorageManager().clearPublicStorage().whenComplete(() { + for (final key in keys) { + ScreenController().dispatchStorageChanges(context, key, null); + } + })); } @override