/storefront-next:sfnext-revalidationfrom storefront-next
Controls which Storefront Next loaders re-run after actions or navigation. Manages shouldRevalidate exports, policy modules in src/lib/revalidation/routes, and tag primitives. Use when loaders run too often, data is stale after mutations, or adding new actions/routes.
Ships in storefront-next. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
React Router re-runs loaders after every action submission. A storefront has deep route trees, persistent fetchers (mini-cart) and lazy modals (quick view), so one add-to-cart can re-run many loaders that never read the basket, each with its own SCAPI fan-out. This skill is how to keep only the re-runs that are needed. The authoritative guide is docs/README-REVALIDATION.md in your project; read it before changing policy.
An action submission (<Form>, useSubmit, fetcher.submit) re-runs the whole active set:
fetcher.load() of a resource route whose component is still mounted),A raw fetch(), a SCAPI client call, or fetcher.load() is not a submission and triggers nothing. A route that only exports an action fires revalidation but has no loader to re-run.
For each pair (action, active loader) it is justified only if both are true:
Two waste types: no overlap, or overlap with the value already available. Do not gate a re-run that is itself the sync mechanism (a provider that refills from loader output).
Each route re-exports a shared policy rather than inlining logic:
// src/routes/_app.cart.tsx
export { shouldRevalidate } from '@/lib/revalidation/routes/cart';
Module (src/lib/revalidation/routes/) | Used by |
|---|---|
root.ts | src/root.tsx (export { shouldRevalidate } from ...); denylist of irrelevant mutations, safe default is revalidate |
cart.ts, checkout.ts, home.ts, wishlist.ts | the matching route files |
product.ts | _app.p.$.tsx: relevant mutations force true; navigation re-runs only on different path or pid |
category.ts | _app.c.$.tsx and _app.search.tsx: skips client-only param changes and non-ambient mutations |
api-client.ts | resource.api.client.$resource.ts |
shared.ts | helpers: getActionPath, isContextMutation, isIdentityMutation, isAmbientMutation |
_app.tsx exports shouldRevalidate() { return false } (navigation data that no shopper action changes). resource.basket-products.ts opts in only when actionResult.basket.basketId exists.
"Ambient" mutations (site/currency, shopper context, login/signup/logout) change request-wide inputs and legitimately re-run most loaders.
Prefer suppress-by-default allowlists for expensive loaders, and defer to the default for cheap ones:
// src/lib/revalidation/routes/store-events.ts
import type { ShouldRevalidateFunctionArgs } from 'react-router';
import { resourceRoutes } from '@/route-paths';
import { getActionPath, isAmbientMutation } from './shared';
const RELEVANT = [resourceRoutes.setSelectedStore] as readonly string[];
export function shouldRevalidate({ currentUrl, nextUrl, formMethod, formAction, defaultShouldRevalidate }: ShouldRevalidateFunctionArgs) {
if (formMethod && formMethod !== 'GET') {
const path = getActionPath(formAction, currentUrl.origin);
return Boolean(path && (isAmbientMutation(path) || RELEVANT.includes(path)));
}
if (currentUrl.pathname !== nextUrl.pathname) return true;
return defaultShouldRevalidate; // explicit revalidate() still works; client-only params stay skipped
}
Steps:
*.test.ts), covering an admitted mutation, a skipped mutation and a navigation..data) requests.Gate adequacy matters: a policy that only checks formAction is set still re-runs on every action. Inspect the action path or actionResult.
When several routes depend on the same data, use the tag primitives in @/lib/revalidation/tags (the framework ships primitives only; you own the catalogs):
// src/lib/revalidation/tags/cart.ts (yours)
export const cartTags = { all: 'cart.*', lineItem: (id: string) => `cart.lineItems:${id}` as const } as const;
// action: emit
import { withRevalidateTags } from '@/lib/revalidation/tags';
return withRevalidateTags({ basket }, [cartTags.lineItem(itemId)]);
// route: subscribe
import { shouldRevalidateForTags } from '@/lib/revalidation/tags';
export const shouldRevalidate = shouldRevalidateForTags([cartTags.all]);
Spell tags only through catalog builders (a typo silently matches nothing). Syntax: dot-separated segments, optional :id, .* wildcard is subscriber-only. Helpers: tagGroup, tagImplications, matchesTag, normalizeTags, resolveTags; shouldRevalidateForTags(spec, { ambient, expand }). An untagged action falls back to default behavior. See src/lib/revalidation/tags/index.example.test.ts and details in POLICIES-AND-TAGS.md.
updateBasketResource and BasketProvider (src/providers/basket.tsx), so pages rarely need loader re-runs to show the new basket.useRevalidateOnReturn (@/hooks/use-revalidate-on-return) refreshes stale data when the shopper returns to the tab or page.shouldRevalidate gates on root-level session, site and config loaders conservative: the root policy defaults to revalidate.docs/README-REVALIDATION.md, docs/README-DATA.md, docs/README-STATE.md and AGENTS.md in your project. b2c docs search "revalidation" or the docs_search MCP tool for product docs.
storefront-next:sfnext-data-fetching - loaders, actions, fetchersstorefront-next:sfnext-performance - review checklist (revalidation scope section)storefront-next:sfnext-state-management - providers that make a re-run unnecessarystorefront-next:sfnext-routing - route files that export policiesstorefront-next:sfnext-testing - tests for policiesWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub salesforcecommercecloud/b2c-developer-tooling --plugin storefront-next25 skills in this plugin
/sfnext-accessibilityBuild and fix accessible UI in a Storefront Next storefront (WCAG 2.1 AA): jsx-a11y lint findings, missing accessible names and labels, form error association, dialog focus management, aria-live status messages, keyboard behavior, color contrast, and verifying fixes with Storybook a11y/play() tests and the e2e axe scan with its baseline. Use for "accessibility", "a11y", "WCAG", "screen reader", "aria-label", "focus trap", "axe violation", pnpm lint:a11y, pnpm a11y, a11y-baseline.json, skip-a11y, STORYBOOK_A11Y_TEST_MODE, or an accessibility audit finding to fix. Do not use for general lint/typecheck gates (use `storefront-next:sfnext-quality-gates`), writing non-accessibility tests (use `storefront-next:sfnext-testing`), or color/token design (use `storefront-next:sfnext-theming`)./sfnext-analytics-consentStorefront Next analytics: engagement adapters (Einstein, Active Data, Data 360), adding a custom adapter, tracking consent gating, PageViewTracker, useAnalytics events, and first-touch attribution (dw_attribution). Use when configuring engagement.adapters in config.server.ts, writing an adapter with hasConsent, registering it in initializeEngagementAdapters, wiring the consent banner (trackingConsent, consentCategories, dw_dnt), firing trackViewProduct/trackCartItemAdd events, debugging why no analytics events are sent, or passing campaign attribution to orders. Do not use for general config loading or env vars (use `storefront-next:sfnext-configuration`), CSP/script allowlisting of third-party tags (use `storefront-next:sfnext-security`), or SEO meta/JSON-LD (use `storefront-next:sfnext-seo`).Other plugins' skills for the same job