Skip to content

Commit ce4ed3e

Browse files
committed
Address coderabbitai feedback
1 parent 2f034af commit ce4ed3e

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

packages/dart/lib/src/utils/parse_live_list.dart

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,18 @@ class ParseLiveList<T extends ParseObject> {
603603
// Setting the object will mark it as loaded and emit it to the stream
604604
_list[index].object = response.results!.first;
605605
} else if (response.error != null) {
606-
// Emit error to the element's stream so listeners can handle it
607-
// Use _list[index] to ensure we emit to the current element at this index
608-
_list[index].emitError(response.error!, StackTrace.current);
606+
// Emit error to the element's stream so listeners can handle it.
607+
// Guard against list mutations so we don't emit on the wrong element.
608+
final currentElement = _list[index];
609+
if (currentElement.object.objectId != element.object.objectId) {
610+
if (_debug) {
611+
print(
612+
'ParseLiveList: Element at index $index changed during load (error)',
613+
);
614+
}
615+
return;
616+
}
617+
currentElement.emitError(response.error!, StackTrace.current);
609618
if (_debug) {
610619
print(
611620
'ParseLiveList: Error loading element at index $index: ${response.error}',
@@ -786,7 +795,7 @@ class ParseLiveListElement<T extends ParseObject> {
786795
bool loaded = false,
787796
Map<String, dynamic>? updatedSubItems,
788797
}) : _loaded = loaded,
789-
_isLoading = false {
798+
isLoading = false {
790799
_updatedSubItems = _toSubscriptionMap(
791800
updatedSubItems ?? <String, dynamic>{},
792801
);
@@ -799,7 +808,7 @@ class ParseLiveListElement<T extends ParseObject> {
799808
final StreamController<T> _streamController = StreamController<T>.broadcast();
800809
T _object;
801810
bool _loaded = false;
802-
bool _isLoading = false;
811+
bool isLoading = false;
803812
late Map<PathKey, dynamic> _updatedSubItems;
804813
LiveQuery? _liveQuery;
805814
final Future<void> _subscriptionQueue = Future<void>.value();
@@ -928,9 +937,6 @@ class ParseLiveListElement<T extends ParseObject> {
928937

929938
bool get loaded => _loaded;
930939

931-
bool get isLoading => _isLoading;
932-
set isLoading(bool value) => _isLoading = value;
933-
934940
/// Emits an error to the stream for listeners to handle.
935941
/// Used when lazy loading fails to fetch the full object data.
936942
void emitError(Object error, StackTrace stackTrace) {

packages/dart/lib/src/utils/parse_utils.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,6 @@ Future<ParseResponse> batchRequest(
123123
}
124124
}
125125

126-
Stream<T> _createStreamError<T>(Object error) async* {
127-
throw error;
128-
}
129-
130126
List removeDuplicateParseObjectByObjectId(Iterable iterable) {
131127
final list = iterable.toList();
132128

0 commit comments

Comments
 (0)