Previously, when deploying in Vercel or connecting to XM Cloud using local Next.js, deployment was done using API keys and endpoints; since JSS 21.6, this has been changed to allow the use of Context IDs. This is introduced in this issue.
Verification of Context ID.
In the XM Cloud Deploy administration screen, select the environment, open Detail and two Context IDs are given for the environment. This key allows you to view Live (published content) and Preview (all content).
![contextid01.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F1yrbjv0kYGqpdWuYMG9v1s%2Fa71289a7a6580dd1a0a13d0bdf8a8f15%2Fcontextid01.png&w=3840&q=75)
Switching to the Developer Settings tab also shows the actual keys used and makes it easier to use them with copy-paste.
![contextid02.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2FEvQizIjgNNfzMCKXcnsxI%2F281a47ef42d73569f33bc1ca4996a923%2Fcontextid02.png&w=3840&q=75)
Deploy the XM Cloud sample site in practice.
Preparing sample sites
In this case, we just want to see how to deploy using Context IDs, so follow the steps below to create a site.
- Create Basic site
- Publish site
- Prepare the Context ID.
Assume the following situation: a site is ready to go.
![contextid03.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F27JLXWsvKLKqVK38jLYbzo%2Fcc498e9148f4b3c08ef07590b11dfd2c%2Fcontextid03.png&w=3840&q=75)
Creating a project in Vercel
Create a new project. The steps are as follows.
- Create new project
- Select GitHub repository.
- Set the Environment Variables to the Live values in Developer Settings.
![contextid04.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F1qc6VkU6aNuKxBPJTmJjK0%2F972ec15c245aec3fcb3f9230e653995e%2Fcontextid04.png&w=3840&q=75)
Click on the Deploy button and the website is up and running in a few moments.
![contextid05.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F2OzNYS0lxxQHKk1VVQlG9T%2F465b9349cff31ca5b4cd148c10705889%2Fcontextid05.png&w=3840&q=75)
Prepare Preview environment
We have launched a site using Context ID's Live, but this time we will create a preview site using Preview. First, create a Preview branch in the GitHub repository.
![contextid06.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F59SGaLftIOtVMipO8nX4q5%2Fed8e590e6a24ea4cf2833453bd051f0a%2Fcontextid06.png&w=3840&q=75)
In Vercel, select Settings - Domain from the previous project to add a preview domain.
![contextid07.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F63ul6hpJ4o1RUI22wdSnnh%2F3da21d48ed69421b9a70845f92bf2857%2Fcontextid07.png&w=3840&q=75)
Then switch to the Environment Variables screen: do not change anything for SITECORE_SITE_NAME as it is common. For this reason, only check Production for SITECORE_EDGE_CONTEXT_ID.
![contextid08.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F5WWiHMVmY31Em8ihNdihtT%2Fb7914a835115769aa721fe4792105b9b%2Fcontextid08.png&w=3840&q=75)
Then add the Preview values SITECORE_EDGE_CONTEXT_ID and JSS_EDITING_SECRET from the Developer settings screen in XM Cloud Deploy.
![contextid09.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2FwVAj5lutWxDVZiMYEvp1e%2F189aafe9087136aa7b7bf60f918619ee%2Fcontextid09.png&w=3840&q=75)
You are now ready to deploy the Preview; updating the Preview branch on GitHub will automatically start the Build.
![contextid10.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F6yzQ0Ok6H5fgqeVB6anY94%2F8a71d4d93dbf65b74e55c20ea64b0f2d%2Fcontextid10.png&w=3840&q=75)
After a short time, the site was up and running.
![contextid11.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F7I69qtRmaCO21Mz6eEpEdB%2Ff973100f5b00e0ca87a9e51402c5c39f%2Fcontextid11.png&w=3840&q=75)
Find out the difference between Live and Preview.
Now you have two sites up and running, what's the difference?
![contextid12.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F3M8c2Oi9l4kIzrvaeljB1g%2F3f05849f8fb47f5f0c1e52891efeb464%2Fcontextid12.png&w=3840&q=75)
With regard to this page, the Preview website shows that the content has already been updated.
![contextid13.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F5ztEYC28O8Ei73w28m5RqX%2F030b017b0e36a380f0ae0adcb584a5c0%2Fcontextid13.png&w=3840&q=75)
In this way, if you are using a Preview ID, you can preview the page you are editing in Sitecore via the web server. The site is updated when the Publish is actually executed.
Summary
When deploying to Vercel, we have confirmed that it is possible to obtain values from XM Cloud Deploy and deploy the site. We have also confirmed the difference between Live and Preview behaviour for Context IDs.
Note: We have added an article that confirms the operation of the system. Please refer to it as well.