Skip to content

fix(admin): provide QueryClient for OrdersByTimeslotView (No QueryClient set)#89

Merged
choden-dev merged 2 commits into
mainfrom
fix/admin-query-provider
Jun 24, 2026
Merged

fix(admin): provide QueryClient for OrdersByTimeslotView (No QueryClient set)#89
choden-dev merged 2 commits into
mainfrom
fix/admin-query-provider

Conversation

@choden-dev

Copy link
Copy Markdown
Owner

Problem

After migrating OrdersByTimeslotView to React Query (#88), the admin view throws at runtime:

Uncaught Error: No QueryClient set, use QueryClientProvider to set one

Root cause

The QueryClientProvider is only set up in pages/_app.tsx, which wraps the Pages Router tree. Payload admin custom views render in the App Router (app/(payload)) tree and never inherit that provider — so useQuery/useMutation have no client. (TimeslotSelector works because it's used on customer-facing Pages Router pages.)

The Payload app/(payload)/layout.tsx is auto-generated ("DO NOT MODIFY"), so wrapping there is not appropriate.

Fix

  • Add a small reusable components/admin/AdminQueryProvider.tsx (client component) that creates a QueryClient with the same defaults as the Pages Router provider (staleTime: 30s, retry: 1).
  • Split OrdersByTimeslotView into an inner component (OrdersByTimeslotViewInner, contains the hooks) and a default export that wraps it in AdminQueryProvider, making the view self-sufficient regardless of where Payload mounts it.

Notes

  • Other admin views on the React Query roadmap can reuse AdminQueryProvider when migrated.

Verification

  • tsc --noEmit passes.
  • biome check passes on both files.

Payload admin custom views render in the App Router (app/(payload)) tree,
which is not wrapped by the QueryClientProvider in pages/_app.tsx (that only
covers the Pages Router). After migrating OrdersByTimeslotView to React Query
it threw 'No QueryClient set' at runtime.

Add a reusable AdminQueryProvider and wrap the view's default export in it so
the view is self-sufficient. Defaults (staleTime 30s, retry 1) are kept in
sync with the Pages Router provider.
Clarify that the Pages Router and App Router (Payload admin) trees do not
share a QueryClientProvider, and that admin views must wrap their content in
AdminQueryProvider. Mark OrdersByTimeslotView as migrated.
@choden-dev choden-dev merged commit 9afca25 into main Jun 24, 2026
4 checks passed
@choden-dev choden-dev deleted the fix/admin-query-provider branch June 24, 2026 04:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant