dist/codex/salesforce-commerce/skills/sf-b2b-lwc/SKILL.md
Build B2B Commerce LWC components — Lightning Web Components with @api/@track/@wire decorators, commerce-specific wire adapters, custom events, Lightning Web Security, Jest unit testing, and component lifecycle. Use when building B2B storefront UI components.
npx skillsauth add orcaqubits/agentic-commerce-claude-plugins sf-b2b-lwcInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Build Lightning Web Components for Salesforce B2B Commerce storefronts.
Fetch live docs BEFORE writing code:
Web-search the latest:
Web-fetch official sources:
developer.salesforce.com/docs/component-library/documentation/en/lwcdeveloper.salesforce.com/docs/commerce/salesforce-commerce/guide/lwc-for-b2b.htmldeveloper.salesforce.com/docs/platform/lwc/guide/reference-wire-adapters-intro.htmlVerify current decorator syntax, commerce wire adapters, Jest testing patterns, and Lightning Web Security vs Locker behavior.
| File | Purpose | Notes |
|------|---------|-------|
| componentName.html | Template | {property} binding, lwc:if/lwc:else, for:each |
| componentName.js | Controller | ES6 class extending LightningElement, decorators, lifecycle hooks |
| componentName.css | Styles | Component-scoped, :host selector, CSS custom properties |
| componentName.js-meta.xml | Metadata | API version, targets (Experience Builder, App Builder), exposed properties |
| Decorator | Purpose | Reactivity |
|-----------|---------|-----------|
| @api | Public property (parent-settable) or public method | Re-renders on change from parent |
| @track | Deep reactivity for objects/arrays | Only needed for nested mutation (e.g., this.obj.nested = val) |
| @wire | Reactive data fetching from wire adapters | Re-fetches when reactive ($-prefixed) params change |
Important: Primitive class fields are auto-tracked in modern LWC -- @track is only needed for deep object/array mutation. Reassigning the entire object triggers reactivity without @track.
| Hook | When | Use For |
|------|------|---------|
| constructor() | Instance created | Initialize non-reactive state; cannot access DOM or properties |
| connectedCallback() | Inserted into DOM | Initialization, subscriptions (LMS, platform events) |
| renderedCallback() | After every render | DOM access; use sparingly (called frequently) |
| disconnectedCallback() | Removed from DOM | Cleanup listeners, unsubscribe channels, release resources |
| errorCallback(error, stack) | Child component error | Error boundary; log or display user-friendly messages |
Wire adapters provide reactive, cached data fetching. Two binding styles exist:
@wire(adapter, params) propertyName; -- result is { data, error }@wire(adapter, params) functionName({ data, error }) { ... } -- for custom handlingCommerce-specific adapters live under the lightning/commerce and commerce/* namespaces. Fetch live docs for the current list of available commerce wire adapters (products, pricing, cart, inventory).
// Pattern: Wire adapter usage
// Fetch live docs for adapter params
@wire(getProduct, { productId: '$productId' })
product;
Communication from child to parent uses CustomEvent:
| Property | Purpose |
|----------|---------|
| detail | Event payload (keep minimal) |
| bubbles | Propagate up the DOM tree |
| composed | Cross shadow DOM boundary |
Parent listens via on[eventname] attribute in template (all lowercase).
| Direction | Mechanism |
|-----------|-----------|
| Parent to Child | @api properties set in parent template |
| Child to Parent | CustomEvent dispatched from child |
| Sibling / Unrelated | Lightning Message Service (LMS) via publish/subscribe |
LWS (default since Spring '23) replaces the legacy Locker Service:
Restrictions: No eval(), no Function(), no setTimeout(string). Use @salesforce/resourceUrl for static resources. Follow CRUD/FLS patterns for data access.
Components are exposed to Experience Builder via the js-meta.xml file:
<isExposed>true</isExposed>lightningCommunity__Page and lightningCommunity__Default targets<property> elements (String, Integer, Boolean, etc.)LWC components are unit-tested with @salesforce/sfdx-lwc-jest. Key concepts:
jest.mock()createElement from lwc to instantiate componentselement.shadowRoot.querySelector()Promise.resolve()afterEach to avoid test pollution// Pattern: Jest test skeleton
// Fetch live docs for mock utilities
import { createElement } from 'lwc';
import MyComponent from 'c/myComponent';
@wire for read-only data (reactive, cached via Lightning Data Service)renderedCallback logic (runs on every render)Fetch the LWC Developer Guide, B2B Commerce LWC docs, and wire adapter reference for exact decorator behavior, adapter parameters, and testing utilities before implementing.
development
Build with Spree's headless Next.js storefront — the official `spree/storefront` repo (Next.js 16 App Router with Server Actions and Turbopack, React 19 Server Components, Tailwind CSS 4, TypeScript 5, `@spree/sdk`, Sentry), server-only auth (httpOnly JWT cookies + publishable key), MeiliSearch faceted catalog, one-page checkout with Apple/Google Pay/Klarna/Affirm/SEPA, multi-region market routing, GA4 + JSON-LD SEO, and Vercel/Docker deployment. Use when forking or customizing the storefront, or evaluating headless adoption.
tools
Build Spree extensions as Rails engines — gem scaffolding, `bin/rails g spree:extension`, mounting routes/migrations/assets, the modern `prepend` decorator pattern (`*_decorator.rb` with `self.prepended(base)`), generators (`spree:model_decorator`, `spree:controller_decorator`), the four customization surfaces in preference order (Events > Webhooks > Dependencies > Decorators), Spree::Dependencies for swapping service objects, gem release/versioning, and the deprecated Deface engine. Use when building a reusable Spree extension or adding non-trivial customization to an app.
development
Build with Spree's event bus and Webhooks 2.0 — `Spree::Events` publication, `Spree::Subscriber` DSL with `subscribes_to` and `on`, wildcard matching, lifecycle events (`{model}.created/.updated/.deleted` via `publishes_lifecycle_events`), the canonical event catalog (order.*, payment.*, shipment.*, product.*), Webhooks 2.0 endpoints, HMAC-SHA256 signing (`X-Spree-Webhook-Signature`), exponential-backoff retries, and Sidekiq job orchestration. Use when wiring event-driven business logic, building webhook consumers, or replacing ActiveSupport callback chains.
tools
Cross-cutting Spree development patterns — the customization preference hierarchy (Events > Webhooks > Dependencies > Decorators), `Spree::Dependencies` service-object swapping, the `_decorator.rb` + `prepend` + `self.prepended` idiom, idempotent subscribers and webhook receivers, multi-store scoping discipline, prefixed IDs, calculator polymorphism (shipping/promotion/tax share the base), service-object composition with `dry-monads` or simple results, why to avoid `class_eval` reopening and Deface, and Spree-on-Rails idioms (Hotwire/Turbo Stimulus, ActiveStorage, Action Cable, Sidekiq). Use when designing the architecture of a Spree extension or solving cross-cutting concerns.