Skip to content

Revalidate storefront cache on product webhook events (F4) - #4

Merged
pawelekbyra merged 1 commit into
mainfrom
claude/image-upload-display-diagnosis-qevpga
Jul 7, 2026
Merged

pawelekbyra merged 1 commit into
mainfrom
claude/image-upload-display-diagnosis-qevpga

Conversation

@pawelekbyra

Copy link
Copy Markdown
Owner

Summary

  • Product changes made in the admin (create/update/delete) were only visible on the storefront after the 10-minute "use cache" TTL — deleting a product stayed visible even after a manual refresh.
  • The backend already publishes product.created/product.updated/product.deleted through the same webhook pipeline as order events (Spree::Product has publishes_lifecycle_events — no backend code change needed).
  • Added handleProductChanged in src/lib/webhooks/handlers.ts, wired to those three event names in /api/webhooks/spree/route.ts. It busts the products, product-filters, and product:{slug} cache tags plus revalidatePath("/", "layout") — same escape hatch already used by the manual /api/revalidate endpoint.
  • Updated docs/technical-debt.md (closes the F4 entry) and docs/deployment-vercel.md (checklist + env var docs for SPREE_WEBHOOK_SECRET's expanded role).

Manual step required after merge

A webhook endpoint must exist in the admin (Settings → Webhooks) pointing at this storefront's /api/webhooks/spree, subscribed to product.created/product.updated/product.deleted (or product.*), using the same secret as SPREE_WEBHOOK_SECRET on Vercel. Without this, events are never sent and the fix has no effect.

Test plan

  • npx tsc --noEmit clean
  • npx biome check clean
  • npx vitest run — 91/91 passing (added src/lib/webhooks/__tests__/handlers.test.ts)
  • After merge + webhook endpoint configured: delete/edit a product in the admin, confirm it disappears/updates on the storefront within seconds

Generated by Claude Code

@vercel

vercel Bot commented Jul 7, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sklepik_front Ready Ready Preview, Comment Jul 7, 2026 12:21pm

Admin-side product changes (create/update/delete) were only visible
after the 10-minute "use cache" TTL — deleting a product in the admin
kept it showing on the storefront even after a refresh. The backend
already publishes product.created/updated/deleted through the same
webhook pipeline as order events, so this just wires up a handler that
busts the products/product-filters/product:{slug} cache tags and the
route cache on those events (closes F4 for the product case).

Still needs a webhook endpoint configured in the admin (Settings ->
Webhooks) subscribed to these three events, pointing at this
storefront's /api/webhooks/spree.
@pawelekbyra
pawelekbyra force-pushed the claude/image-upload-display-diagnosis-qevpga branch from 3243921 to 77d1bfc Compare July 7, 2026 12:18
@pawelekbyra
pawelekbyra merged commit 4d483db into main Jul 7, 2026
1 of 2 checks passed

This branch was successfully deployed

1 active deployment
Preview — 77d1bfc2 Deployed Jul 7, 2026 by vercel[bot]
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.

2 participants