Upgrade JSS apps to JSS 22.10
Sitecore JSS version 22.10 primarily focuses on support for Angular 20. For Angular apps, you will need to update multiple dependencies. In general, the only other requirement is to update and install core JSS dependencies before re-testing your apps.
-
If you haven't already done so, upgrade your app to JSS 22.9.
-
Since this process also involves updating Angular to version 20, you'll need to refer to the official guide to complete the upgrade process for your apps.
-
Familiarize yourself with the JSS 22.10 changelog to ensure you understand the implications of upgrading.
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: