# Hybrid Stability Upgrade for PWA Kit Version 3.8.0

This guide explains how to make and verify code changes in a [hybrid storefront](/docs/commerce/b2c-commerce/guide/hybrid-implementation.md) to:

- Update a Progressive Web App (PWA) Kit project from version 3.5.0 or later to version 3.8.0.
- Upgrade from Plugin Shopper Login and API Access Service (Plugin SLAS) version 7.3.0 or later to version 7.4.0.

We recommend testing the steps in a non-production environment before deploying your changes to production.

:::tip
Only existing customers can access some of the links on this page. Visit [Salesforce Commerce Cloud GitHub Repositories and Access](https://developer.salesforce.com/docs/commerce/b2c-commerce/guide/b2c-github-repo-access.md) for information about how to get access to the repositories.
:::

:::note
- The steps in this guide apply to a hybrid storefront that uses [Plugin SLAS](https://github.com/SalesforceCommerceCloud/plugin_slas). With B2C Commerce version 25.3, hybrid authentication (auth) replaces Plugin SLAS. For more information, see [Configure a Hybrid Storefront with Hybrid Auth](/docs/commerce/b2c-commerce/guide/hybrid-auth.md).
- This guide applies to hybrid storefronts built in part with PWA Kit version 3.5.0 or later. For the steps that apply to PWA Kit version 2.x, see [Hybrid Stability Upgrade for PWA Kit Version 2.x](/docs/commerce/b2c-commerce/guide/hybrid-upgrade-v2.x.md).
:::

## What’s New

To improve stability and performance for hybrid storefronts, we:

- Removed calls to `OCAPI /sessions` from PWA Kit to eliminate session churn (frequent changes to `dwsid`). For more information about `dwsid`, see [Understand Session Management between SFRA and PWA Kit](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/phased-headless-rollouts.md?q=dwsid#understand-session-management-between-sfra-and-pwa-kit).
- Added a header to Salesforce Commerce API (SCAPI) calls to send the `dwsid` to SCAPI to ensure that requests from a given shopper session are routed to the same app server.
- Removed the Open Commerce API (OCAPI) proxy from the PWA Kit configuration, which makes PWA Kit fully SCAPI-based.

## Prerequisites

If you haven’t already done so, complete these steps.

- [Set Up SLAS for PWA Kit](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/phased-headless-rollouts.md#1-set-up-slas-for-pwa-kit).
- Set Up [Session Bridging](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/phased-headless-rollouts.md#2-session-bridging).
- Configure [Routing](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/phased-headless-rollouts.md#3-routing). See also [CDN APIs for Phased Headless Rollouts](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/ecdn-rules-for-phased-headless-rollout.md).
- Make [Other Changes to PWA Kit Projects](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/phased-headless-rollouts.md#5-other-changes-to-pwa-kit-projects).

## Submit a Support Request

Open a support case that asks Salesforce Customer Support to enable Session Override for dwsid. In the support case:

- Request to enable both parent and child toggles.
- Mention your correct realm ID and tenant ID. If you don’t know your realm ID, ask your Account Executive or Customer Success Manager.

## Make PWA Kit Code Changes

If you're using PWA Kit version 3.5.0 or later:

1. To upgrade to the latest version of Commerce SDK React, run:

   `npm install @salesforce/commerce-sdk-react@latest`

2. To upgrade to the latest version of the Retail React App, run:

   `npm install @salesforce/retail-react-app@latest`

## Make Plugin SLAS Code Changes

If you're using Plugin SLAS version 7.3.0 or later, complete these steps.

1. In `cartridges/plugin_slas/cartridge/controllers/Login.js`:

   - Remove the `access_token` cookie after logout in the `/Login-Logout` controller
   - Add `config.ACCESS_TOKEN_COOKIE_NAME` to the `cookiesToRemove` array in the `/Login-Logout` controller.

2. In `cartridges/plugin_slas/cartridge/scripts/helpers/slasAuthHelper.js`, update the `removeCookie` function to remove any existing chunks of cookies:

   - Change the condition from exact match (==) to `.startsWith`.

3. In `cartridges/plugin_slas/cartridge/scripts/hooks/request/onSession.js`, update the `onSession` hook implementation for the new guest shopper flow:
   - Extract the `dwsid` from `x-is-session_id header` into a variable.
   - Use the variable in the call to `getSLASAccessTokenForGuestSessionBridge`.
   - Set the `dwsid` cookie to the response for new guest shoppers.

See the files changed in this [pull request](https://github.com/SalesforceCommerceCloud/plugin_slas/pull/207/files?diff=split).

## Verify Your Code Changes

1. Confirm that PWA Kit isn’t making calls to `OCAPI /sessions`.

   - Go to your storefront and clear all site data.

     If you’re using Chrome DevTools, see [Delete all cache data](https://developer.chrome.com/docs/devtools/storage/cache#deletecache).

   - Refresh your storefront or go to any page that’s PWA Kit-based and inspect the Network Tab in Chrome DevTools. Confirm that you don’t see requests being made to `dw/shop/<version>/sessions`. See this example from Chrome DevTools.

![No Sessions](https://a.sfdcstatic.com/developer-website/sfdocs/commerce-cloud/media/pwa-kit-managed-runtime/no-sessions.png)

2. Confirm that `dwsid` is sent with all SCAPI requests.

   - Go to your storefront. Visit any SFRA/SG-based page then go to a PWA Kit-based page.
   - If you’re using Chrome DevTools:
     - Open Cookie Storage and look for `dwsid` value in the cookies. See [Open the Cookies pane](https://developer.chrome.com/docs/devtools/application/cookies#open).
     - Open the Network Tab and inspect any SCAPI request (for example, `/baskets`). In the Request Headers, confirm that you see the `sfdc_dwsid` header with the value same as the `dwsid` that you found in the previous step. See this example from Chrome DevTools.

![No Sessions](https://a.sfdcstatic.com/developer-website/sfdocs/commerce-cloud/media/pwa-kit-managed-runtime/dwsid3.png)

## See Also

- [Configure a Hybrid Storefront with Plugin SLAS](/docs/commerce/b2c-commerce/guide/phased-headless-rollouts.md)
- [Build Baskets and Place Orders](https://developer.salesforce.com/docs/commerce/commerce-api/guide/work-with-baskets-orders.md)
- [Get Started with the B2C Commerce API (SCAPI)](https://developer.salesforce.com/docs/commerce/commerce-api/guide/scapi-get-started.md)
- [Configure a Hybrid Storefront with Hybrid Auth](/docs/commerce/b2c-commerce/guide/hybrid-auth.md)
- [Get Started with Composable Storefront](/docs/commerce/b2c-commerce/guide/pwa-developer-workflow.md)
