You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Copy file name to clipboardExpand all lines: AGENTS.md
+14-3Lines changed: 14 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,7 +71,13 @@ After discovering the project's specific touchpoints, use a checklist like this
71
71
72
72
## Data Fetching with React Query
73
73
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`.
75
81
76
82
### Guidelines
77
83
@@ -99,18 +105,23 @@ This project uses **@tanstack/react-query** (v5) for client-side data fetching.
99
105
100
106
6.**Do not install `react-query`** (v3). The package is `@tanstack/react-query` (v5).
101
107
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
+
102
110
### Refactoring roadmap
103
111
104
112
The following components still use raw `useEffect` + `fetch` and should be migrated to React Query as they are touched:
105
113
106
114
-`components/ordercontainer/OrderContainer.tsx` — order resumption & pending orders fetch
107
115
-`components/admin/PendingVerificationView.tsx`
108
-
-`components/admin/OrdersByTimeslotView.tsx`
109
116
-`components/admin/ScheduleCalendarView.tsx`
110
117
-`components/admin/NotifyTimeslotsView.tsx`
111
118
-`components/payment/StripePaymentForm.tsx`
112
119
-`components/payment/BankTransferForm.tsx`
113
120
-`pages/my-orders.tsx`
114
121
-`pages/order_complete.tsx`
115
122
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