Sknoe / Notes

Building with Salesforce Storefront Next: Real Developer Experience & Lessons

What building a standalone Storefront Next feature feels like, how React state shapes the UI, and what SFRA developers should know before they start.

4 min read

Your colleagues are already talking about migrating their projects to Salesforce Storefront Next—raving about how fast, modern, and smooth the React-based architecture feels compared to legacy SFRA. If you are tempted to see what the hype is about, you are in the right place.

I recently built and shipped a standalone feature in Salesforce B2C Commerce Storefront Next on a live project, and the experience was… interesting to say the least.

If you come from SFRA, you already know the drill: a request hits a controller route (server.get), the route prepares view data and packs it into pdict, and ISML turns that data into HTML. Then you open a Storefront Next project and find route files, loaders, React components, and actions.

Suddenly, you are staring at the folder tree asking:

  • Which part replaces the controller?
  • Is a loader just a new name for server.get()?
  • Where did pdict go?

1. The Core Shift: Server Round-Trips vs. State-Driven Views

In SFRA, adding a product or moving from Cart to Shipping Details can involve another controller request, a full page response, or an AJAX call that updates part of the page. The exact flow depends on how that feature was built.

In Storefront Next, you stop manually updating the DOM. Instead, you describe what the screen should look like for a given state, and React updates the UI when that state changes. Server work still happens behind the scenes—loaders fetch product data, and actions update the basket—React just handles how the screen reacts.

UI = f(state)

2. Seeing It in Action: A Step-by-Step Quick-Order Flow

Let’s take a small quick-order interface. When the list is empty, the shopper sees the add-product step. Once an item is added, the component renders the selected items and the customer-details step. The rendered UI follows the current state; we are not manually hiding and showing DOM elements for this normal interaction.

This example keeps items in React state only so you can see that UI transition clearly. It is not a production Commerce basket integration: it does not persist the basket, verify a SKU, or call a Salesforce API.

Step 1: Hold the order list in React state

Instead of packing items into pdict on the server, keep an items array in component state with useState:

QuickOrderFlow.jsx
import { useState } from 'react';
export function QuickOrderFlow() {
// Starts empty [] -> Step 1 renders first
const [items, setItems] = useState([]);
const [skuInput, setSkuInput] = useState('');

React watches items. Whenever we update it via setItems, React re-runs this component to calculate the new UI.

Step 2: Add an item by returning a new array

When the user submits a SKU, create a new item and pass a fresh array ([...previous, newItem]) to setItems:

QuickOrderFlow.jsx
const handleAddItem = (event) => {
event.preventDefault();
const sku = skuInput.trim().toUpperCase();
if (!sku) return;
const newItem = { id: crypto.randomUUID(), sku };
// Return a new array—never mutate with previous.push()
setItems((previous) => [...previous, newItem]);
setSkuInput('');
};
Under the hoodWhy [...previous, newItem] instead of previous.push()?React detects state changes by comparing memory references, not array contents.

Looking closer

Calling push() mutates the existing array in place and keeps the exact same memory reference. React thinks nothing changed and skips updating the screen. Spreading into a new array gives React a new reference and triggers an immediate UI update.

Step 3: Let state choose which view renders

Inside return (...), use a standard JavaScript ternary (condition ? viewA : viewB) to render either the empty form or the customer details section:

QuickOrderFlow.jsx
return (
<div className="quick-order-container">
<p>
<strong>Current step: </strong>
{items.length === 0 ? '1. Add products' : '2. Customer & delivery details'}
</p>
{items.length === 0 ? (
<form onSubmit={handleAddItem}>
<input
value={skuInput}
onChange={(e) => setSkuInput(e.target.value)}
placeholder="e.g., SKU-1024"
/>
<button type="submit">Add to Order</button>
</form>
) : (
<section>
<h3>Selected Items ({items.length})</h3>
<ul>
{items.map((item) => (
<li key={item.id}>{item.sku}</li>
))}
</ul>
<h3>Customer Details</h3>
<input type="text" placeholder="Full Name" />
<input type="text" placeholder="Delivery Address" />
</section>
)}
</div>
);
}

