Skip to content

Commit 8e5111f

Browse files
authored
Upgrade Nextjs to v16.2 (#2193)
* Upgrade Nextjs to v16.2 * Regenerate yarn.lock * Update CHANGELOG.md * Fix scaffold apps issues * Regenerate yarn.lock * Restore previous files / change linting rules for samples * Restore tighter linting rules and adjust sxa components
1 parent 8e7591f commit 8e5111f

9 files changed

Lines changed: 721 additions & 749 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Our versioning strategy is as follows:
1515

1616
### 🎉 New Features & Improvements
1717

18+
* `[Next.js]` `[sitecore-jss-nextjs]` Upgrade Next.js to 16.2 ([#2193](https://github.com/Sitecore/jss/pull/2193))
1819
* `[sitecore-jss]` Add Unified UI origin to allowed origins ([#2192](https://github.com/Sitecore/jss/pull/2192))
1920

2021
## 22.12.0

packages/create-sitecore-jss/src/templates/nextjs-sxa/src/components/Image.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,17 @@ export const Default = (props: ImageProps): JSX.Element => {
7272
const { sitecoreContext } = useSitecoreContext();
7373

7474
if (props.fields) {
75-
const Image = () => <JssImage field={props.fields.Image} />;
7675
const id = props.params.RenderingIdentifier;
76+
const imageField = props.fields.Image;
7777

7878
return (
7979
<div className={`component image ${props?.params?.styles}`} id={id ? id : undefined}>
8080
<div className="component-content">
8181
{sitecoreContext.pageState === 'edit' || !props.fields.TargetUrl?.value?.href ? (
82-
<Image />
82+
<JssImage field={imageField} />
8383
) : (
8484
<JssLink field={props.fields.TargetUrl}>
85-
<Image />
85+
<JssImage field={imageField} />
8686
</JssLink>
8787
)}
8888
<Text

packages/create-sitecore-jss/src/templates/nextjs-sxa/src/components/Title.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,28 +64,30 @@ export const Default = (props: TitleProps): JSX.Element => {
6464
const datasource = props.fields?.data?.datasource || props.fields?.data?.contextItem;
6565
const { sitecoreContext } = useSitecoreContext();
6666
const text: TextField = datasource?.field?.jsonValue || {};
67-
const link: LinkField = {
67+
const linkValue: NonNullable<LinkField['value']> = {
6868
value: {
6969
href: datasource?.url?.path,
7070
title: datasource?.field?.jsonValue?.value,
7171
},
72-
};
72+
}.value;
73+
74+
const displayText: TextField =
75+
sitecoreContext.pageState !== 'normal' && !text?.value ? { ...text, value: 'Title field' } : text;
76+
7377
if (sitecoreContext.pageState !== 'normal') {
74-
link.value.querystring = `sc_site=${datasource?.url?.siteName}`;
75-
if (!text?.value) {
76-
text.value = 'Title field';
77-
link.value.href = '#';
78-
}
78+
linkValue.querystring = `sc_site=${datasource?.url?.siteName}`;
79+
if (!displayText?.value) linkValue.href = '#';
7980
}
81+
const link: LinkField = { value: linkValue };
8082

8183
return (
8284
<ComponentContent styles={props?.params?.styles} id={props?.params?.RenderingIdentifier}>
8385
<>
8486
{sitecoreContext.pageEditing ? (
85-
<Text field={text} />
87+
<Text field={displayText} />
8688
) : (
8789
<Link field={link}>
88-
<Text field={text} />
90+
<Text field={displayText} />
8991
</Link>
9092
)}
9193
</>
Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
11
/**
22
* ESLint flat config for JSS Next.js apps.
3-
* Replaces legacy .eslintrc so scaffolded apps use ESLint 9 flat config.
3+
* Loads eslint-config-next's published flat bundle (no FlatCompat) to avoid circular
4+
* plugin graphs when ESLint 9 validates legacy eslintrc through @eslint/eslintrc.
45
*/
5-
import { dirname } from 'path';
6-
import { fileURLToPath } from 'url';
7-
import { FlatCompat } from '@eslint/eslintrc';
6+
import { createRequire } from 'module';
87
import eslintConfigPrettier from 'eslint-config-prettier';
8+
import prettierPlugin from 'eslint-plugin-prettier';
99

10-
const __filename = fileURLToPath(import.meta.url);
11-
const __dirname = dirname(__filename);
12-
const compat = new FlatCompat({ baseDirectory: __dirname });
13-
14-
const nextAndPrettierLegacy = compat.extends(
15-
'next',
16-
'next/core-web-vitals',
17-
'plugin:@typescript-eslint/recommended',
18-
'prettier',
19-
'plugin:yaml/recommended',
20-
'plugin:prettier/recommended'
21-
);
10+
const require = createRequire(import.meta.url);
11+
const coreWebVitals = require('eslint-config-next/core-web-vitals');
2212

2313
export default [
24-
{ ignores: ['.generated/**', '**/*.d.ts', '**/*.js', 'node_modules', '.next', 'out'] },
25-
...nextAndPrettierLegacy,
14+
{
15+
ignores: ['.generated/**', '**/*.d.ts', '**/*.js', 'node_modules', '.next', 'out'],
16+
},
17+
...coreWebVitals,
2618
{
2719
files: ['**/*.ts', '**/*.tsx'],
2820
rules: {
@@ -37,5 +29,11 @@ export default [
3729
'jsx-quotes': ['error', 'prefer-double'],
3830
},
3931
},
32+
{
33+
plugins: { prettier: prettierPlugin },
34+
rules: {
35+
'prettier/prettier': 'warn',
36+
},
37+
},
4038
eslintConfigPrettier,
4139
];
Lines changed: 74 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,74 @@
1-
{
2-
"name": "<%- appName %>",
3-
"description": "Application utilizing Sitecore JavaScript Services and Next.js",
4-
"version": "0.1.0",
5-
"private": true,
6-
"config": {
7-
"appName": "<%- appName %>",
8-
"rootPlaceholders": [
9-
"<%- helper.getAppPrefix(appPrefix, appName) %>jss-main"
10-
],
11-
"sitecoreConfigPath": "/App_Config/Include/zzz",
12-
"graphQLEndpointPath": "/sitecore/api/graph/edge",
13-
"language": "en"
14-
},
15-
"author": {
16-
"name": "Sitecore Corporation",
17-
"url": "https://jss.sitecore.com"
18-
},
19-
"repository": {
20-
"type": "git",
21-
"url": "git+https://github.com/sitecore/jss.git"
22-
},
23-
"bugs": {
24-
"url": "https://github.com/sitecore/jss/issues"
25-
},
26-
"license": "Apache-2.0",
27-
"dependencies": {
28-
"@sitecore-jss/sitecore-jss-nextjs": "<%- version %>",
29-
"next": "^16.1.0",
30-
"next-localization": "^0.12.0",
31-
"react": "^19.1.0",
32-
"react-dom": "^19.1.0",
33-
"sharp": "0.34.3"
34-
},
35-
"devDependencies": {
36-
"@sitecore-jss/sitecore-jss-cli": "<%- version %>",
37-
"@sitecore-jss/sitecore-jss-dev-tools": "<%- version %>",
38-
"@types/node": "^24.10.4",
39-
"@types/react": "^19.1.7",
40-
"@types/react-dom": "^19.1.7",
41-
"@typescript-eslint/eslint-plugin": "^8.14.0",
42-
"@typescript-eslint/parser": "^8.14.0",
43-
"chalk": "~4.1.2",
44-
"chokidar": "~4.0.3",
45-
"constant-case": "^3.0.4",
46-
"cross-env": "~10.0.0",
47-
"dotenv-flow": "^4.1.0",
48-
"@eslint/eslintrc": "^3.2.0",
49-
"eslint": "^9.15.0",
50-
"eslint-config-next": "^15.0.0",
51-
"eslint-config-prettier": "^8.6.0",
52-
"eslint-plugin-prettier": "^4.2.1",
53-
"eslint-plugin-react": "^7.37.5",
54-
"eslint-plugin-yaml": "^0.5.0",
55-
"npm-run-all": "~4.1.5",
56-
"prettier": "^2.8.3",
57-
"ts-node": "^10.9.1",
58-
"tsconfig-paths": "^4.1.2",
59-
"typescript": "~5.4.0"
60-
},
61-
"scripts": {
62-
"jss": "jss",
63-
"lint": "eslint ./src/**/*.tsx ./src/**/*.ts ./scripts/**/*.ts",
64-
"bootstrap": "ts-node --require dotenv-flow/config --project tsconfig.scripts.json scripts/bootstrap.ts",
65-
"build": "cross-env NODE_ENV=production npm-run-all --serial bootstrap next:build",
66-
"next:build": "next build --webpack",
67-
"next:dev": "cross-env NODE_OPTIONS='--inspect' next dev --webpack",
68-
"next:start": "next start",
69-
"scaffold": "ts-node --project tsconfig.scripts.json scripts/scaffold-component/index.ts",
70-
"start:connected": "cross-env NODE_ENV=development npm-run-all --serial bootstrap --parallel next:dev start:watch-components",
71-
"start:production": "cross-env-shell NODE_ENV=production npm-run-all --serial bootstrap next:build next:start",
72-
"start:watch-components": "ts-node --project tsconfig.scripts.json scripts/generate-component-builder/index.ts --watch",
73-
"install-pre-push-hook": "ts-node --project tsconfig.scripts.json ./scripts/install-pre-push-hook.ts"
74-
}
75-
}
1+
{
2+
"name": "<%- appName %>",
3+
"description": "Application utilizing Sitecore JavaScript Services and Next.js",
4+
"version": "0.1.0",
5+
"private": true,
6+
"config": {
7+
"appName": "<%- appName %>",
8+
"rootPlaceholders": [
9+
"<%- helper.getAppPrefix(appPrefix, appName) %>jss-main"
10+
],
11+
"sitecoreConfigPath": "/App_Config/Include/zzz",
12+
"graphQLEndpointPath": "/sitecore/api/graph/edge",
13+
"language": "en"
14+
},
15+
"author": {
16+
"name": "Sitecore Corporation",
17+
"url": "https://jss.sitecore.com"
18+
},
19+
"repository": {
20+
"type": "git",
21+
"url": "git+https://github.com/sitecore/jss.git"
22+
},
23+
"bugs": {
24+
"url": "https://github.com/sitecore/jss/issues"
25+
},
26+
"license": "Apache-2.0",
27+
"dependencies": {
28+
"@sitecore-jss/sitecore-jss-nextjs": "<%- version %>",
29+
"next": "^16.2.0",
30+
"next-localization": "^0.12.0",
31+
"react": "^19.1.0",
32+
"react-dom": "^19.1.0",
33+
"sharp": "0.34.3"
34+
},
35+
"devDependencies": {
36+
"@sitecore-jss/sitecore-jss-cli": "<%- version %>",
37+
"@sitecore-jss/sitecore-jss-dev-tools": "<%- version %>",
38+
"@types/node": "^24.10.4",
39+
"@types/react": "^19.1.7",
40+
"@types/react-dom": "^19.1.7",
41+
"@typescript-eslint/eslint-plugin": "^8.14.0",
42+
"@typescript-eslint/parser": "^8.14.0",
43+
"chalk": "~4.1.2",
44+
"chokidar": "~4.0.3",
45+
"constant-case": "^3.0.4",
46+
"cross-env": "~10.0.0",
47+
"dotenv-flow": "^4.1.0",
48+
"eslint": "^9.15.0",
49+
"eslint-config-next": "^16.2.0",
50+
"eslint-config-prettier": "^8.6.0",
51+
"eslint-plugin-prettier": "^4.2.1",
52+
"eslint-plugin-react": "^7.37.5",
53+
"eslint-plugin-yaml": "^0.5.0",
54+
"npm-run-all": "~4.1.5",
55+
"prettier": "^2.8.3",
56+
"ts-node": "^10.9.1",
57+
"tsconfig-paths": "^4.1.2",
58+
"typescript": "~5.4.0"
59+
},
60+
"scripts": {
61+
"jss": "jss",
62+
"lint": "eslint ./src/**/*.tsx ./src/**/*.ts ./scripts/**/*.ts",
63+
"bootstrap": "ts-node --require dotenv-flow/config --project tsconfig.scripts.json scripts/bootstrap.ts",
64+
"build": "cross-env NODE_ENV=production npm-run-all --serial bootstrap next:build",
65+
"next:build": "next build --webpack",
66+
"next:dev": "cross-env NODE_OPTIONS='--inspect' next dev --webpack",
67+
"next:start": "next start",
68+
"scaffold": "ts-node --project tsconfig.scripts.json scripts/scaffold-component/index.ts",
69+
"start:connected": "cross-env NODE_ENV=development npm-run-all --serial bootstrap --parallel next:dev start:watch-components",
70+
"start:production": "cross-env-shell NODE_ENV=production npm-run-all --serial bootstrap next:build next:start",
71+
"start:watch-components": "ts-node --project tsconfig.scripts.json scripts/generate-component-builder/index.ts --watch",
72+
"install-pre-push-hook": "ts-node --project tsconfig.scripts.json ./scripts/install-pre-push-hook.ts"
73+
}
74+
}

packages/sitecore-jss-cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"@types/node": "^24.10.4",
5050
"@types/readline-sync": "^1.4.8",
5151
"@types/resolve": "^1.20.6",
52-
"@types/sinon": "^10.0.13",
52+
"@types/sinon": "^17.0.4",
5353
"@types/tmp": "^0.2.6",
5454
"@types/yargs": "^17.0.33",
5555
"chai": "^4.3.7",

packages/sitecore-jss-cli/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"target": "es6",
55
"module": "commonjs",
66
"forceConsistentCasingInFileNames": true,
7+
"skipLibCheck": true,
78
"outDir": "dist/cjs",
89
"typeRoots": ["node_modules/@types"],
910
"declarationDir": "./types"

packages/sitecore-jss-nextjs/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"eslint-plugin-react": "^7.37.5",
5454
"jsdom": "^26.1.0",
5555
"mocha": "^11.7.0",
56-
"next": "^16.1.0",
56+
"next": "^16.2.0",
5757
"nock": "^13.3.0",
5858
"nyc": "^17.1.0",
5959
"react": "^19.1.0",
@@ -67,7 +67,7 @@
6767
"@sitecore-cloudsdk/core": "^0.5.2",
6868
"@sitecore-cloudsdk/events": "^0.5.2",
6969
"@sitecore-cloudsdk/personalize": "^0.5.2",
70-
"next": "^16.1.0",
70+
"next": "^16.2.0",
7171
"react": "^19.1.0",
7272
"react-dom": "^19.1.0"
7373
},

0 commit comments

Comments
 (0)