Access Site Preferences in Your Composable Storefront from the MRT Data Store
If your composable storefront code requires access to the site preferences that administrators manage in Business Manager, access site preferences directly from the Managed Runtime (MRT) Data Store. Accessing site preferences from the MRT data store is faster than making a Salesforce B2C Commerce API (SCAPI) call. Enable the MRT data store by using a configuration or an environment variable.
Enable the MRT Data Store
Before accessing the MRT Data Store, enable it in the app configuration file or by using an MRT environment variable.
Enable the MRT Data Store in the app configuration value in config/default.js as shown in this example.
1module.exports = {2 app: {3 mrtDataStore: {4 enabled: true // Enable MRT Data Store bootstrap5 },6 // ... rest of config7 }8}
Alternatively, use an environment variable to enable the MRT Data Store.
1PWAKIT_MRT_DATA_STORE_ENABLED=true npm start
If the PWAKIT_MRT_DATA_STORE_ENABLED environment variable is set to a valid value, it takes precedence over the app configuration value.
Note
Usage in ssr.js (Server Middleware)
Access preferences at the server middleware layer, before React renders. The async getCustomSitePreferences and getCustomGlobalPreferences functions from @salesforce/pwa-kit-runtime/utils/ssr-server let you inspect preference values and modify the HTTP response—for example, returning a 503 status during maintenance or populating an API endpoint with feature flags. Because middleware runs before rendering, this is the right place when preferences need to gate or redirect requests. To access preferences inside React components instead, use the utility functions or hooks.
Use the utility functions from @salesforce/pwa-kit-runtime/utils/ssr-server when you need direct control over how preferences are fetched and cached. Wrap them in useQuery from @tanstack/react-query to configure caching behavior—for example, staleTime: Infinity fetches data once per session, and enabled: Boolean(siteId) prevents the query from running until a site ID is available. Extract this logic into shared custom hooks and call them from any component that needs to conditionally render content based on preference flags.
Use the React hooks for the most idiomatic way to access preferences in React function components. The useCustomSitePreferences and useCustomGlobalPreferences hooks from @salesforce/pwa-kit-react-sdk/ssr/universal/hooks integrate with React’s component model, follow standard hook conventions, and can be composed into custom hooks. This is the recommended approach for React function components.
Use MRT_DATA_STORE_DEFAULTS to seed values without a real data store for local testing. You can use either a flat object or the SCAPI envelope format with data and total.
Or use the SCAPI envelope format to match the actual data store structure. Include both data (array) and total (number) — both fields are required to trigger envelope unwrapping:
For example, based on the MRT_DATA_STORE_DEFAULTS definition, getCustomSitePreferences({siteId: 'RefArch'}) returns:
1{2 productsPerPage: 24,3 showBanner: true4}
And getCustomGlobalPreferences() returns:
1{2 enableChat: true,3 maintenanceMode: false4}
Data Store Structure
The MRT Data Store is populated automatically when enabled. You don’t need to manually configure keys. The utilities and hooks handle key resolution internally based on the site ID you provide.
For reference, data is stored under these keys:
Global preferences: custom-global-preferences
Site preferences: {siteId}-custom-site-preferences
The exact structure of the preference objects depends on the custom preferences defined in Business Manager for your B2C Commerce instance.