API Integration Differences with PWA Kit
While both PWA Kit and Storefront Next use SCAPI for commerce functionality, they take fundamentally different approaches to API client architecture.
| Aspect | PWA Kit | Storefront Next |
|---|---|---|
| Package | @salesforce/commerce-sdk-react | @salesforce/storefront-next-runtime/scapi |
| Underlying Client | commerce-sdk-isomorphic | openapi-fetch |
| Pattern | React hooks | Direct API calls |
| Type Generation | Manual TypeScript | Generated from OpenAPI specs |
| Bundle Size | Larger (includes React Query + SDK) | Smaller (lightweight client) |
| Aspect | PWA Kit | Storefront Next |
|---|---|---|
| Reads (GET) | Inside components via hooks | In route loaders |
| Writes (POST/PUT) | Inside components via mutation hooks | In action routes |
| Authentication | Automatic via provider | Manual via middleware |
| Aspect | PWA Kit | Storefront Next |
|---|---|---|
| When | Once at app root | Per-request in loaders/actions |
| Where | CommerceApiProvider | createApiClients() helper |
| Auth | Automatic token management | Middleware injects tokens |
| Aspect | PWA Kit | Storefront Next |
|---|---|---|
| Strategy | React Query cache | React Router revalidation |
| Invalidation | Automatic after mutations | Manual or via shouldRevalidate |
| Stale Time | Configurable (default 10s) | No built-in stale time |
Fetching a product:
Adding to Cart:
- Both use SCAPI for commerce operations.
- Both support SLAS authentication.
- Both proxy API requests through the server.
- Both provide TypeScript support.
When migrating from PWA Kit to Storefront Next:
- Move API calls to loaders: Replace
useProduct,useCategory, and so on with loader fetches. - Move mutations to actions: Replace
useShopperBasketsMutationwith action routes. - Update parameter format: Change from
{ parameters: {} }to{ params: { path: {}, query: {} } }. - Handle auth manually: Create auth middleware instead of relying on provider.
- Remove React Query: No longer needed; caching handled by React Router.
- Update error handling: Use
ApiErrorclass instead of hook error states.