Upgrade JSS apps to JSS 22.4
Sitecore JavaScript Rendering SDK version 22.4 requires you to make some modifications to your apps.
Among other changes, the 22.4 release removes the Axios dependency from all core @sitecore-jss packages. The dependency was deeply ingrained in core JSS functionality, and its removal provides greater flexibility in how your JSS app can communicate with Sitecore, be that via native node fetch, some alternative fetch library, or one of the latest versions of Axios including current security fixes and features.
For a full summary of the changes relating to removal of Axios as the default fetcher, refer to the related changelog entry.
-
If you haven't already done so, upgrade your app to JSS 22.3.
-
Familiarize yourself with the JSS 22.4 release notes to ensure you understand the implications of upgrading.
This topic describes how to:
To update your JSS Next.js applications, follow the detailed upgrade guide from JSS 22.3 to 22.4 for JSS Next.js apps instead of this topic.
Update Angular apps
To update your Angular applications:
-
Replace all Axios import statements, where present, as follows:
Existing import
Replacement import
AxiosDataFetcherNativeDataFetcherAxiosResponseNativeDataFetcherResponseAxiosDataFetcherConfigNativeDataFetcherConfig -
Update your application's JSS package, and install dependencies.
Update React apps
To update your React applications:
-
Throughout your application (except
src/dataFetcher.js), replace all Axios import statements as follows:Existing import
Replacement import
AxiosDataFetcherNativeDataFetcherAxiosResponseNativeDataFetcherResponseAxiosDataFetcherConfigNativeDataFetcherConfig -
Update your application's JSS package, and install dependencies.
Additionally, if you want to switch your data fetch logic from Axios to the JSS native implementation (based on Node.js in-built logic), make the following changes:
-
In
server/server.js, do the following:-
Remove the Axios import statement:
RequestResponseimport axios from 'axios'; -
Locate the following export statement:
RequestResponseexport const setUpDefaultAgents = (httpAgent, httpsAgent) => { ... }; -
Delete the following lines from within that statement:
RequestResponseaxios.defaults.httpAgent = httpAgent; axios.defaults.httpsAgent = httpsAgent;
-
-
In
src/dataFetcher.js, do the following:-
Locate the
AxiosFetcherimport statement. -
Delete that statement and replace it with the following:
RequestResponseimport { NativeDataFetcher } from '@sitecore-jss/sitecore-jss-react'; -
Locate the
dataFetcherfunction. -
Delete that function and replace it with the following:
RequestResponseexport async function dataFetcher(url, data) { const fetcher = new NativeDataFetcher({ credentials: 'include' }); const response = await fetcher.fetch(url, { method: data ? 'POST' : 'GET', headers: { 'Content-Type': 'application/json', }, body: data ? JSON.stringify(data) : undefined, }); return response.data; }
-
-
In
package.json, do the following:-
Delete the following dependency:
RequestResponse"axios": "^1.2.3", -
Apply the change with
npm install.
-
Update Vue.js apps
To update your Vue.js applications:
-
Throughout your application (except
src/dataFetcher.js), replace all Axios import statements as follows:Existing import
Replacement import
AxiosDataFetcherNativeDataFetcherAxiosResponseNativeDataFetcherResponseAxiosDataFetcherConfigNativeDataFetcherConfig -
Update your application's JSS package, and install dependencies.
Additionally, if you want to switch your data fetch logic from Axios to the JSS native implementation (based on Node.js in-built logic), make the following changes:
-
In
server/server.js, do the following:-
Remove the Axios import statement:
RequestResponseimport axios from 'axios'; -
Locate the following export statement:
RequestResponseexport const setUpDefaultAgents = (httpAgent, httpsAgent) => { ... }; -
Delete the following lines from within that statement:
RequestResponseaxios.defaults.httpAgent = httpAgent; axios.defaults.httpsAgent = httpsAgent;
-
-
In
src/dataFetcher.js, do the following:-
Locate the
Axiosimport statement. -
Delete that statement and replace it with the following:
RequestResponseimport { NativeDataFetcher } from '@sitecore-jss/sitecore-jss-vue'; -
Locate the
dataFetcherfunction. -
Delete that function and replace it with the following:
RequestResponseexport async function dataFetcher(url, data) { const fetcher = new NativeDataFetcher({ credentials: 'include' }); const response = await fetcher.fetch(url, { method: data ? 'POST' : 'GET', headers: { 'Content-Type': 'application/json', }, body: data ? JSON.stringify(data) : undefined, }); return response.data; }
-
-
In
package.json, do the following:-
Delete the following dependency:
RequestResponse"axios": "^1.2.3", -
Apply the change with
npm install.
-
Update application dependencies
For your upgraded applications to work correctly, you must update dependencies.
To update your dependencies:
-
In your existing application's
package.jsonfile, update every@sitecore-jsspackage to version~22.4. -
Install the dependencies with the following command:
RequestResponsenpm install