Skip to content

Commit 0a1555f

Browse files
committed
docs(agents): document App Router/admin QueryClient provider requirement
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.
1 parent 8d5bef7 commit 0a1555f

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

AGENTS.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,13 @@ After discovering the project's specific touchpoints, use a checklist like this
7171

7272
## Data Fetching with React Query
7373

74-
This project uses **@tanstack/react-query** (v5) for client-side data fetching. The `QueryClientProvider` is set up in `pages/_app.tsx`.
74+
This project uses **@tanstack/react-query** (v5) for client-side data fetching.
75+
76+
> ⚠️ **Two separate provider trees.** This app mixes the **Pages Router** and the **App Router**, and they do **not** share a `QueryClientProvider`:
77+
> - **Pages Router** (`pages/**`, customer-facing pages): the `QueryClientProvider` is set up in `pages/_app.tsx`. Components rendered here (e.g. `components/pickup/TimeslotSelector.tsx`) get a client automatically.
78+
> - **App Router** (`app/(payload)/**`, Payload admin custom views): these render **outside** `pages/_app.tsx` and therefore have **no** QueryClient. Using `useQuery`/`useMutation` there without a provider throws `No QueryClient set, use QueryClientProvider to set one` at runtime.
79+
>
80+
> The Payload admin `app/(payload)/layout.tsx` is **auto-generated ("DO NOT MODIFY")**, so do not wrap it. Instead, any admin (App Router) component that uses React Query must wrap its own content in **`components/admin/AdminQueryProvider.tsx`**. The standard pattern is to split the view into an inner component (which holds the hooks) and a default export that wraps the inner component in `AdminQueryProvider` — see `components/admin/OrdersByTimeslotView.tsx`. Keep `AdminQueryProvider`'s defaults in sync with the Pages Router provider in `pages/_app.tsx`.
7581
7682
### Guidelines
7783

@@ -99,18 +105,23 @@ This project uses **@tanstack/react-query** (v5) for client-side data fetching.
99105

100106
6. **Do not install `react-query`** (v3). The package is `@tanstack/react-query` (v5).
101107

108+
7. **Admin (App Router) views** must wrap their content in `components/admin/AdminQueryProvider.tsx` (see the "two separate provider trees" note above). Do not rely on the `pages/_app.tsx` provider for anything under `app/(payload)/**`.
109+
102110
### Refactoring roadmap
103111

104112
The following components still use raw `useEffect` + `fetch` and should be migrated to React Query as they are touched:
105113

106114
- `components/ordercontainer/OrderContainer.tsx` — order resumption & pending orders fetch
107115
- `components/admin/PendingVerificationView.tsx`
108-
- `components/admin/OrdersByTimeslotView.tsx`
109116
- `components/admin/ScheduleCalendarView.tsx`
110117
- `components/admin/NotifyTimeslotsView.tsx`
111118
- `components/payment/StripePaymentForm.tsx`
112119
- `components/payment/BankTransferForm.tsx`
113120
- `pages/my-orders.tsx`
114121
- `pages/order_complete.tsx`
115122

116-
When refactoring these components, follow the pattern established in `components/pickup/TimeslotSelector.tsx`.
123+
Already migrated (use as references):
124+
125+
-`components/admin/OrdersByTimeslotView.tsx` — admin (App Router) view; wraps its default export in `AdminQueryProvider`.
126+
127+
When refactoring Pages Router components, follow the pattern established in `components/pickup/TimeslotSelector.tsx`. When refactoring **admin (App Router) views** (the remaining `components/admin/*` entries above), additionally wrap the view in `AdminQueryProvider` as shown in `components/admin/OrdersByTimeslotView.tsx`.

0 commit comments

Comments
 (0)