-
Couldn't load subscription status.
- Fork 276
Description
Describe the Bug
When a headless site using JSS is renamed, the personalize middleware plugin fails on subsequent page loads. This failure occurs because the cookie sc_site still holds the old site name. The middleware attempts to resolve the site using this outdated name and throws an exception stating it cannot resolve the site.
To Reproduce
- Deploy a headless site using JSS.
- Access the site and confirm the
sc_sitecookie is set with the current site name. - Rename the site in Sitecore.
- Redeploy the site after renaming.
- Attempt to load a page on the renamed site.
- The Personalize middleware throws an exception. HTTP 500 server error is displayed.
Here are Vercel logs:
Personalize middleware failed:
[Error: Could not resolve site for name oldname]
⨯ Error: Could not resolve site for name oldname
at SiteResolver.getByName (/var/task/headapps/nextjs-starter/node_modules/@sitecore-jss/sitecore-jss/dist/cjs/site/site-resolver.js:38:23)
at i.exec (/var/task/headapps/nextjs-starter/.next/server/chunks/687.js:402:3474)
at /var/task/headapps/nextjs-starter/.next/server/chunks/687.js:401:18584
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async /var/task/headapps/nextjs-starter/.next/server/chunks/687.js:401:18561
at async /var/task/headapps/nextjs-starter/.next/server/chunks/687.js:401:18561
at async /var/task/headapps/nextjs-starter/.next/server/chunks/687.js:401:18561
at async /var/task/headapps/nextjs-starter/.next/server/chunks/687.js:401:18561
at async /var/task/headapps/nextjs-starter/.next/server/chunks/687.js:401:18561
at async /var/task/headapps/nextjs-starter/.next/server/chunks/687.js:401:18561 {
page: '/en/_site_navigator-ft/about-us'
}
Expected Behavior
The middleware should correctly resolve the site and not throw an exception.
Possible Fix
Wrap the getSite function site resolution logic from the cookie in a try-catch block. If the resolution by cookie fails, fall back to using the host header to resolve the site name. This ensures that the site is resolved all the time. The site name will probably be updated in the cookie once the page load is successful.
Provide environment information
- Sitecore Version: XM Cloud
- JSS Version: 22.4.1
- Browser Name and version: Google Chrome v138.0.7204.158
- Operating System and version (desktop or mobile): Windows 11 Pro 24H2 (desktop)