Upgrade JSS 22.9 Angular apps to version 22.10
This topic covers most of the changes you must make to your existing JSS 22.9 Angular applications to benefit from the latest improvements in version 22.10. However, because this process also involves updating Angular to version 20, you'll need to refer to the relevant guides to complete the upgrade process for your apps.
While upgrading, consider the JSS templates and add-ons you used when creating your Angular application. You can find them in your package.json file. For example, a JSS 22.9 application included in the XM Cloud Angular starter foundation uses the following templates and add-ons:
-
angular -
angular-xmcloud
Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.
-
If you haven't already done so, upgrade your 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 describes how to:
Update the Angular template files in your existing app
This version of JSS upgrades Angular to version 20 that switches your components to be standalone by default. You should refer to the official Angular guide to complete the upgrade process for your apps and familiarize with standalone components and relevant migrations.
To upgrade your JSS app to Angular 20:
-
In your existing application's
package.jsonfile, update the following dependencies to the specified versions: -
In the
src/appfolder:-
Add a new file called
ViewBag.tswith the following content: -
Add a new file called
injection-tokens.tswith the following content:
-
-
Use the
inject()method to to replace field initializations in the constructor for all instances of class fields.For example, in
src/app/jss-context.service.ts, the original constructor is as shown:To use the
inject()method here:-
Import the method from the
angularpackage: -
Use the
inject()function to remove the field initializations from the constructor as shown: -
Repeat the above steps for the rest of the app logic, like components, services (for example,
src/app/jss-context.server.ts,jss-graphql.service.tsfiles), etc.
-
-
For all the modules using
declarations, move the entries intoimportsinstead.-
For example, in
src/app/routing/routing.module.ts, the existing declarations are as shown:Move the entries to the imports as shown:
-
Similarly, in
src/app/routing/scripts/scripts.module.ts, move theScriptsComponentandVisitorIdentificationComponent(if present) fromdeclarationstoimportsas shown: -
Perform the same step for
StyleguideSpecimenComponentinsrc/app/components/app-components.shared.module.tsand any other component modules you wish to have as standalone.
-
-
The
app.component.tsfile will remain non-standalone for simplicity and continued support of SSR proxy. Make the following changes to theapp.component.tsfile:-
Mark the component with
standalone: falseas shown -
Implement the
OnInitinterface -
Add the
ngInit()method: -
Remove the original constructor and initialize fields with the
inject()method: -
Making the app-component non-standalone allows you to keep the
declarationssection inapp.module.tsas is, butapp.server.module.tsshould be modified to use an injection token.Find the existing string token:
Replace it with an imported token object:
-
-
Use injection tokens in the
server.bundle.tsfile:-
Import the injection tokens:
-
Add the injection tokens to the
extraProviderssection of therenderModulefunction as shown:
-
-
In the app's
src/app/routing/layout/layout.component.tsfile:-
Ensure the following imports are present:
-
Add an
importssection for theComponentdirective: -
Use the
inject()function to remove the field initializations from the constructor as shown:
-
-
In the app's
jss-graphql.module.tsfile:-
Import
injectfrom theangularpackage, replaceApolloModulewithprovideApollofrom theapollo-angularpackage, and import theAPOLLO_CACHEinjection token as shown: -
Add the following two new function outside of
GraphQLModule: -
Remove
ApolloModulefromimportsand expand theproviderssection as shown: -
Modify the module constructor as shown:
-
Initialize two module fields with the
inject()function: -
Replace the
createApolloClientmethod with the following:
-
-
In the app's
src/app/jss-graphql.service.tsfile, use theinject()function to remove the field initializations from the constructor as shown: -
You can optionally replace all usages of
ngIfandngForin your components with the new@ifand@fordirectives. See the updated Angular sample for examples on how to do it. To continue usingNgIfandNgForwith your standalone components, importngIfandngForfrom the@angular/core packageand add them to your component’simportssection:
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.10.0. -
Install the dependencies with the following command:
Update the Node XM Cloud proxy app
To update your Node XM Cloud proxy app:
Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.
-
In your existing application's
package.jsonfile, update every@sitecore-jsspackage to version~22.10.0. -
Install the dependencies with the following command:
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.