When working with personalization in SitecoreAI, you expect the preview to reflect the experience you have selected. But what happens when you select a personalized variant in Pages, click Preview, and still see the default version of the page?
We encountered this behavior while working with personalized versions of a home page in SitecoreAI. Here is what we investigated, what we discovered about the Content SDK, and a possible workaround for projects that are not yet ready to upgrade.
The Problem
We had created multiple personalized versions of our home page to deliver different experiences to different audiences.
For example, one of the variants was intended for Wholesalers. While working in the Personalize section of Sitecore Pages, we could select this variant. However, clicking the Preview icon in the top-right corner did not display the selected personalized experience.
Instead, the preview consistently showed the default version of the page, regardless of which variant we selected.
This made it difficult for content authors to verify the appearance of personalized experiences in preview mode.
The expected behavior was straightforward: when a particular personalization variant is selected, the preview should display that variant rather than the default page.
Our Investigation
We started by looking at how the page behaved inside the Pages editor.
The first thing to establish was whether the personalization itself was working or whether the problem was specific to the preview experience.
When we reviewed the personalized variants in the Pages editor, they were available for rendering, and the selected variant could be applied in edit mode. The unexpected behavior occurred when we switched to Preview.
This distinction was important. If the variant was available in the editor but the preview continued to display the default page, the issue was not necessarily with the personalization rules or content configuration. It could instead be related to how the selected variant was communicated to the preview rendering request.
We then investigated the relationship between our Content SDK version and the preview functionality. This led us to a key finding: the ability to preview a specifically selected personalization variant depends on the Content SDK version and how the Preview API request is constructed.
We raised the issue with Sitecore Support to validate our findings and understand the supported options for our current SDK version.
What Sitecore Support Confirmed
Sitecore Support confirmed that previewing a selected personalized variant directly in Preview mode is supported natively from Content SDK 2.2.0 onwards. This capability is not available out of the box in Content SDK 1.x versions.
Support also confirmed the technical detail that helped explain the behavior: the Preview API can render the requested variant when the sc_variant header is included in the GraphQL Preview request.
This gave us two possible approaches: use the Pages editor to review variants in the meantime, or customize the preview request in our application.
Understanding the Technical Solution
In a typical Sitecore Content SDK Next.js application, the page route is commonly located at:
src/pages/[[...path]].tsx
The preview flow uses the Content SDK to retrieve preview data. In SDK versions where selected-variant preview is not supported natively, the preview request needs additional information to identify which variant should be rendered.
The relevant API is:
client.getPreview(previewData, fetchOptions)
The second argument, fetchOptions, allows custom options, including HTTP headers, to be passed with the Preview GraphQL request.
The proposed workaround is to pass the selected variant ID through the sc_variant header.
Conceptually, the implementation involves three steps:
- Read the selected variant ID from
previewData.variantIds. - When handling the Preview request, pass the selected variant ID as the
sc_variantheader. - If no variant is selected, use
default.
A simplified illustration of the intended request configuration would look like this:
const fetchOptions = {
headers: {
sc_variant: selectedVariantId || 'default',
},
};
Here, selectedVariantId represents the variant ID extracted from the actual preview data. This example illustrates the header configuration; it is not a complete, drop-in implementation. The exact integration depends on how the existing page route handles preview mode and calls getPreview.
The key point is that selecting a variant in the Pages interface is not, by itself, enough for an older SDK preview request to render that variant. The request must carry the selected variant information.
This customization should be implemented and tested against the actual SDK API and preview flow in your application before being used in production.
An Alternative While Waiting for an Upgrade
If upgrading the SDK is not immediately possible, content authors can continue reviewing personalized variants in the Pages editor.
In edit mode, the personalized variants are returned to the application, and the selected variant is applied there. This provides a practical way to review the personalized experience without relying on the affected Preview flow.
The custom sc_variant header approach is another option for teams that need the selected variant to render in Preview mode before upgrading.
However, this is a custom implementation rather than native support in the older SDK. It needs thorough testing, particularly to verify that selecting a different variant changes the preview correctly and that the default experience continues to work when no variant is selected.
The Long-Term Fix
For projects using Content SDK 1.x, upgrading is the cleaner long-term solution.
Sitecore Support recommended planning an upgrade to the latest Content SDK 2.4.x release available for the project. The native behavior introduced in version 2.2.0 removes the need to maintain a custom workaround for this particular limitation, while later versions include further improvements to personalization handling.
As with any SDK upgrade, compatibility with the existing application and dependencies should be evaluated before proceeding.
Conclusion
This investigation was a useful reminder that a personalization issue in SitecoreAI does not always originate in the personalization configuration itself.
In our case, the behavior pointed towards the preview rendering flow and the capabilities of the Content SDK version in use. Reviewing the page in edit mode helped narrow down the problem, and Sitecore Support confirmed the version-specific limitation and the role of the sc_variant header in the Preview API request.
If you encounter the same issue, I would recommend checking your Content SDK version first, verifying the behavior in edit mode, and then deciding between a tested request customization and an SDK upgrade.
Sometimes the key to solving a Sitecore issue is not changing the content or personalization rules, but understanding what information is actually being passed to the rendering application.
Hope this helps you!!
Comments
Post a Comment