You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.
fix(admin): product card stock/price cache snap-back#332
Summary
- Optimistic-patch admin infinite-list (and related) caches on stock/price mutate
- Await cache invalidate before closing stock/price editors (fixes «Үлдэгдэл тэглэх» / set-to-0 looking unsaved)
Test plan
- Admin products list: overflow → Үлдэгдэл тэглэх → confirm; card shows 0 without reload
- Inline stock edit to 0 / non-zero; list stays correct
- Inline price edit; list price updates without snap-back
- Hard refresh still matches DB
Checks
Failing2
- astro-checkGitHubFailed
- vite-8-smokeGitHubFailed
Added 1 commit
- fix(admin): keep product list stock/price in sync after card edits5e47fef
Important
Review skipped
Auto reviews are disabled on base/target branches other than the default branch.
🗂️ Base branches to auto review (1)
- v2
Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: 0f34740b-22e5-4834-aa96-2c369297a0c7
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
- 🔍 Trigger review
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
Greptile Summary
The PR optimistically synchronizes product stock and price across admin caches and waits for invalidation before closing the corresponding editors.
- Adds a shared helper for patching infinite-list, all-products, and product-detail caches.
- Applies optimistic stock and price patches from product cards.
- Awaits cache invalidation before clearing editor state.
Confidence Score: 4/5
The failed-mutation rollback path should be fixed before merging because an unsuccessful stock or price update can remain visible as though it were saved.
The new optimistic handlers overwrite several caches but retain those unconfirmed values when the mutation and corrective refetch fail.
Files Needing Attention: apps/admin/src/components/product/product-card.tsx
Important Files Changed
| Filename | Overview |
|---|---|
| apps/admin/src/components/product/product-card.tsx | Adds optimistic stock and price updates and delayed editor closing, but failed mutations do not roll back their unconfirmed cache values. |
| apps/admin/src/utils/product-cache.ts | Adds immutable stock and price patching across the relevant list and detail cache representations. |
Reviews (1): Last reviewed commit: "fix(admin): keep product list stock/pric..." | Re-trigger Greptile
| … | … | @@ -57,11 +57,17 @@ const ProductCard = ({ brands, categories, product }: ProductCardProps) => { | |
| 62 | - | invalidateProductCaches(queryClient, product.id); | |
| 62 | + | onMutate: async ({ id, newStock }) => { | |
| 63 | + | await queryClient.cancelQueries({ queryKey: ["admin-products-infinite"] }); | |
| 64 | + | patchProductInCaches(queryClient, id, { stock: newStock }); | |
P1 Failed mutations retain optimistic state
When a stock or price mutation and its corrective refetch both fail, onError does not restore the previous cached values, causing cards and other cache consumers to display a value that was never saved until a later successful refetch or reload.