Skip to content

Conversation

devjiwonchoi
Copy link
Member

backports #83194

@ijjk ijjk added create-next-app Related to our CLI tool for quickly starting a new Next.js application. created-by: Next.js team PRs by the Next.js team. labels Sep 22, 2025
@devjiwonchoi devjiwonchoi marked this pull request as ready for review September 22, 2025 15:28
@ijjk
Copy link
Member

ijjk commented Sep 22, 2025

Tests Passed

initial:
linterIndexMap[
getPrefOrDefault('linter') as keyof typeof linterIndexMap
],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
],
] ?? 0,

The code could fail if the user's linter preference contains an unexpected value, causing undefined to be passed as the initial prompt selection.

View Details

Analysis

Undefined initial value passed to prompts when linter preference is invalid

What fails: The linterIndexMap lookup in packages/create-next-app/index.ts:321-324 returns undefined when getPrefOrDefault('linter') returns a value not in the map ('eslint', 'biome', 'none'), causing the prompts library to receive initial: undefined.

How to trigger:

  1. Create or modify the create-next-app config with an invalid linter preference:
# Edit ~/.config/create-next-app/config.json to contain:
{"preferences": {"linter": "invalid-value"}}
  1. Run create-next-app without CLI linter flags to trigger the interactive prompt

Result: The prompts library receives initial: undefined instead of a valid array index, leading to unpredictable default selection behavior.

Expected: Should default to a valid index (0 = ESLint) when the preference value is not recognized, ensuring consistent user experience.

Fix applied: Added nullish coalescing operator ?? 0 to provide fallback to first option (ESLint) when lookup returns undefined.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will get at least a default value so wouldn't be undefined

@devjiwonchoi devjiwonchoi merged commit b6a32bb into next-15-5 Sep 22, 2025
262 of 265 checks passed
@devjiwonchoi devjiwonchoi deleted the backport-next-15-5-83194 branch September 22, 2025 18:10
@github-actions github-actions bot added the locked label Oct 7, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

create-next-app Related to our CLI tool for quickly starting a new Next.js application. created-by: Next.js team PRs by the Next.js team. locked

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants