-
-
Notifications
You must be signed in to change notification settings - Fork 43
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
Using @supabase-cache-helpers/postgrest-server in Next and react-query with either cache.swr(query) or cache.query(query) results in a runtime error, both:
- On the server when used with
prefetchQuery(...) - On the client when used with
useQuery(...)
The error thrown is:
Error: Key is not a PostgrestBuilder
at Generator.next (<anonymous>)
at new Promise (<anonymous>)
To Reproduce
- Set up the cache as described in the documentation.
- Create a query using Supabase's and wrap it with
cache.swr(...)orcache.query(...). - Use this wrapped query in:
- A server component with prefetchQuery(...) from @supabase-cache-helpers/postgrest-react-query
- A client component with useQuery(...)
// lib/cache.ts
export const cache = new QueryCache(new DefaultStatefulContext(), {
stores: [new MemoryStore({ persistentMap: new Map() })],
fresh: 1000,
stale: 2000,
});// lib/queries/challenges.ts
function getChallenges(client: TypedSupabaseClient, opts: { searchQuery: string }) {
let query = client
.from("challenges")
.select("*")
.order("created_at", { ascending: false });
return cache.swr(query); // or cache.query(query)
}On the server:
// app/challenges/page.tsx
await prefetchQuery(
queryClient,
queries.challenges.list(supabase, { searchQuery: "" })
);On the client:
// components/challenges/challenges-list.tsx
const { data, isLoading } = useQuery(
queries.challenges.list(supabase, { searchQuery: debouncedSearchTerm })
);Expected behavior
The result of cache.swr(...) or cache.query(...) should be compatible with both useQuery(...) and prefetchQuery(...) without throwing runtime errors.
Additional context
- The same queries work perfectly fine without caching.
- The error seems to indicate that the object returned is not a valid PostgrestBuilder or doesn't match the expected shape.
- Happens even with simple .select("*") queries.
- Using:
- @supabase-cache-helpers/postgrest-server@0.0.10
- @supabase-cache-helpers/postgrest-react-query@1.12.1
- @tanstack/react-query@5
- Next.js 15 (App Router)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working