Upgrade Content SDK 1.2.0 Next.js apps to version 1.3.1
This guide covers the required changes you must make to your existing Content SDK 1.2.0 applications to take advantage of the new features and improvements in version 1.3.1. Content SDK 1.3.1 includes the general release of Next.js App Router and several other improvements and bug fixes. Note that version 1.3.0 was released and deprecated due to a critical vulnerability related to React Server Components.
Because JavaScript and Next.js development is very flexible and customizable, this guide provides only general instructions and might not cover the specific configurations, custom code, or architectural decisions present in your existing application.
-
If you have a JSS app that you want to convert into a Content SDK app, follow the migration guide to upgrade your JSS Next.js 22.9/22.10 app to a Content SDK 1.3.1 app instead of this topic.
-
Review the changelogs for 1.3.0 and 1.3.1. 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 must update dependencies.
To update your dependencies:
-
In your existing application's
package.jsonfile, update every@sitecore-content-sdkpackage to version1.3.1. -
Install the dependencies with the following command:
Update the Next.js template files in your existing app
After updating your dependencies, you must synchronize files in your existing application.
Pages Router
To update the Next.js template files in your Content SDK Next.js Pages Router app, in your existing app's middleware.ts file:
-
Find the following:
-
Replace it with the following:
-
Pass local configuration to the
redirectsmiddleware:
App Router
The editing config Router Handler has been updated to support component runtime information for compatibility with Sitecore Pages. Before this, the route handler only provided component names and metadata. Now, the Router Handler accepts an optional clientComponents parameter and returns additional information, including framework type and the client component list. This allows Pages to differentiate between server and client components, preventing invalid operations.
To update the Next.js template files in your Content SDK Next.js App Router app:
-
In your existing app's
middleware.tsfile:-
Find the following:
-
Replace it with the following:
-
Pass local configuration to the
redirectsmiddleware:
-
-
In your application's
/api/editing/config/route.ts:-
Add the following import:
-
Pass
clientComponentsto thecreateEditingConfigRouteHandler:
-
-
In
src/Layout.tsx:-
Remove the following import:
-
Add the import for
DesignLibraryAppto replace the earlier one forDesignLibraryLayout: -
Remove the following usage of the
DesignLibraryLayout: -
Replace it with the following:
-
Remove the
DesignLibraryLayout.tsxfile.
-
-
In
src/Providers.tsx:-
Pass the client import map inside
SitecoreProviderso that it's available in context: -
In
/src/app/api/editing/render/route.tsaddPOSTto the exported handlers:
-
The middleware.ts file introduces a new callback function called extractGeoDataCb(). It runs on every request in the Edge middleware and provides geo location data that the PersonalizeMiddleware uses for personalization.
It returns an object that contains the following properties:
-
city -
country -
region
You can implement the callback in the PersonalizeMiddleware configuration to extract or provide geo data on each request. Some of the common approaches include using a geo-IP service or extracting geolocation data from the request headers. You can also use static values like in the template middleware.ts file for testing.
Next steps
To finalize the upgrade process, make sure you resolve any errors and warnings you encounter. Enable debug logging for Content SDK specific issues to assist you if necessary.