sfnext-hybrid-storefronts
Implement hybrid storefronts that run Storefront Next alongside SFRA or SiteGenesis. Use when planning gradual migration from SFRA, configuring hybrid proxy for local development, setting up session bridging between storefronts, or routing traffic between old and new implementations.
What this skill does
# Hybrid Storefronts Skill
This skill covers running Storefront Next alongside an existing SFRA or SiteGenesis storefront — enabling gradual migration without a full rewrite.
## Overview
A hybrid storefront splits traffic between Storefront Next (for new or migrated pages) and an existing SFRA/SiteGenesis storefront (for pages not yet migrated). Session bridging ensures users maintain authentication and cart state across both implementations.
## Architecture
```
Customer Request
↓
CDN / eCDN (Cloudflare) ← Production: routes based on URL patterns
↓
┌─────────────────────────────┐
│ Storefront Next │ SFRA/SiteGenesis │
│ (MRT) │ (B2C Instance) │
└────────┴────────────────────┘
↕ Session Bridge (shared cookies) ↕
```
**Production:** Cloudflare eCDN handles routing between Storefront Next and SFRA based on origin rules.
**Local Development:** A Vite dev server plugin (`hybridProxyPlugin` from `@salesforce/storefront-next-dev`) proxies non-matching requests to your SFCC sandbox, simulating the eCDN split at `localhost:5173`.
## Configuration
Hybrid mode is configured entirely through environment variables — there is no extension directory.
### Application Config (All Environments)
These `PUBLIC__` variables are bundled into the app and required in all environments:
```bash
# Enable hybrid mode — activates the client-side legacy-routes middleware
PUBLIC__app__hybrid__enabled=true
# Routes that belong to SFRA — client-side <Link> clicks to these trigger full-page loads
# Supports exact paths and React Router parameterized routes
PUBLIC__app__hybrid__legacyRoutes='["/cart", "/checkout", "/product/:id"]'
```
### Proxy Plugin Config (Local Development Only)
These configure the Vite dev server proxy and have no effect in production:
```bash
# Enable the proxy
HYBRID_PROXY_ENABLED=true
# Your SFCC sandbox origin
SFCC_ORIGIN=https://zzrf-001.dx.commercecloud.salesforce.com
# Routing rules: Cloudflare eCDN expression format
# Paths matching → Storefront Next; paths not matching → proxied to SFCC
HYBRID_ROUTING_RULES='(http.request.uri.path matches "^/$" or http.request.uri.path matches "^/product.*" or http.request.uri.path matches "^/category.*" or http.request.uri.path matches "^/resource.*" or http.request.uri.path matches "^/action/.*")'
# Optional: locale for SFRA path transformation (falls back to PUBLIC__app__i18n__fallbackLng)
HYBRID_PROXY_LOCALE=en-GB
```
## Client-Side Navigation Middleware
The `legacy-routes.client.ts` middleware intercepts client-side navigation to SFRA-owned routes:
1. User clicks `<Link to="/checkout">`
2. React Router begins client-side navigation
3. Middleware checks if `/checkout` matches any pattern in `legacyRoutes`
4. If yes → forces a full-page navigation so the CDN/proxy routes to SFRA
5. If no → continues normal client-side rendering
This prevents React Router from trying to render pages that belong to SFRA.
## Session Bridging
Both storefronts share the same session cookies (`dwsid`, `cc-*`) on a common domain:
### Cookie Handling (Local Dev)
The proxy handles cookies in three layers:
1. **Set-Cookie header rewriting** — SFCC response `Domain=.salesforce.com` → `Domain=localhost`
2. **Storefront Next server cookies** — Written directly to localhost, no rewriting needed
3. **Client-side cookie interception** — Injected script patches `document.cookie` for SFRA's JS
### SFRA to Storefront Next
When navigating from SFRA to Storefront Next:
1. SFRA provides session credentials (dwsgst/dwsrst tokens)
2. Storefront Next exchanges the bridge token for SLAS tokens
3. Normal SLAS cookie-based auth resumes
### Storefront Next to SFRA
When navigating from Storefront Next to SFRA:
1. Shared `dwsid` cookie maintains session continuity
2. Full-page navigation triggered by legacy-routes middleware
3. CDN/proxy routes request to SFCC origin
## Traffic Routing Patterns
### Gradual Migration Strategy
1. **Phase 1** — Homepage, product, and category pages on Storefront Next
2. **Phase 2** — Account and search pages
3. **Phase 3** — Cart and checkout flow
4. **Phase 4** — Full migration, remove SFRA
### Required Routing Rules
Some patterns must always route to Storefront Next:
| Pattern | Why |
| -------------- | ---------------------------------------------- |
| `^/resource.*` | React Router resource routes (data endpoints) |
| `^/action/.*` | React Router actions (form submissions) |
### Keep Rules in Sync
`HYBRID_ROUTING_RULES` (what Storefront Next owns) and `PUBLIC__app__hybrid__legacyRoutes` (what SFRA owns) are complementary. Any path not in routing rules that could be a `<Link>` target should be in `legacyRoutes`.
## Common Considerations
- **Cookie domains** — Both storefronts must share a cookie domain for session bridging
- **CDN configuration** — Update eCDN origin rules as pages migrate
- **SEO continuity** — Maintain URL structure to preserve search rankings
- **Cart synchronization** — Basket state is consistent via shared session cookies
## Troubleshooting
| Issue | Cause | Solution |
| --------------------------------- | -------------------------- | ------------------------------------------------- |
| Lost session crossing storefronts | Cookie domain mismatch | Ensure shared parent domain |
| Cart items disappear | Basket not synced | Verify session bridge cookies (`dwsid`, `cc-*`) |
| Redirect loops | Conflicting routing rules | Check eCDN rules and `legacyRoutes` consistency |
| 404 on SFRA pages (local dev) | Missing from routing rules | Add path to `HYBRID_ROUTING_RULES` |
| React Router 404 on legacy route | Missing from legacyRoutes | Add path to `PUBLIC__app__hybrid__legacyRoutes` |
## Related Skills
- `storefront-next:sfnext-authentication` - SLAS token management and session cookies
- `storefront-next:sfnext-deployment` - MRT deployment for hybrid setup
- `storefront-next:sfnext-configuration` - Environment configuration for hybrid mode
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.