From 3100b2e4e5cd901ad59037d73f05561c7884299d Mon Sep 17 00:00:00 2001 From: ggurdin <46800240+ggurdin@users.noreply.github.com> Date: Tue, 17 Feb 2026 14:34:59 -0500 Subject: [PATCH] fix: add guard to not update space hierarchy info if space ID changes while fetching (#5723) --- lib/pangea/course_chats/course_chats_page.dart | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/pangea/course_chats/course_chats_page.dart b/lib/pangea/course_chats/course_chats_page.dart index f3f7c6142..27bf0cf63 100644 --- a/lib/pangea/course_chats/course_chats_page.dart +++ b/lib/pangea/course_chats/course_chats_page.dart @@ -260,6 +260,7 @@ class CourseChatsController extends State }) 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 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 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;