Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
4b364ca9
Unverified
Commit
4b364ca9
authored
Oct 20, 2024
by
Sebastian "Sebbie" Silbermann
Committed by
GitHub
Oct 20, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
next-upgrade: Stop prompting for React 19 upgrade on pure App Router apps (#71486)
parent
a4840e32
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
38 additions
and
11 deletions
+38
-11
README.md
..._testfixtures__/react-18-installed-mixed-router/README.md
+1
-1
package.json
...stfixtures__/react-18-installed-mixed-router/package.json
+1
-1
README.md
...stfixtures__/react-18-installed-pure-app-router/README.md
+1
-1
package.json
...ixtures__/react-18-installed-pure-app-router/package.json
+1
-1
README.md
...fixtures__/react-18-installed-pure-pages-router/README.md
+1
-1
package.json
...tures__/react-18-installed-pure-pages-router/package.json
+1
-1
package.json
...stfixtures__/react-19-installed-mixed-router/package.json
+1
-1
package.json
...ixtures__/react-19-installed-pure-app-router/package.json
+1
-1
package.json
...tures__/react-19-installed-pure-pages-router/package.json
+1
-1
upgrade.ts
packages/next-codemod/bin/upgrade.ts
+29
-2
No files found.
packages/next-codemod/bin/__testfixtures__/react-18-installed-mixed-router/README.md
View file @
4b364ca9
Prompts for React 19 upgrade
Prompts for React 19 upgrade
with a recommendation to do so
packages/next-codemod/bin/__testfixtures__/react-18-installed-mixed-router/package.json
View file @
4b364ca9
{
"name"
:
"react-18-installed-mixed-router"
,
"scripts"
:
{
"dev"
:
"next dev"
"dev"
:
"next dev
--turbo
"
},
"dependencies"
:
{
"next"
:
"14.3.0-canary.44"
,
...
...
packages/next-codemod/bin/__testfixtures__/react-18-installed-pure-app-router/README.md
View file @
4b364ca9
Prompts for React 19 upgrade
Upgrades to React 19 automatically
packages/next-codemod/bin/__testfixtures__/react-18-installed-pure-app-router/package.json
View file @
4b364ca9
{
"name"
:
"react-18-installed-pure-app-router"
,
"scripts"
:
{
"dev"
:
"next dev"
"dev"
:
"next dev
--turbo
"
},
"dependencies"
:
{
"next"
:
"14.3.0-canary.44"
,
...
...
packages/next-codemod/bin/__testfixtures__/react-18-installed-pure-pages-router/README.md
View file @
4b364ca9
Prompts for React 19 upgrade
Prompts for React 19 upgrade
without any recommendation
packages/next-codemod/bin/__testfixtures__/react-18-installed-pure-pages-router/package.json
View file @
4b364ca9
{
"name"
:
"react-18-installed-pure-pages-router"
,
"scripts"
:
{
"dev"
:
"next dev"
"dev"
:
"next dev
--turbo
"
},
"dependencies"
:
{
"next"
:
"14.3.0-canary.44"
,
...
...
packages/next-codemod/bin/__testfixtures__/react-19-installed-mixed-router/package.json
View file @
4b364ca9
{
"name"
:
"react-19-installed-mixed-router"
,
"scripts"
:
{
"dev"
:
"next dev"
"dev"
:
"next dev
--turbo
"
},
"dependencies"
:
{
"next"
:
"14.3.0-canary.45"
,
...
...
packages/next-codemod/bin/__testfixtures__/react-19-installed-pure-app-router/package.json
View file @
4b364ca9
{
"name"
:
"react-19-installed-pure-app-router"
,
"scripts"
:
{
"dev"
:
"next dev"
"dev"
:
"next dev
--turbo
"
},
"dependencies"
:
{
"next"
:
"14.3.0-canary.45"
,
...
...
packages/next-codemod/bin/__testfixtures__/react-19-installed-pure-pages-router/package.json
View file @
4b364ca9
{
"name"
:
"react-19-installed-pure-pages-router"
,
"scripts"
:
{
"dev"
:
"next dev"
"dev"
:
"next dev
--turbo
"
},
"dependencies"
:
{
"next"
:
"14.3.0-canary.45"
,
...
...
packages/next-codemod/bin/upgrade.ts
View file @
4b364ca9
...
...
@@ -125,6 +125,12 @@ export async function runUpgrade(
console
.
log
(
` - React: v
${
installedReactVersion
}
`
)
console
.
log
(
` - Next.js: v
${
installedNextVersion
}
`
)
let
shouldStayOnReact18
=
false
const
usesAppDir
=
isUsingAppDir
(
process
.
cwd
())
const
usesPagesDir
=
isUsingPagesDir
(
process
.
cwd
())
const
isPureAppRouter
=
usesAppDir
&&
!
usesPagesDir
const
isMixedApp
=
usesPagesDir
&&
usesAppDir
if
(
// From release v14.3.0-canary.45, Next.js expects the React version to be 19.0.0-beta.0
// If the user is on a version higher than this but is still on React 18, we ask them
...
...
@@ -134,13 +140,21 @@ export async function runUpgrade(
// x-ref(PR): https://github.com/vercel/next.js/pull/65058
// x-ref(release): https://github.com/vercel/next.js/releases/tag/v14.3.0-canary.45
compareVersions
(
targetNextVersion
,
'14.3.0-canary.45'
)
>=
0
&&
installedReactVersion
.
startsWith
(
'18'
)
installedReactVersion
.
startsWith
(
'18'
)
&&
// Pure App Router always uses React 19
// The mixed case is tricky to handle from a types perspective.
// We'll recommend to upgrade in the prompt but users can decide to try 18.
!
isPureAppRouter
)
{
const
shouldStayOnReact18Res
=
await
prompts
(
{
type
:
'confirm'
,
name
:
'shouldStayOnReact18'
,
message
:
`Are you using
${
pc
.
underline
(
'only the Pages Router'
)}
(no App Router) and prefer to stay on React 18?`
,
message
:
`Do you prefer to stay on React 18?`
+
(
isMixedApp
?
" Since you're using both pages/ and app/, we recommend upgrading React to use a consistent version throughout your app."
:
''
),
initial
:
false
,
active
:
'Yes'
,
inactive
:
'No'
,
...
...
@@ -371,6 +385,19 @@ function getInstalledReactVersion(): string {
}
}
function
isUsingPagesDir
(
projectPath
:
string
):
boolean
{
return
(
fs
.
existsSync
(
path
.
resolve
(
projectPath
,
'pages'
))
||
fs
.
existsSync
(
path
.
resolve
(
projectPath
,
'src/pages'
))
)
}
function
isUsingAppDir
(
projectPath
:
string
):
boolean
{
return
(
fs
.
existsSync
(
path
.
resolve
(
projectPath
,
'app'
))
||
fs
.
existsSync
(
path
.
resolve
(
projectPath
,
'src/app'
))
)
}
/*
* Heuristics are used to determine whether to Turbopack is enabled or not and
* to determine how to update the dev script.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment