Upgrade JSS 22.1 Next.js apps to version 22.2
This topic covers most of the changes you must make to your existing JSS 22.1 applications to take advantage of the new features in version 22.2, which primarily relate to integration with version 0.4 of the Cloud SDK. However, because of the nature of JavaScript and Next.js application development, this topic doesn't account for all the customization you might have in your existing application.
While upgrading, consider the JSS templates and add-ons you used when creating your Next.js application. You can find them in your package.json file. For example, a JSS 22.1 application included in the XM Cloud starter foundation uses the following templates and add-ons:
Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.
-
nextjs -
nextjs-xmcloud -
nextjs-sxa -
nextjs-multisiteÂ
-
If you haven't already done so, upgrade your app to JSS 22.1.
-
Familiarize yourself with the changelog. If your application is heavily customized, the changelog can provide guidance on what additional changes you need that are not covered in this topic.
This topic describes how to:
Update application dependencies in your existing app
For your upgraded application to work correctly, you will need to update dependencies.
To update your dependencies:
-
In your existing application's
package.jsonfile:-
Update every
@sitecore-jsspackage to version~22.2.0. -
Update the
@sitecore/componentspackage to version~2.0.0. -
Add the
@sitecore-cloudsdk/corepackage at version^0.4.0. -
Update the
@sitecore-cloudsdk/eventspackage to version^0.4.0.
-
-
Install the dependencies with the following command:
Create a JSS 22.2 Next.js application
To simplify the upgrade process as much as possible, create a JSS 22.2 Next.js application with the XM Cloud add-on. You can then copy some files from this app into your existing app.
To create a JSS 22.2 Next.js application with the XM Cloud add-on included:
-
In a console, run the following command:
-
If prompted to install the
[email protected]package, answer y. -
Enter the folder path for the JSS 22.2 Next.js app. For example, enter
./jss222, to create the app folder in your current working directory. -
Follow the remaining prompts, selecting the same options for data fetching (
GraphQLorREST) and prerendering (SSGorSSR) as in your existing application. -
When asked if you are building for Sitecore XM Cloud, answer y to install the XM Cloud add-on.
-
Select other add-ons used by your existing application and press Enter.
The script then installs the application dependencies.
Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.
Update the Next.js template files in your existing app
This explains how to synchronize files in your existing application with corresponding files from your new JSS 22.2 app.
To update the Next.js template files:
-
Delete the
src/lib/context/folder. -
If you have not customized the
src/Bootstrap.tsxfile, replace it with the 22.2 version. Otherwise, modify your file as follows:-
Delete the following import statement:
-
Add the following import statements:
-
Locate the following call:
-
Replace it with the following, which is performed within
useEffectand only takes effect in normal (not developer) mode:
-
-
If you have not customized the
src/components/CDPPageView.tsxfile, replace it with the 22.2 version. Otherwise, modify your file as follows:-
Delete the following import statement:
-
Add the following import statement:
-
Locate the context promise, such as:
-
Replace it with a simplified version similar to the following, using your own properties for
pageView, such as:
-
-
If you have not customized the
src/byoc/index.tsfile, replace it with the 22.2 version (which is namedindex.tsx) and delete the old file. Otherwise, modify your file as follows:-
Rename the file to
index.tsx. -
Delete the following import statement:
-
Add the following import statements:
-
Locate the existing
FEAAS.setContextPropertiescall, such as: -
Replace it with the following, which contains a new version of that call:
-
Replace the existing export statement at the end of the file with the following:
-
-
Search for any other
'lib/context'imports throughout your code and delete them. If your app used thecontext.getSDK()method, you can now use CloudSDK method calls directly. If your app currently usescontextto retrieve other values, we recommend usingtemp/configinstead. -
If your app contains any other references to the Cloud SDK, update them using the Cloud SDK upgrade guide.
Next steps
To finalize the upgrade process, make sure you resolve any errors and warnings you encounter. Enable debug logging for JSS specific issues to assist you if necessary.