fix: add guard to not update space hierarchy info if space ID changes while fetching (#5723)
This commit is contained in:
parent
33774da076
commit
3100b2e4e5
1 changed files with 12 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue