@@ -42,18 +42,21 @@ class RefreshSearchExecutor extends ActionExecutor {
4242 final direction = data['direction' ] as String ? ?? 'down' ;
4343 final paginationConfig = data['pagination' ] as Map <String , dynamic >? ;
4444
45- // Get screen key
45+ // Get composite key (includes instanceId for proper isolation)
46+ // IMPORTANT: Try CrudItemContext.compositeKey first - it's correctly passed
47+ // from popups via ActionPopupWidget. Only fall back to getEffectiveCompositeKey
48+ // when not in a popup context.
4649 final crudCtx = CrudItemContext .of (context);
47- final screenKey =
48- crudCtx? .screenKey ?? getEffectiveScreenKey (context, contextData);
50+ final compositeKey =
51+ crudCtx? .compositeKey ?? getEffectiveCompositeKey (context, contextData);
4952
50- if (screenKey == null ) {
51- debugPrint ('REFRESH_SEARCH: No screen key found, cannot refresh' );
53+ if (compositeKey == null ) {
54+ debugPrint ('REFRESH_SEARCH: No composite key found, cannot refresh' );
5255 return contextData;
5356 }
5457
5558 // Check if there are any accumulated filters for this screen
56- final hasFilters = SearchStateManager ().hasFiltersForScreen (screenKey );
59+ final hasFilters = SearchStateManager ().hasFiltersForScreen (compositeKey );
5760
5861 if (! hasFilters) {
5962 debugPrint ('REFRESH_SEARCH: No accumulated filters for screen, skipping' );
@@ -64,7 +67,7 @@ class RefreshSearchExecutor extends ActionExecutor {
6467 return _executeWithBidirectionalPagination (
6568 context,
6669 contextData,
67- screenKey ,
70+ compositeKey ,
6871 direction,
6972 paginationConfig,
7073 );
@@ -73,15 +76,15 @@ class RefreshSearchExecutor extends ActionExecutor {
7376 Future <Map <String , dynamic >> _executeWithBidirectionalPagination (
7477 BuildContext context,
7578 Map <String , dynamic > contextData,
76- String screenKey ,
79+ String compositeKey ,
7780 String direction,
7881 Map <String , dynamic >? paginationConfig,
7982 ) async {
8083 final stateManager = SearchStateManager ();
8184 const paginationKey = '_pagination' ;
8285
8386 // Get config for default pagination settings
84- final config = FlowRegistry .getByName (screenKey .split ('::' ).last);
87+ final config = FlowRegistry .getByName (compositeKey .split ('::' ).last);
8588 final defaultPaginationConfig =
8689 config? ['wrapperConfig' ]? ['searchConfig' ]? ['pagination' ];
8790 final defaultLimit = defaultPaginationConfig? ['limit' ] as int ? ?? 10 ;
@@ -97,32 +100,32 @@ class RefreshSearchExecutor extends ActionExecutor {
97100 : defaultMaxItems);
98101
99102 // Get or initialize pagination window
100- debugPrint ('REFRESH_SEARCH: Looking for pagination window with screenKey=$ screenKey ' );
101- var window = stateManager.getPaginationWindow (screenKey , paginationKey);
103+ debugPrint ('REFRESH_SEARCH: Looking for pagination window with compositeKey=$ compositeKey ' );
104+ var window = stateManager.getPaginationWindow (compositeKey , paginationKey);
102105 debugPrint ('REFRESH_SEARCH: Found window=$window ' );
103106
104107 if (window == null ) {
105108 // Initialize window if not exists (shouldn't happen normally)
106109 debugPrint ('REFRESH_SEARCH: Window not found, initializing new one' );
107110 stateManager.initPaginationWindow (
108- screenKey ,
111+ compositeKey ,
109112 paginationKey,
110113 limit: limit,
111114 maxItems: maxItems,
112115 );
113- window = stateManager.getPaginationWindow (screenKey , paginationKey);
116+ window = stateManager.getPaginationWindow (compositeKey , paginationKey);
114117 }
115118
116119 // Determine offset based on direction
117120 int ? offset;
118121 if (direction == 'down' ) {
119- offset = stateManager.prepareLoadDown (screenKey , paginationKey);
122+ offset = stateManager.prepareLoadDown (compositeKey , paginationKey);
120123 if (offset == null ) {
121124 debugPrint ('REFRESH_SEARCH: Cannot load down - no more data' );
122125 return contextData;
123126 }
124127 } else if (direction == 'up' ) {
125- offset = stateManager.prepareLoadUp (screenKey , paginationKey);
128+ offset = stateManager.prepareLoadUp (compositeKey , paginationKey);
126129 if (offset == null ) {
127130 debugPrint ('REFRESH_SEARCH: Cannot load up - at beginning' );
128131 return contextData;
@@ -136,7 +139,7 @@ class RefreshSearchExecutor extends ActionExecutor {
136139 'REFRESH_SEARCH: Loading $direction from offset=$offset , limit=$limit ' );
137140
138141 // Get ALL accumulated filters for the screen (across all searchNames)
139- final accumulatedFilters = stateManager.getAllFilters (screenKey );
142+ final accumulatedFilters = stateManager.getAllFilters (compositeKey );
140143
141144 // Convert to SearchFilter objects
142145 final filters = < SearchFilter > [];
@@ -178,7 +181,7 @@ class RefreshSearchExecutor extends ActionExecutor {
178181 );
179182
180183 // Set mode in registry - FlowCrudBloc.onTransition will handle it
181- final registryKey = screenKey .split ('::' ).last;
184+ final registryKey = compositeKey .split ('::' ).last;
182185 FlowCrudStateRegistry ().setScrollDirection (registryKey, direction);
183186 FlowCrudStateRegistry ().setPaginationInfo (
184187 registryKey,
0 commit comments