Hi, I think I’ve encountered an issue with @Query causing unexpected view invalidations in SwiftUI.
I have a View that uses @Query with a SeasonEpisodeCountsRequest. The problem is that the view’s body is being recomputed continuously, even when the underlying data has not changed.
This happens both when:
- the query is initialized inline
@Query(SeasonEpisodeCountsRequest(seasonID: nil, filters: .init()))
private var episodesCount: SeasonViewState.EpisodeCounts
- the query is initialized in
init using Query(constant:)
@Query<SeasonEpisodeCountsRequest>
private var episodesCount: SeasonViewState.EpisodeCounts
init(seasons: [Season], selection: Binding<Season.ID?>) {
_episodesCount = Query(constant: .init(seasonID: selection.wrappedValue, filters: .init()))
self.seasons = seasons
self._selection = selection
}
To debug, I added:
let _ = Self._printChanges()
and noticed that the view is re-rendered repeatedly even when:
selection does not change
filters do not change
- the database content remains the same
Additional context:
- The view is embedded inside a
ScrollView
- The request uses a simple filter struct
- the behavior does not change whether I:
update the query parameters (e.g. seasonID, filters)
or leave them completely unchanged
Expected behavior:
The view should only re-render when the query result actually changes.
Actual behavior:
@Query seems to trigger continuous invalidations, causing unnecessary body recomputations.
Questions:
- Is this expected behavior for
@Query?
- Could this be related to how the request is evaluated or compared for equality?
- Is there a recommended pattern to avoid these redundant updates?
If needed, I can provide a minimal reproducible example.
Thanks in advance!
Hi, I think I’ve encountered an issue with
@Querycausing unexpected view invalidations in SwiftUI.I have a
Viewthat uses@Querywith aSeasonEpisodeCountsRequest. The problem is that the view’sbodyis being recomputed continuously, even when the underlying data has not changed.This happens both when:
initusingQuery(constant:)To debug, I added:
and noticed that the view is re-rendered repeatedly even when:
selectiondoes not changefiltersdo not changeAdditional context:
ScrollViewupdate the query parameters (e.g. seasonID, filters)
or leave them completely unchanged
Expected behavior:
The view should only re-render when the query result actually changes.
Actual behavior:
@Queryseems to trigger continuous invalidations, causing unnecessary body recomputations.Questions:
@Query?If needed, I can provide a minimal reproducible example.
Thanks in advance!