mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
### What? Two behaviour changes to the rage-restart detection in `next dev`, plus a refactor of the git helper code: 1. **Lower the rage-restart threshold from 120s to 90s.** The previous window was too generous; 90 s is a better match for the workflow of stopping and immediately restarting the dev server. 2. **Don't count a restart as a rage-restart if the git branch changed.** A common workflow is: stop the dev server, `git checkout <other-branch>`, restart. That sequence has nothing to do with frustration — it's intentional. The dev state file now records the current git branch on shutdown, and on startup the recorded branch is compared to the current one. If they differ the restart is not flagged. If either branch is unknown (detached HEAD, not a git repo, etc.) the comparison is skipped and we fall back to time-only detection, preserving the existing behaviour. ### Why? The rage-restart signal is meant to detect genuine frustration with the dev server (e.g. it's hanging or erroring on startup). Switching branches is an intentional, deliberate action that happens to look the same from a pure timing perspective. Capturing it as rage-restart pollutes telemetry and could trigger unwanted recovery behaviour. The git helper consolidation removes duplicated `spawnSync` / `execSync` calls spread across unrelated files, centralises the `VERCEL_GIT_*` env-var fallback logic, and makes it easy to add further git queries in one place. ### How? - `writeDevState()` in `next-dev.ts` now calls `getGitBranch(dir)` and stores the result under a `gitBranch` key in the dev state file (omitted when the branch is unknown). - On startup, after reading the dev state file, the stored `gitBranch` is compared to the freshly-read `getGitBranch(dir)`. `isRageRestart` is only set when the branch either hasn't changed or couldn't be determined. - `packages/next/src/lib/helpers/git.ts` provides `gitExec()` (private), `getGitBranch()`, and `getGitCommit()`. It replaces the deleted `get-git-branch.ts` and the open-coded `child_process.spawnSync` calls in `trace-uploader.ts`. <!-- NEXT_JS_LLM_PR --> --------- Co-authored-by: Will Binns-Smith <[email protected]> Co-authored-by: Claude <[email protected]>