Wait for app to load the relay list and connect before loading universe view

This commit addresses a race condition that happened when the user
initializes the app on the universe view, where the loading function
would run before the relay list was fully loaded and connected, causing
the loading function to connect to an empty relay list.

The issue was fixed by introducing a call that allows callers to wait
for the app to connect to the network

Changelog-Fixed: Fixed issue where the app would occasionally launch an empty universe view
Closes: https://github.com/damus-io/damus/issues/3528
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
This commit is contained in:
Daniel D’Aquino
2026-01-28 16:58:30 -08:00
parent 438d537ff6
commit fa4b7a7518
3 changed files with 118 additions and 8 deletions
@@ -55,6 +55,8 @@ class SearchHomeModel: ObservableObject {
DispatchQueue.main.async {
self.loading = true
}
await damus_state.nostrNetwork.awaitConnection()
let to_relays = await damus_state.nostrNetwork.ourRelayDescriptors
.map { $0.url }
.filter { !damus_state.relay_filters.is_filtered(timeline: .search, relay_id: $0) }
@@ -14,7 +14,6 @@ struct SearchHomeView: View {
@StateObject var model: SearchHomeModel
@State var search: String = ""
@FocusState private var isFocused: Bool
@State var loadingTask: Task<Void, Never>?
func content_filter(_ fstate: FilterState) -> ((NostrEvent) -> Bool) {
var filters = ContentFilters.defaults(damus_state: damus_state)
@@ -118,13 +117,8 @@ struct SearchHomeView: View {
.onReceive(handle_notify(.new_mutes)) { _ in
self.model.filter_muted()
}
.onAppear {
if model.events.events.isEmpty {
loadingTask = Task { await model.load() }
}
}
.onDisappear {
loadingTask?.cancel()
.task {
await model.load()
}
}
}