Upgrade JSS 22.9 Next.js apps to Content SDK 1.1
Content SDK is a major upgrade from previous versions of Sitecore JavaScript Services SDK (JSS) for SitecoreAI. It reduces the size and complexity of starter applications, removing redundant functionality not needed for SitecoreAI implementations. As a result, Content SDK applications are easier to understand and maintain than apps built with JSS.
This guide summarizes the differences between Content SDK and JSS. It also explains how to upgrade your existing JSS apps for SitecoreAI.
This guide also covers most of the changes you must make to your existing JSS 22.9 applications to take advantage of the new features in Content SDK 1.1. However, 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 JSS application. You can find them in your package.json file. For example, a JSS 22.9 application based on the XM Cloud starter kit uses the following templates and add-ons, so this guide assumes your app includes all of them:
-
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.
This upgrade guide has no additional steps compared to the one for migrating JSS 22.8.0 to Content SDK 1.0.0. The only breaking change for JSS 22.9.0, in comparison to JSS 22.8.0, is the updated third-party dependencies. Due to this, JSS 22.9.0 Next.js apps have two dependencies ("sharp": "0.34.3", "cross-env": "~10.0.0") with updated versions compared to the latest Content SDK version. This doesn't conflict with the upgrade. Content SDK 1.1.0 includes the following optional improvements that you can take advantage of:
-
If you haven't already done so, upgrade your JSS app to JSS 22.9.
-
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 covers the following subjects:
What's new in Content SDK?
Here's a short overview of the changes introduced in Content SDK:
-
Includes out-of-the-box support for the Design studio that serves as a centralized interface to help teams visualize and test components across their organization.
-
Three brand new site templates in addition to the classic Skatepark template.
-
A new file,
sitecore.config.ts, serves as the central point for configuring your application's build and run time. -
Another new file,
sitecore.cli.config.ts, used to configure CLI commands for Content SDK that enable it to replace build-time and dev tools scripts. -
The new Sitecore Client Data Fetching API, represented by the
SitecoreClientclass, unifies all data fetching logic and replaces the previous data fetching plugins. -
A new utility named
defineMiddleware, simplifies middleware composition and provides better visibility by removing the need for middleware plugins. -
Supports the enhanced SitecoreAI page builder in place of the Sitecore Experience Editor.
Removal of Experience Editor
Unlike JSS for SitecoreAI, Content SDK doesn't support the Experience Editor tool and, for that reason, doesn't include the chromes-based integration required by Experience Editor. Instead, all visual editing with Content SDK is done with the SitecoreAI page builder using metadata integration.
When migrating to Content SDK, Content Editor Preview is not supported. Content SDK removes all Experience Editor–based rendering and preview capabilities, including preview functionality accessed from the Content Editor. Preview and editing are supported only through Page Builder.
The following packages have been updated for Content SDK in relation to removal of Experience Editor support. Familiarize yourself with the updates and note any breaking changes this might introduce to your application so you can address them during the upgrade process:
sitecore-jss
-
Removed the
HtmlElementRenderinginterface, meaning onlyComponentRenderinginterface is now used. -
field.editableis no longer available. Instead,field.metadatais used for edit mode. -
Removed the
EditMode.Chromesenum value. -
LayoutServiceContextno longer exposeseditMode. -
Renamed the
HorizonEditorutility class toPagesEditor. -
Removed the
ExperienceEditorutility class. -
Removed the
handleEditorAnchorsutility. -
Removed all
EditFrameutilities, including:-
DefaultEditFrameButton -
DefaultEditFrameButtons -
DefaultEditFrameButtonIds -
EditFrameDataSource -
ChromeCommand -
FieldEditButton -
WebEditButton -
EditButtonTypes -
mapButtonToCommand
-
Update application dependencies in your existing JSS 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:-
Replace
"@sitecore-jss/sitecore-jss-nextjs"with"@sitecore-content-sdk/nextjs", and make the same change to all references to the old dependency throughout your application. -
Delete the
"@sitecore-jss/sitecore-jss-cli"dependency. -
Delete the
"@sitecore-jss/sitecore-jss-dev-tools"dependency.
-
-
Install the dependencies with the following command:
RequestResponsenpm install
Create a template Content SDK 1.1 application
To simplify the upgrade process as much as possible, create a Content SDK application. You can then copy some files from this template app into your existing app.
To create a Next.js Content SDK application:
-
In a console, run the following command:
RequestResponsenpx create-content-sdk-app@latest nextjs -
If prompted to install the
create-content-sdk-app@latestpackage, answery. -
Enter the folder path for the new app. For example, enter
./content-sdk-template, to create the named subfolder in your current working directory. -
When prompted, choose the same prerendering method (SSG or SSR) as used in your existing JSS application.
The script then installs the application dependencies.
Update the Next.js template files in your existing app
The following sections explain how to synchronize files in your existing JSS application with corresponding files from your Content SDK template app.
Update configurations and environment variables
This sections updates your existing app's configurations and environment variables to match the new Content SDK app.
To update your JSS app's configurations and environment variables:
-
Copy the
sitecore.config.tsfile from your template app into your existing app. -
Throughout your app, replace all imports of config from temp/config and use the new sitecore.config.ts file instead:
-
Locate all instances of the following:
RequestResponseimport config from 'temp/config' -
Replace these with the following:
RequestResponseimport scConfig from 'sitecore.config'
-
-
A new
pageparameter has been added toSitecoreContext. To support this change, update theSitecoreContextAPI configuration in the following files:-
[[...path]].tsx -
500.tsx -
404.tsx
In each file, set the
apiparameter to usescConfig.apiand thepageparameter to usepageas shown in the following example:RequestResponseimport scConfig from 'sitecore.config'; ... const page = client.getPage(...); <SitecoreContext ... api={scConfig.api} page={page} > -
-
Rename the following environment variables within your JSS app:
Old (JSS)
New (Content SDK)
SITECORE_API_KEYNEXT_PUBLIC_SITECORE_API_KEYSITECORE_API_HOSTNEXT_PUBLIC_SITECORE_API_HOSTSITECORE_SITE_NAMENEXT_PUBLIC_DEFAULT_SITE_NAMEDEFAULT_LANGUAGENEXT_PUBLIC_DEFAULT_LANGUAGEJSS_EDITING_SECRETSITECORE_EDITING_SECRET -
If your existing app uses
SITECORE_EDGE_URLfor dev or staging, rename itNEXT_PUBLIC_SITECORE_EDGE_URL.NoteSITECORE_EDGE_CONTEXT_IDdoes not need to be renamed. -
If your existing solution requires client-side requests to the Edge endpoint, create a new environment variable named
NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_IDand give it the same value asSITECORE_EDGE_CONTEXT_ID.NoteDoing this will expose your context ID secret on the client.
-
If your existing app uses
DISABLE_SSG_FETCHrename it toGENERATE_STATIC_PATHS.NoteThe meaning and value of this variable has been logically inverted. If your existing solution uses this variable in the code, you must adjust them accordingly.
ImportantSee The Sitecore configuration file for more information on the configuration properties and their corresponding environment variables.
-
Copy the
src/lib/sitecore-client.tsfile from your template app into the same folder in your existing JSS app. -
Refactor all Next.js middleware in your existing app to use the new
defineMiddlewareutility:-
For refactoring standard middleware, use
src/middleware.tsin your template app as a reference. -
For information and instructions about refactoring custom middleware to use defineMiddleware, refer to Integrate custom middleware.
-
-
In
[[..path]].tsx,404.tsx,500.tsx, andLayout.tsx, remove all usages ofheadLinks.
Refactor components and interfaces
This section refactors all components, interfaces, and other files to match the new Content SDK app's structure.
To refactor your files:
-
Copy the new component
src/components/SitecoreStyles.tsxfrom your template app into the same folder in your existing JSS app. -
In
Layout.tsx, importSitecoreStylesand place the component afterScripts, as shown in the following example:RequestResponseimport SitecoreStyles from 'src/components/SitecoreStyles'; ... <Scripts /> <SitecoreStyles layoutData={layoutData} /> ... -
Throughout your JSS app, remove all usages of the
publicUrlproperty of the now-obsoleteconfig. -
Update references and imports for the following component, interfaces, higher-order components, and properties:
Old
New
Type
SitecoreContextSitecoreProvidercomponent
SitecoreContextPropsSitecoreProviderPropsinterface
SitecoreContextStateSitecoreProviderStateinterface
SitecoreContextReactContextSitecoreProviderReactContextinterface
WithSitecoreContextOptionsWithSitecoreOptionsinterface
WithSitecoreContextPropsWithSitecorePropsinterface
WithSitecoreContextHocPropsWithSitecoreHocPropsinterface
useSitecoreContext()useSitecore()higher-order component
withSitecoreContext()withSitecore()higher-order component
contextpageproperty
updateSitecoreContextupdatePageproperty
sitecoreContextpageproperty
-
Remove the
SitecoreContextinterface and update any references with the newPageinterface from theSitecoreClient. -
Update references to the
getServerSidePropsandgetStaticPropsmethods togetComponentServerPropswithout changing the existing method signature.If your component contains code that's executed based on static or server side Next.js context, import the
isServerSidePropsContexthelper method and implement it based on the following example:RequestResponseimport { isServerSidePropsContext } from '@sitecore-content-sdk/nextjs/utils'; ... export const getComponentServerProps: GetComponentServerProps = async ( rendering, layoutData, context ) => { if (isServerSidePropsContext(context)) { // function implementation } }; -
Update references and imports for the following services if you use them directly or substitute them by using the methods in the
SitecoreClientclass:Old
New
Type
RestComponentLayoutServiceComponentLayoutServiceservice class
RestComponentLayoutServiceConfigComponentLayoutServiceConfiginterface
GraphQLEditingServiceEditingServiceservice class
GraphQLEditingServiceConfigEditingServiceConfiginterface
GraphQLDictionaryServiceDictionaryServiceservice class
GraphQLDictionaryServiceConfigDictionaryServiceConfiginterface
GraphQLLayoutServiceLayoutServiceservice class
GraphQLLayoutServiceConfigLayoutServiceConfiginterface
GraphQLPersonalizeServicePersonalizeServiceservice class
GraphQLPersonalizeServiceConfigPersonalizeServiceConfigtype
GraphQLErrorPagesServiceErrorPagesServiceservice class
GraphQLErrorPagesServiceConfigErrorPagesServiceConfiginterface
GraphQLRedirectsServiceRedirectsServiceservice class
GraphQLRedirectsServiceConfigRedirectsServiceConfigtype
GraphQLRobotsServiceRobotsServiceservice class
GraphQLRobotsServiceConfigRobotsServiceConfigtype
GraphQLSiteInfoServiceSiteInfoServiceservice class
GraphQLSiteInfoServiceConfigSiteInfoServiceConfigtype
GraphQLSitemapXmlServiceSitemapXmlServiceservice class
GraphQLSitemapXmlServiceConfigSitemapXmlServiceConfigtype
GraphQLSitePathServiceSitePathServiceservice class
GraphQLSitePathServiceConfigSitePathServiceConfiginterface
-
Delete the
DictionaryServiceinterface and remove any references to it. -
Update the
src/lib/component-props/index.tsfile in your existing app using the one from your template app. -
Throughout your app, wherever is used, do the following:
-
Update imports of
componentBuilderto usecomponentsinstead, as shown in the following example:RequestResponseimport components from '.sitecore/component-map'; -
Within
<SitecoreProvider>, replace usages of thecomponentFactoryprop to usecomponentsinstead, as shown in the following example:RequestResponse<SitecoreProvider componentMap={components} ...>
-
-
Update any remaining imports of
temp/componentBuilderto use.sitecore/component-mapinstead.
Finalize build process and cleanup
This section contains changes related to the build process and finalizes the upgrade process.
To edit the build process and clean up your project:
-
In your
package.jsonfile, do the following:-
Remove the
start:watch-componentsandbootstrapscripts and all mentions of these two scripts from the remaining scripts. -
Remove the
jssscript. -
Remove the
install-pre-push-hookscript -
Remove the
scaffoldscript -
Update the
buildscript with the following:RequestResponse"build": "cross-env NODE_ENV=production npm-run-all --serial sitecore-tools:generate-map sitecore-tools:build next:build", -
Update the
lintscript by removing linting for the script folder:RequestResponse"lint": "eslint ./src/**/*.tsx ./src/**/*.ts", -
(Optional) Add the following scripts, for dynamically generating the component map and building the Content SDK app:
RequestResponse"sitecore-tools:generate-map": "sitecore-tools project component generate-map", "sitecore-tools:generate-map:watch": "sitecore-tools project component generate-map --watch", "sitecore-tools:build": "sitecore-tools project build", -
Rename the
start:connectedscript todevand replace it with the following:RequestResponse"dev": "cross-env NODE_ENV=development npm-run-all --serial sitecore-tools:build --parallel next:dev sitecore-tools:generate-map:watch", -
Rename the
start:productiontostartand replace it with the following:RequestResponse"start": "cross-env-shell NODE_ENV=production npm-run-all --serial build next:start"
-
-
Copy the
sitecore.cli.config.tsfile from your template app into your existing app. -
Because the build time artifacts
metadata.jsonandsites.json(the second of which used to be calledconfig.sites) are now created under the .sitecore temp folder at the root of the app, you need to update the imports of these artifacts accordingly throughout your application, making sure to rename instances of config.sites to sites.json. -
Content SDK introduces the
sitecore-tools:buildcommand that, similar tonext:build, is used to generate build-time artifacts required for your app to function. Make sure this script is executed before you start your application. -
In your existing app's next.config.js file, make the following changes:
-
Migrate all Next config plugin logic (previously located in the
src/lib/next-configfolder) and all associated custom settings into thenext.config.jsfile, then delete the now-redundant files from the lib folder. -
Replace the existing
defaultLocaleproperty with the following:RequestResponsedefaultLocale: process.env.DEFAULT_LANGUAGE || process.env.NEXT_PUBLIC_DEFAULT_LANGUAGE || 'en',
-
-
The
Pagetype now includes amodefield of typePageMode, that provides runtime context (editing, preview, Design studio, etc). Update references to layout context properties likepageState,pageEditing, andrenderingTypewith the newpage.modefield as shown in the examples below:-
If the rendering mode
isDesignLibrary, find the following:RequestResponseif (layoutData.sitecore.context.renderingType === RenderingType.Component) { ... }Replace with the following:
RequestResponseif (page.mode.isDesignLibrary) { ... } -
If the rendering mode
isNormal, find the following:RequestResponseif (layoutData.sitecore.context.pageState === LayoutServicePageState.Normal) { ... }Replace with the following:
RequestResponseif (page.mode.isNormal) { ... } -
Similarly, if the rendering mode
isEditingorisPreview, update them to use the following:RequestResponseif (page.mode.isEditing || page.mode.isPreview) { ... }
-
-
If you've customized your existing JSS app, refer to the obsolete JSS functionality section and make all changes necessary to refactor your code and then remove the obsolete parts of your app, such as:
-
Using appropriate data fetching functionality provided by
scClient. Use your Sitecore Content SDK template app as a reference. -
Replacing imports of
SitecorePagePropsto use"@sitecore-content-sdk/nextjs"instead of"lib/page-props". For example:RequestResponseimport { SitecorePageProps } from "@sitecore-content-sdk/nextjs"
NoteIn their unaltered forms, the following files provided by the Next.js starter kit will need to be updated:
-
src/pages/api/robots.ts -
src/pages/api/sitemap.ts -
src/pages/[[...path]].tsx -
src/pages/404.tsx -
src/pages/500.tsx -
src/Bootstrap.tsx -
src/_app.tsx
-
Obsolete and revised functionality in your existing app
Some parts of existing JSS apps are either revised or no longer required in Content SDK apps, meaning they can be removed. However, if your app contains custom code that uses any of this obsolete functionality, or if you have any customizations in the affected files or folders, you will need to modify your app accordingly.
After you've finished refactoring, you can remove any obsolete parts to reduce the overall size of your app:
-
The
scripts/configfolder, which contains the plugins that JSS used to generate the runtime config under thesrc/tempfolder. All of this has been replaced bysitecore.config.ts, and a config file is no longer generated at build time. -
The
scripts/scaffold-componentfolder, which contains the script for thejss scaffold componentcommand. This is now replaced by a new CLI commandsitecore-tools scaffold. -
The
scripts/templatesfolder, which contains the templates JSS used for scaffolding components. This is now replaced by the new CLI configurationsitecore.cli.config.ts. -
The
scripts/generate-config.tsscript that generated the runtime config file. This is now replaced bysitecore.config.ts. -
The
scripts/generate-metadata.tsscript that generated themetadata.jsonrequired for editing integration. This is now replaced by thegenerateMetadata()function insitecore.cli.config.tswhich is executed by the new CLI commandsitecore-tools build. -
The
scripts/generate-component-builderscript, which generated the component builder that manages registration of components. This is now replaced bycomponent-map. -
The
scripts/generate-plugins.tsscript is no longer required. -
The
scripts/bootstrap.tsscript that handled running build-time scripts. This is now replaced by the CLI andsitecore.cli.config.ts. -
The
scripts/utils.tsfile that stores utilities for scripts is no longer used. -
If you've already disabled graphQL code generation for your JSS app, the
/scriptsfolder and thetsconfig.scripts.jsonfile are no longer needed. -
The
src/lib/page-props-factoryplugins that created contextualSitecorePagePropsobjects. This is now replaced by the functions ofSitecoreClient. -
src/lib/site-resolver, which is now replaced byscClient.resolveSite(). -
src/lib/extract-path, which must now be imported from@sitecore-content-sdk/nextjs/utils. -
src/lib/sitemap-fetcher, which is now replacedscClient.getSiteMap(). -
src/lib/middleware. All middleware is now defined inmiddleware.tsxand executed using thedefineMiddlewareutility function. -
src/lib/next-config. All Next.js config settings are now consolidated innextj.config.js. -
The
src/lib/config.tstype, which defined runtime config, is now replaced bysitecore.config.ts. The following services are now incorporated intoSitecoreClient. If your solution includes customization of any of these services, you need to extendSitecoreClientand override any services that need to be extended:-
src/lib/graphql-client-factory -
src/lib/dictionary-service-factory.ts -
src/lib/layout-service-factory.ts -
src/lib/graphql-editing-service.ts
-
-
The
src/lib/page-props.tstype that definedSitecorePagePropshas been moved to the base@sitecore-content-sdk/nextjspackage, and must now be imported from there instead.
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.