Skip to content

feat(devserver): auto-detect free port for dev-ui#113961

Merged
JonasBa merged 8 commits intomasterfrom
jb/infra/devserver-port
Apr 27, 2026
Merged

feat(devserver): auto-detect free port for dev-ui#113961
JonasBa merged 8 commits intomasterfrom
jb/infra/devserver-port

Conversation

@JonasBa
Copy link
Copy Markdown
Member

@JonasBa JonasBa commented Apr 24, 2026

Update dev-server startup with a more DX friendly approach that checks if the port is used and prompts user to open the dev server on a next port. This allows folks running multiple checkouts or worktrees to more easily start dev servers and do work in parallel

@JonasBa JonasBa requested review from a team as code owners April 24, 2026 17:37
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Apr 24, 2026
When port 7999 is already in use, the dev-ui server now scans for the
next available port (up to +10) and prompts the user before starting
rspack on it, rather than failing immediately.
Comment thread scripts/dev-ui-server.ts
- Normalize input to lowercase before comparison
- Only treat 'y' or 'yes' as confirmation
- Prevents 'no' and other responses from being treated as yes

Co-authored-by: Jonas <JonasBa@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b2f87fb. Configure here.

Comment thread scripts/dev-ui-server.ts
- Empty input now accepts the default [Y/n] option
- Aligns with standard CLI prompt conventions
- Users can press Enter to quickly confirm alternate port

Co-authored-by: Jonas <JonasBa@users.noreply.github.com>
Copy link
Copy Markdown
Member

@scttcper scttcper left a comment

Choose a reason for hiding this comment

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

rspack does support port: 'auto' that we could use behind a flag i guess? wouldn't ask for confirmation like this version

@JonasBa
Copy link
Copy Markdown
Member Author

JonasBa commented Apr 24, 2026

rspack does support port: 'auto' that we could use behind a flag i guess? wouldn't ask for confirmation like this version

As far as I can tell, there is no way to do auto + default right? We'd need that for when folks run the entire stack, so that it gets served from :8000 or whatever we use

Comment thread scripts/dev-ui-server.ts Outdated
Comment on lines +64 to +70
const confirmed = await ask(
`Port ${requestedPort} is already in use. Start on port ${availablePort} instead? [Y/n] `
);

if (!confirmed) {
process.exit(0);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've been meaning to do this for quite some time. Really glad you went ahead with it! 🎉 I agree with Scott's point, though... I'd probably skip asking for confirmation.

JonasBa and others added 2 commits April 27, 2026 08:40
Remove the interactive confirmation prompt when the default dev-ui
port is in use. The server now silently picks the next available port
and prints a message to stderr instead of waiting for user input.
Co-Authored-By: Claude <noreply@anthropic.com>
- Remove redundant 'use strict' (ES modules are always strict)
- Unify port search into a single findNextPort call instead of a
  separate isPortAvailable check followed by findNextPort
- Fix off-by-one in the exhausted-range error message
Co-Authored-By: Claude <noreply@anthropic.com>
Previously only the first port (e.g. 7999) was reported as in use.
Now all skipped ports are collected and logged so the message reflects
every port that was actually taken.

Co-Authored-By: Claude <noreply@anthropic.com>
@JonasBa
Copy link
Copy Markdown
Member Author

JonasBa commented Apr 27, 2026

@priscilawebdev @scttcper I've went ahead and swapped the confirmation for a log line, thanks for the suggestion!

@JonasBa JonasBa enabled auto-merge (squash) April 27, 2026 15:57
@JonasBa JonasBa merged commit aebfdff into master Apr 27, 2026
64 checks passed
@JonasBa JonasBa deleted the jb/infra/devserver-port branch April 27, 2026 16:06
cleptric pushed a commit that referenced this pull request May 5, 2026
Update dev-server startup with a more DX friendly approach that checks
if the port is used and prompts user to open the dev server on a next
port. This allows folks running multiple checkouts or worktrees to more
easily start dev servers and do work in parallel

---------

Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Jonas <JonasBa@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants