Upgrade Content SDK 0.3.0 Next.js apps to version 1.0.0
This guide covers most of the changes you must make to your existing Content SDK 0.3.0 applications to take advantage of the new features and improvements in version 1.0.0.
This version of the Content SDK introduces code extraction support for the Design studio, refactors the SitecoreClient class, improves the site resolution logic, and more. Code extraction is the first prerequisite to enable Design studio's AI code generation.
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.8 app to a Content SDK 1.0 app, instead of this topic.
-
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:
Rename service classes
You don't need to follow this procedure if you're using the methods in SitecoreClient. If you are accessing the Content SDK services directly, you must make these changes:
-
Update references and imports for the following:
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
-
Remove all usages of the
DictionaryServiceinterface.
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.0.0. -
Install the dependencies with the following command:
RequestResponsenpm install
Create a template 1.0.0 Content SDK application for Next.js
To simplify the upgrade process as much as possible, create a Content SDK 1.0.0 Next.js application. You can then copy some files from this app into your existing app.
To create a 1.0.0 Content SDK Next.js application:
-
In a console, run the following command:
RequestResponsenpx [email protected] nextjs -
If prompted to install the
[email protected]package, answery. -
Enter the folder path for the new app. For example, enter
./content-sdk-100, to create the app folder in your current working directory. -
When prompted, choose the same prerendering method (SSG or SSR) as used in your existing Content SDK application.
The script then installs the application dependencies.
Update the Next.js template files in your existing app
After updating your dependencies, you must synchronize files in your existing application.
To update the Next.js template files:
-
In
src/lib/sitecore-client.ts:-
Delete the following import:
RequestResponseimport sites from '.sitecore/sites.json'; -
Remove the
sitesreference from theSitecoreClientdeclaration.
-
-
The
siteproperty of the typePagehas been renamed tositeName.In
src/Bootstrap.tsxandsrc/Pages/[[...path]].tsx, replace all occurrences ofprops.site?.namewithprops.siteName. -
The
getStaticPaths()method in theSitecoreClientnow has an additionalsitesparameter of typeSiteInfo.If you're pre-rendering your app using the SSG (Static Site Generation) method, in
src/Pages/[[...path]].tsx:-
Add the following import:
RequestResponseimport sites from '.sitecore/sites.json'; -
Find the following line:
RequestResponsepaths = await client.getPagePaths(context?.locales || []); -
Replace it with the following:
RequestResponsepaths = await client.getPagePaths( sites.map((site: SiteInfo) => site.name), context?.locales || [] );
-
-
SitecorePagePropsnow uses a standalonepagefield instead of merging all data into onepropsobject. Update your page-level functions (getStaticProps,getServerSideProps) to return the new structure.-
Find the following:
RequestResponseexport const getStaticProps = () => { ... const page = await client.getPage(...); return { props: { ...page } } } -
Replace it with the following:
RequestResponseexport const getStaticProps = () => { ... const page = await client.getPage(...); return { props: { page } } } -
Repeat the same steps for the
getServerSidePropspage-level method. -
Update all pages that consume
SitecorePagePropsto use the newprops.pagestructure instead of accessing merged properties directly.
-
-
The
Pagetype now includes amodefield of typePageModethat provides runtime context (editing, preview, Design studio, and so on). Update references to layout properties likepageState,pageEditing, andrenderingTypewith the newpage.modefield as shown in the following examples:If the rendering mode
isDesignLibrary:-
Find the following:
RequestResponseif (layoutData.sitecore.context.renderingType === RenderingType.Component) { ... } -
Replace it with the following:
RequestResponseif (page.mode.isDesignLibrary) { ... }
If the rendering mode
isNormal:-
Find the following:
RequestResponseif (pageState === LayoutServicePageState.Normal) { ... } -
Replace it with the following:
RequestResponseif (page.mode.isNormal) { ... }
Lastly, if the rendering mode
isEditingorisPreview:-
Find the following:
RequestResponseif (pageState === LayoutServicePageState.Edit || pageState === LayoutServicePageState.Preview) { ... } -
Replace it with the following:
RequestResponseif (page.mode.isEditing || page.mode.isPreview) { ... }
-
-
Update the
getErrorPages()method with the newgetErrorPage()method. This method returns a specific error page, for example,404.tsx,500.tsx.-
Find references to the
getErrorPages()method:RequestResponseexport const getStaticProps = () => { const resultErrorPages = await client.getErrorPages({ site, locale }); return { props: { layout: resultErrorPages?.notFoundPage?.rendered || null, } } } -
Replace it with the following for a 404 page:
RequestResponseexport const getStaticProps = () => { const page = await client.getErrorPage(ErrorPage.NotFound, { site, locale }); return { props: { page } } } -
Replace it with the following for a 500 page:
RequestResponseexport const getStaticProps = () => { const page = await client.getErrorPage(ErrorPage.InternalServerError, { site, locale }); return { props: { page } } }
-
-
Update the
SitecoreProvidercomponent to use the newpageprop instead of thelayoutprop.-
Find the following:
RequestResponse<SitecoreProvider layoutData={layoutData} ...>...</SitecoreProvider> -
Replace it with the following:
RequestResponse<SitecoreProvider page={page} ...>...</SitecoreProvider>
-
-
Remove the
SitecoreProviderPageContextinterface and any references to it. Use thePageinterface from theSitecoreClientinstead. -
Remove the
NextjsPageinterface and any references to it. All page-generating methods now return a singlePagetype. -
The
useSitecore()hook andwithSitecore()higher-order component have been updated for clarity and consistency. You can now access allPageentity information directly via the context.For the
useSitecore()hook:-
Find the following:
RequestResponseimport { useSitecore } from '@sitecore-content-sdk/nextjs' const { pageContext, updateContext } = useSitecore(); -
Replace it with the following:
RequestResponseimport { useSitecore } from '@sitecore-content-sdk/nextjs' const { page, updatePage } = useSitecore();
For the
withSitecore()higher-order component:-
Find the following:
RequestResponseimport { withSitecore } from '@sitecore-content-sdk/nextjs' function MyComponent({ pageContext, updateContext }) {...} export default withSitecore(MyComponent); -
Replace it with the following:
RequestResponseimport { withSitecore } from '@sitecore-content-sdk/nextjs' function MyComponent({ page, updatePage }) {...} export default withSitecore(MyComponent);
-
-
You must provide an additional
sitesparameter to theRobotsMiddlewareconstructor.In
src/pages/api/robots.ts:-
Add the following import:
RequestResponseimport sites from '.sitecore/sites.json'; -
Find the following line:
RequestResponseconst handler = new RobotsMiddleware(scClient).getHandler(); -
Replace it with the following:
RequestResponseconst handler = new RobotsMiddleware(scClient, sites).getHandler();
-
-
You must provide an additional
sitesparameter to theSitemapMiddlewareconstructor.In
src/pages/api/sitemap.ts:-
Add the following import:
RequestResponseimport sites from '.sitecore/sites.json'; -
Find the following line:
RequestResponseconst handler = new SitemapMiddleware(scClient).getHandler(); -
Replace it with the following:
RequestResponseconst handler = new SitemapMiddleware(scClient, sites).getHandler();
-
-
In
sitecore.cli.config.ts:-
Find the following import:
RequestResponseimport { generateSites, generateMetadata } from '@sitecore-content-sdk/nextjs/tools'; -
Replace it with the following:
RequestResponseimport { generateSites, generateMetadata, extractFiles } from '@sitecore-content-sdk/nextjs/tools'; -
Inside the
defineCliConfigblock, aftergenerateSites({...}), add the following:RequestResponseexport default defineCliConfig({ build: { commands: [ generateMetadata(), generateSites({ scConfig: config, }), extractFiles({ scConfig: config, }), ], }, ... });ImportantCode extraction is enabled by default. If you want to opt out of it, in
sitecore.config.ts, add the following parameter insidedefineConfig({...})block:RequestResponseexport default defineConfig({ ... disableCodeGeneration: true, ... });
-
Upgrade Content SDK 1.0.0 Next.js apps to version 1.0.1
Apps based on Content SDK 1.0.0 and earlier had a middleware-related bug that was fixed in Content SDK 1.0.1. When upgrading to 1.0.1, you must, in addition to updating dependencies in the package.json file, do the following:
-
In the console, run the following command to create a template app:
RequestResponsenpx [email protected] nextjs -
If you have not customized the
src/middleware.tsfile, replace it with the version in your template app. -
If you have customized the
src/middleware.tsfile, make the following changes:-
Find the following import statement:
RequestResponseimport { type NextRequest, type NextFetchEvent } from 'next/server'; -
Update it with the following:
RequestResponseimport { type NextRequest, type NextFetchEvent, NextResponse } from 'next/server'; -
At the beginning of the
middleware()function, add the following:RequestResponseif (!scConfig.api?.edge?.contextId) { return NextResponse.next(); }This allows the middleware logic to be skipped when running locally or without Edge context.
-
Shift the creation of
multisite,redirects, andpersonalizemiddlewares after the aboveifstatement. This avoids running constructors when they’re not needed.
-
-
Ensure you've updated every
@sitecore-content-sdkpackage to version 1.0.1 in thepackage.jsonfile. -
Install the dependencies with the following command:
RequestResponsenpm install
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.