Skip to content

Commit 112070f

Browse files
Hoang Phamclaude
andcommitted
Fix actor isolation errors in Pokemon list view
- Capture initialOffset value before closures to avoid actor isolation issues - Use capturedOffset in queryFn and getNextPageParam closures - Fixes compilation errors with Swift 6 strict concurrency 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6dda30d commit 112070f

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

Example/swiftui-query-demo/ContentView.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,19 @@ struct PokemonListView: View {
120120

121121
var body: some View {
122122
WithPerceptionTracking {
123+
// Capture the initial offset value before the closures
124+
let capturedOffset = initialOffset
125+
123126
UseInfiniteQuery(
124127
queryKey: "pokemon-infinite-list-\(initialOffset)", // Include offset in key for cache separation
125128
queryFn: { _, pageParam in
126-
let offset = pageParam ?? initialOffset
129+
let offset = pageParam ?? capturedOffset
127130
return try await PokemonAPI.fetchPokemonPage(offset: offset)
128131
},
129132
getNextPageParam: { pages in
130133
// Calculate next offset based on current pages and initial offset
131134
let currentTotal = pages.reduce(0) { total, page in total + page.results.count }
132-
let nextOffset = initialOffset + currentTotal
135+
let nextOffset = capturedOffset + currentTotal
133136
let lastPage = pages.last
134137

135138
// If we have next URL or haven't reached the total count, continue pagination
@@ -138,7 +141,7 @@ struct PokemonListView: View {
138141
}
139142
return nil // No more pages
140143
},
141-
initialPageParam: initialOffset,
144+
initialPageParam: capturedOffset,
142145
staleTime: 5 * 60 // 5 minutes before considered stale
143146
) { result in
144147
if result.isLoading, result.data?.pages.isEmpty != false {

0 commit comments

Comments
 (0)