Skip to content

fix: support api.port 0 - #11641

Open
hi-ogawa wants to merge 8 commits into
vitest-dev:mainfrom
hi-ogawa:fix/issue-9035-port-zero
Open

hi-ogawa wants to merge 8 commits into
vitest-dev:mainfrom
hi-ogawa:fix/issue-9035-port-zero

Conversation

@hi-ogawa

@hi-ogawa hi-ogawa commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

api.port: 0 is conventionally expected to let the OS pick an available port, but Vitest treated 0 as unset and fell back to the default port (23315 in browser mode, 51204 otherwise). This PR fixes it.

Side note: Vite itself only handles port: 0 since 8.2.1 (vitejs/vite#23158), so this change relies on that fix.

The new e2e test doesn't test the new behavior exactly because the behavior depends on the Vite version. Various cases are checked manually, and the setup and results are in this note: https://gist.github.com/hi-ogawa/7db0da909aee7b614e7e3ff4d11ba9a9

Refs vitest-dev#9035

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@netlify

netlify Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 4c3706c
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6ad5d763fff85816e363818c
😎 Deploy Preview https://deploy-preview-11641--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

hi-ogawa and others added 3 commits October 19, 2026 17:38
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hi-ogawa and others added 2 commits October 19, 2026 17:51
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pkg-pr-new

pkg-pr-new Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
@vitest/browser

npm i https://pkg.pr.new/@vitest/browser@3cc1327

@vitest/browser-playwright

npm i https://pkg.pr.new/@vitest/browser-playwright@3cc1327

@vitest/browser-preview

npm i https://pkg.pr.new/@vitest/browser-preview@3cc1327

@vitest/coverage-istanbul

npm i https://pkg.pr.new/@vitest/coverage-istanbul@3cc1327

@vitest/coverage-v8

npm i https://pkg.pr.new/@vitest/coverage-v8@3cc1327

@vitest/expect

npm i https://pkg.pr.new/@vitest/expect@3cc1327

@vitest/mocker

npm i https://pkg.pr.new/@vitest/mocker@3cc1327

@vitest/pretty-format

npm i https://pkg.pr.new/@vitest/pretty-format@3cc1327

@vitest/snapshot

npm i https://pkg.pr.new/@vitest/snapshot@3cc1327

@vitest/spy

npm i https://pkg.pr.new/@vitest/spy@3cc1327

@vitest/ui

npm i https://pkg.pr.new/@vitest/ui@3cc1327

@vitest/utils

npm i https://pkg.pr.new/@vitest/utils@3cc1327

vitest

npm i https://pkg.pr.new/vitest@3cc1327

@vitest/web-worker

npm i https://pkg.pr.new/@vitest/web-worker@3cc1327

commit: 3cc1327

hi-ogawa and others added 2 commits October 19, 2026 18:12
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment on lines +236 to +245
const resolvedUrls = this.ctx.vite.resolvedUrls
const origin = resolvedUrls?.local[0] ?? resolvedUrls?.network[0]
if (origin && this.ctx.config._apiRequested) {
if (this.ctx.config.ui) {
const url = new URL(this.ctx.config.uiBase, origin)
url.searchParams.set('token', this.ctx.config.api.token)
this.log(PAD + c.dim(c.green(`UI started at ${url}`)))
} else {
this.log(PAD + c.dim(c.green(`API started at ${new URL('/', origin)}`)))
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The condition is simplified to encode the intent better, which is both apiRequested exists and Vite dev server bound the url. The old fallbackUrl was for old Vite 5 era workaround, so it can be dropped vitejs/vite#15438.

@hi-ogawa
hi-ogawa marked this pull request as ready for review October 19, 2026 09:23

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant