Upgrade JSS 22.5 Next.js apps to version 22.6
22.6 introduces a new Form component that is imported as part of the sitecore-jss-react package. This is now used by JSS Next.js apps instead of the previous wrapper component when adding forms in the page builder. After upgrading your app, we strongly recommend manually modifying the layout details of your existing forms to use the new wrapper.
This topic covers most of the changes you must make to your existing JSS 22.5 applications to take advantage of the improvements in version 22.6. 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.
While upgrading, 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 22.5 application included in the XM Cloud starter foundation uses the following templates and add-ons:
Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.
-
nextjs -
nextjs-xmcloud -
nextjs-sxa -
nextjs-multisiteÂ
-
If you haven't already done so, upgrade your app to JSS 22.5.
-
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:
Update application dependencies in your existing 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, update every@sitecore-jsspackage to version~22.6.0. -
Install the dependencies with the following command:
Create a JSS 22.6 Next.js application
To simplify the upgrade process as much as possible, create a JSS 22.6 Next.js application with the XM Cloud add-on. You can then copy some files from this app into your existing app.
To create a JSS 22.6 Next.js application with the XM Cloud add-on included:
-
In a console, run the following command:
-
If prompted to install the
[email protected]package, answer y. -
Enter the folder path for the JSS 22.6 Next.js app. For example, enter
./jss226, 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 y to install the XM Cloud add-on.
-
Select other add-ons used by your existing application and press Enter.
The script then installs the application dependencies.
Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.
Update the Next.js template files in your existing app
This explains how to synchronize files in your existing application with corresponding files from your new JSS 22.6 app.
To update the Next.js template files:
-
Copy the
/scripts/generate-component-builder/plugins/form.tsfile from your template app to the same location in your existing app. -
In
/src/pages/[[...path]].tsxand every other file in your app that usesSitecoreContext, import theconfigand then modifySitecoreContextto include theapiparameter (which is used by the newFormcomponent to pass Edge endpoint settings), as shown in the following example:TipFor any such file that you haven't previously made modifications to, you can just replace that file with a copy of the one in your template app.
-
If you have not customized the
/src/pages/api/sitemap.tsfile, replace it with the version from your 22.6 template app. Otherwise, modify your file as follows:-
Delete all of the following lines:
-
Locate the following statement:
Replace it with all of the following:
-
Locate the following statement:
In it, rename
reqtHosttoreqHost. For example: -
In the
sitemaps.mapdeclaration, add theescapedUrlconstant as shown in the following example: -
In the sitemap return statement, locate the following:
Amend it to use the newly defined
escapedUrl. For example: -
Locate the following return statement:
Amend it to add the following XML declaration:
-
Update existing forms to use the new wrapper
After you upgrade your JSS app and redeploy it to SitecoreAI, new forms will use the updated wrapper component. However, we strongly recommend you update the presentation details of existing forms on your pages to use the new wrapper.
If you prefer, you can use the page builder to delete the existing forms and add them again. As new form components, they will automatically use the new wrapper component provided by JSS 22.6.
To update an existing form to use the new wrapper:
-
In Content Editor, select the page containing the existing form.
-
In the ribbon, click Presentation > Details.
-
In the details dialog, in the Final Layout tab, click the Edit link under the Headless Layout section.
-
In the Controls tab, select the BYOC Wrapper control you want update and click Change.
-
In the file browser dialog, select Feature > Headless Experience Accelerator > Forms > Form and click Select.
This closes the dialog, converting the selected control to use the new wrapper. The converted control will remain selected for the next step.
-
Click Edit.
-
In the Control Properties dialog, in the Parameters section, copy the
formIdfrom the Component Name parameter and paste it into the FormId field at the top of the dialog.ImportantOnly copy the value that follows
?formId=. -
Delete all items in the Parameters section.
-
Click OK.
-
Repeat this process for all other forms in your site.
-
When all of your forms have been updated to use the new wrapper, remove the following form registration from
/src/byoc/index.client.tsxin your JSS app and redeploy it:WarningRemoving this import will cause any forms that still use the old wrapper to stop working.
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.