The instant items.length goes from 0 to 1, React swaps out the form for the customer details section.

3. Mapping SFRA Concepts to Storefront Next

If you are trying to map your existing Salesforce B2C Commerce knowledge onto this stack, use the responsibilities as your guide. The names and boundaries do not map one-to-one.

From SFRA Request Flow to Storefront Next
  1. 1. Route Entry: server.get() → Route Module

    SFRA matches a URL to a controller route; Storefront Next matches a URL to a configured React Router route file.

  2. 2. Initial Data Fetch: Controller/Model → Server loader()

    Instead of calling dw.* inside a controller, a route loader() fetches catalog or product data from SCAPI before the page renders.

  3. 3. View Data: pdict → useLoaderData() & State

    pdict becomes useLoaderData() for server-loaded route data and useState for interactive client state.

  4. 4. Templating: ISML → React JSX Components

    Server-rendered ISML tags (<isif>, <isloop>) become standard JSX (? :, .map()).

  5. 5. Mutations: server.post() / AJAX → Route action() or API Client

    Form posts and updates run through React Router action() functions or a decoupled API client.

4. Putting It Together: Answering Your 3 Questions

Remember the three questions from the start when you first opened a Storefront Next folder tree? Now you have the map:

1. Which part replaces the controller? The route module coordinates the screen, while server loaders and actions handle data and mutations.
2. Is a loader just server.get()? Similar job, cleaner boundary. A loader fetches data on the server before your component renders—without manually wiring res.render().
3. Where did pdict go? Server-loaded data arrives through useLoaderData(), and interactive screen changes live in React state (useState).

What’s Next in the Series?

Next up in Part 2: what happens when a shopper double-taps Submit or the network drops mid-request? We’ll replace loose isLoading flags with a 5-state React reducer—and in Part 3, connect it to a resilient polling loop for slow APIs.

Continue the learning path

The JavaScript Before React: A Step-by-Step Guide to the Fundamentals covered the language features that make React code easier to read. React for Salesforce Storefront Next: The Concepts SFRA Developers Need introduced components, props, state, events, and Storefront Next route data. This article connects those ideas to the architecture you already know from SFRA.

Review the SFRA foundation in How SFRA Works: A Beginner’s Guide and SFRA Models and ViewModels: How Data Gets Ready for ISML, then follow an end-to-end SFRA feature in Build Add to Cart: A Backend-to-Frontend SFRA Journey. The React concepts leading into this comparison are in React for Salesforce Storefront Next: The Concepts SFRA Developers Need.

Did this click?

Tap the bulb if this explanation helped.

Further reading

Storefront Next overview

Storefront Next routing

Storefront Next data fetching

Storefront Next state management

SFRA overview

Interview questions

Is a Storefront Next loader the same thing as an SFRA controller?

No. An SFRA controller route can coordinate middleware, data preparation, and template rendering. A Storefront Next route module can separate related responsibilities into a loader for route data, an action for mutations, and a React component for the interface. They participate in similar request flows but have different APIs and runtime contracts.

Where should product data be prepared for a Storefront Next route's initial render?

Start with the route's server loader, which obtains and returns data before the component renders. Then follow how the component reads that route data and passes the values children need through props. Keep presentation formatting in the appropriate view layer and server-specific access in server-side helpers.

What does React Router do with route data after an action completes?

After a route action completes, React Router revalidates active route loaders so components can read refreshed server data. The action can also return a result for immediate success or validation feedback. The browser should display the server-confirmed outcome rather than treating a local state change as proof that a Commerce mutation succeeded.

What is one reason an SFRA feature cannot be translated by copying its controller into a route file?

The runtimes and framework APIs differ. SFRA controller methods, middleware conventions, and server-side Commerce Script APIs are not automatically available in Storefront Next. First identify the behavior and data dependency, then implement it with the target project’s routing, server helpers, and Commerce API clients.