Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

sfnext-revalidation

БесплатноБез исполняемых скриптовНе проверен

Control which Storefront Next loaders re-run after an action or navigation: shouldRevalidate exports, the policy modules in src/lib/revalidation/routes (root…

SalesforceCommerceCloudот SalesforceCommerceCloud★ 58 звёзд на GitHub

Об этом скилле

Storefront Next Revalidation

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.

What revalidates

An action submission (<Form>, useSubmit, fetcher.submit) re-runs the whole active set:

  1. the matched route chain (root, layouts, leaf),
  2. mounted resource fetchers (fetcher.load() of a resource route whose component is still mounted),
  3. fetchers inside open modals, drawers and sheets.

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.

When a re-run is justified

For each pair (action, active loader) it is justified only if both are true:

  • Overlap: the action result changes something the loader reads.
  • Value not already available: the new value does not already reach the UI another way (for example the basket provider is updated from the action result, so a cart action does not need the PDP loader to re-run).

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).

Where the policy lives

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.

Add a policy for a new route

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:

  1. List what the loader reads (fetched fields, URL params, cookies, context such as currency or selected store).
  2. List the actions reachable while this route is active (page, shell, open modals and drawers). Mark overlap and availability per action.
  3. Export the policy. Admit only mutations with overlap and no other delivery path. Document each admit in a comment.
  4. If a URL-filtered loader (search params) re-runs on navigation anyway, skip revalidating when only those params change.
  5. Add a test next to the policy (*.test.ts), covering an admitted mutation, a skipped mutation and a navigation.
  6. Verify manually: open DevTools Network, perform the gesture, and count loader (.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.

Tags for cross-route contracts

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/revalidati
Полный SKILL.md на GitHub

Установить sfnext-revalidation в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

evals/trigger-evals.jsonreferences/POLICIES-AND-TAGS.md

FAQ

Что делает скилл sfnext-revalidation?

Control which Storefront Next loaders re-run after an action or navigation: shouldRevalidate exports, the policy modules in src/lib/revalidation/routes (root, cart, product, category, checkout, home, wishlist, api-client, shared), getActionPath and isAmbientMutation, and the tag primitives in src/lib/revalidation/tags (withRevalidateTags, shouldRevalidateForTags, tagGroup, tagImplications). Use for "page re-fetches after add to cart", "loader runs too often", "stale data after a mutation", "flash of skeleton after changing a swatch", "add shouldRevalidate", or when a new action or route changes which loaders fire. Do not use for writing loaders or actions (use `storefront-next:sfnext-data-fetching`), Suspense and LCP tuning (use `storefront-next:sfnext-performance`), or client-side state (use `storefront-next:sfnext-state-management`).

Как установить скилл sfnext-revalidation?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл sfnext-revalidation запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить sfnext-revalidation с