Upgrade JSS 21.7 Next.js apps to version 21.10
This guide covers most of the changes you must make to your existing Next.js JSS 21.7 applications to take advantage of the improvements in version 21.10. However, because this process also involves updating React to version 19 and Next.js to version 15, you'll need to refer to the relevant guides for each framework to complete the upgrade process for your apps.
This version of JSS introduces Cloud SDK 0.5.1. Due to fundamental changes introduced in this version, you will need to make substantial changes to your JSS app, as described in this upgrade guide.
If you haven't previously upgraded your 21.x app's version of Cloud SDK to 0.4.0, you'll also need to refer to the 0.4.0 upgrade guide and make any relevant changes mentioned there.
Because of the nature of JavaScript and Next.js application development, this guide 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 21.7 application included in the XM Cloud starter foundation uses the following templates and add-ons:
-
nextjs -
nextjs-xmcloud -
nextjs-sxa -
nextjs-multisiteÂ
Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.
-
If you haven't already done so, upgrade your app to JSS 21.7.
-
We recommend you read the official release notes for React 19 and Next.js 15 to understand what has changed in these new versions.
-
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~21.10.0. -
Update the
@sitecore-cloudsdk/eventspackage to version^0.5.1. -
Add the
@sitecore-cloudsdk/corepackage at version^0.5.1. -
Update the
@sitecore/componentspackage to version~2.0.0. -
Update the following dependencies to the specified versions:
-
-
Install the dependencies with the following command:
Create a JSS 21.10 Next.js application
To simplify the upgrade process as much as possible, create a JSS 21.10 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 21.10 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 21.10 Next.js app. For example, enter
./jss2110, 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.
XM Cloud is now SitecoreAISome code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.
-
Select other add-ons used by your existing application and press Enter.
The script then installs the application dependencies.
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 21.10 app.
To update the Next.js template files:
-
Remove the
src/lib/contextfolder. -
If you have not customized the
src/Bootstrap.tsxfile, replace it with the version in your template app. Otherwise, make the following changes:-
Add the following imports required for Cloud SDK 0.5.1:
-
Delete the
contextimport: -
Locate the associated
initmethod call: -
Delete that call, replacing it with the following to initialize Cloud SDK. Make sure this new call is made with
useEffect()in normal, non-development mode:
-
-
If you have not customized the
src/components/CDPPageView.tsxfile, replace it with the version in your template app. Otherwise, make the following changes:-
Add the following imports required for Cloud SDK 0.5.1:
-
Delete the
contextimport: -
Locate the associated promise:
-
Replace it with the following direct call to
pageView:
-
-
If you have not customized the
src/byoc/index.tsfile, replace it with the version in your template app. Otherwise, make the following changes:-
Change the file extension to
.tsx. -
Add the following imports required for Cloud SDK 0.5.1:
-
Delete the
contextimport: -
Delete the following call:
-
Add the following component definition:
-
Replace the
defaultexport statement with the following:
-
-
Unless you previously upgraded your JSS 21.x app's Cloud SDK version to 0.4.0, you'll need to make additional changes as described in the 0.4.0 upgrade guide.
-
Remove all other
lib/contextimports throughout your app. Instead ofcontext.getSDK(), you can now call Cloud SDK methods directly. If you're using context to retrieve other values, we recommend usingtemp/configinstead. -
Because Next.js 15 removes the
geoandipproperties fromNextRequest, if your solution is hosted by Vercel you need to update yoursrc/lib/middleware/plugins/personalize.tsplugin to explicitly provide geo data to thePersonalizeMiddleware, via thePersonalizeOptionsparameter of the personalize middleware handler.If you have not customized the
src/lib/middleware/plugins/personalize.tsfile, replace it with the version in your template app. Otherwise, modify it as shown in the following example: -
For every component that uses the
JSXnamespace (for example, if aJSX.Elementtype is present), add aJSXimport fromreact.-
In the
src/Bootstrap.tsxfile, the existingreactimport might look like this: -
In which case, add
JSXto create the following:
TipIf you haven't previously customized these files, you can replace them with the versions from your template app.
-
Update the SXA add-on
To update the SXA add-on:
-
If you have not customized the
src/assets/sass/components/_component-column-splitter.scssfile, replace it with the version in your template app. Otherwise, do the following:-
Locate the following padding rules:
-
Replace those rules with the following:
-
-
If you have not customized the
/src/assets/sass/components/promo/_promo-shadow.scssfile, replace it with the version in your template app. Otherwise, reposition the CSS statements above the@include respond-to(all-mobile)block, as shown in the following example:-
CSS statements (
padding,margin) previously: -
CSS statements after moving them both:
-
-
If you have not customized the
src/lib/next-config/plugins/sass.jsfile, replace it with the version in your template app. Otherwise, add the following extra properties to yoursassOptionsconfiguration:NoteThis change is a temporary fix to suppress
sassdeprecation warnings from Bootstrap. When new versions ofbootstrapandfont-awesomeare released and the warnings stop, these two properties can be removed.
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.