Upgrade JSS 21.6.4 Next.js apps to version 21.7
The JavaScript Rendering SDKs (JSS) 21.7 uses Next.js 14 and has improved GraphQL retries.
The update contains changes to environment variables, configuration objects, JSS packages, services, and dependencies.
This topic covers most of the changes you must make in your existing JSS 21.6.4 applications to take advantage of the new features. 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.
When performing the upgrade, 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.6.4 application might use the following templates and add-ons:
-
nextjs -
nextjs-sxa -
nextjs-multisite
-
If you haven't already done so, upgrade your app to JSS 21.6.
-
Familiarize yourself with the changelog. If your application is heavily customized, you might need to refer to it for hints on what additional changes you need, which might not be covered in this topic.
-
Read about the Next.js 14 release and keep the Next.js 14 upgrade guide handy. You might need it to finalize the upgrade of your application.
This topic describes how to:
Update environment variables for your existing app
The GraphQL retry functionality is now enabled by default with three retries, while still allowing you to use default or custom retry strategies when fetching data from the Edge GraphQL endpoint.
To customize the global number of retries:
-
In the JSS application's
.envfile, update the value of theGRAPH_QL_SERVICE_RETRIESenvironment variable to the desired number (or to 0 to disable retries).
You might need to restart the local application server for the environment variable changes to take effect.
Update application dependencies in your existing app
For your upgraded application to work correctly, you must also update dependencies.
To update your dependencies:
-
In your existing application's
package.jsonfile, do the following:-
Update the Next.js version:
-
Update every
@sitecore-jsspackage to version~21.7.0. -
Update the package versions in
devDependenciesto the new versions, as follows:
-
-
Install the dependencies with the following command:
-
Perform any Next.js specific upgrades using the Next.js 14 upgrade guide. If necessary, use the provided codemods to complete the Next.js upgrade.
Create a JSS 21.7 Next.js application
To simplify the upgrade process as much as possible, you must create a JSS 21.7 Next.js application. You will need to copy some files from this app into your existing app.
To create a JSS 21.7 Next.js application:
-
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.7 Next.js app. For example, ./jss217, 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 n to skip installing the XM Cloud add-on.
-
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
In this procedure, you will synchronize files in your existing applications with corresponding files for the JSS 21.7 app.
To update the Next.js template files:
-
Copy the
src/lib/next-config/plugins/component-props.jsfile from the 21.7 app to your existing app. -
If you have not customized the
/src/lib/dictionary-service-factory.tsfile, replace it with the 21.7 version. Otherwise, modify the file as follows:-
Locate the
retriesoption in theGraphQLDictionaryServiceconstructor options: -
Replace that code block with the following:
-
-
If you have not customized the
/src/lib/layout-service-factory.tsfile, replace it with the 21.7 version. Otherwise, modify the file as follows:-
Locate the
retriesoption in theGraphQLLayoutServiceconstructor options: -
Replace that code block with the following:
-
Update the SXA add-on
To upgrade the SXA add-on:
-
Replace the following files with the 21.7 versions:
-
src/assets/basic/_container.scss -
src/assets/sass/_app.scss
-
-
Update the
/src/components/Image.tsxfile as follows:-
Import the
CSSPropertiestype from thereactpackage: -
Update the
backgroundStyleconstant definition to:
-
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.
We recommend you evaluate your needs in relation to GraphQL retries and use GraphQL request retry strategies as needed to mitigate rate limits in GraphQL endpoints.