fix(admin): provide QueryClient for OrdersByTimeslotView (No QueryClient set)#89
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After migrating
OrdersByTimeslotViewto React Query (#88), the admin view throws at runtime:Root cause
The
QueryClientProvideris only set up inpages/_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 — souseQuery/useMutationhave no client. (TimeslotSelectorworks because it's used on customer-facing Pages Router pages.)The Payload
app/(payload)/layout.tsxis auto-generated ("DO NOT MODIFY"), so wrapping there is not appropriate.Fix
components/admin/AdminQueryProvider.tsx(client component) that creates aQueryClientwith the same defaults as the Pages Router provider (staleTime: 30s,retry: 1).OrdersByTimeslotViewinto an inner component (OrdersByTimeslotViewInner, contains the hooks) and a default export that wraps it inAdminQueryProvider, making the view self-sufficient regardless of where Payload mounts it.Notes
AdminQueryProviderwhen migrated.Verification
tsc --noEmitpasses.biome checkpasses on both files.