fix: add guard to not update space hierarchy info if space ID changes while fetching (#5723)

This commit is contained in:
ggurdin 2026-02-17 14:34:59 -05:00 committed by GitHub
parent 33774da076
commit 3100b2e4e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -260,6 +260,7 @@ class CourseChatsController extends State<CourseChats>
}) async {
// Load all of the space's state events. Space Child events
// are used to filtering out unsuggested, unjoined rooms.
final requestSpaceId = widget.roomId;
await activeSpace.postLoad();
// The current number of rooms loaded for this space that are visible in the UI
@ -299,6 +300,12 @@ class CourseChatsController extends State<CourseChats>
from: currentNextBatch,
limit: 100,
);
if (widget.roomId != requestSpaceId) {
// The user has navigated to a different space since this call was made, so we should discard the response and not update the state
return;
}
callsToServer++;
if (response.nextBatch == null) {
@ -315,6 +322,11 @@ class CourseChatsController extends State<CourseChats>
currentNextBatch = response.nextBatch;
}
if (widget.roomId != requestSpaceId) {
// The user has navigated to a different space since the first call was made, so we should discard the response and not update the state
return;
}
discoveredChildren = currentHierarchy;
discoveredChildren?.sort(_sortSpaceChildren);
_nextBatch = currentNextBatch;