1. Upgrade guides

Upgrade Content SDK 1.2.0 Next.js apps to version 1.3.1

Version: 1.x

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.

Before you begin
  • 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:

  1. Update application dependencies in your existing app
  2. Update the Next.js template files in your existing app

Update application dependencies in your existing app

For your upgraded application to work correctly, you must update dependencies.

To update your dependencies:

  1. In your existing application's package.json file, update every @sitecore-content-sdk package to version 1.3.1.

  2. Install the dependencies with the following command:

    npm install

Update the Next.js template files in your existing app

After updating your dependencies, you must synchronize files in your existing application.

{ .notintoc }

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:

    if (!scConfig.api?.edge?.contextId) {
        return NextResponse.next();
      }
  • Replace it with the following:

    if (!scConfig.api?.edge?.contextId && !scConfig.api?.local?.apiHost) {
        return NextResponse.next();
      }
  • Pass local configuration to the redirects middleware:

    const redirects = new RedirectsMiddleware({
        /**
         * List of sites for site resolver to work with
         */
        sites,
        // this was present before:
        ...scConfig.api.edge,
        // this needs to be added:
        ...scConfig.api.local,
        ....
        ......

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.

...
  const personalize = new PersonalizeMiddleware({
    ...
    extractGeoDataCb: () => {
      return {
        city: 'Athens',
        country: 'Greece',
        region: 'Attica',
      };
    },
  });
...

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.

If you have suggestions for improving this article, let us know!