Skip to content

Fix Next.js fast refresh broken with bun --bun (issue #64)#238

Open
creativoma wants to merge 1 commit intovercel-labs:mainfrom
creativoma:fix/issue-64-bun-fast-refresh
Open

Fix Next.js fast refresh broken with bun --bun (issue #64)#238
creativoma wants to merge 1 commit intovercel-labs:mainfrom
creativoma:fix/issue-64-bun-fast-refresh

Conversation

@creativoma
Copy link
Copy Markdown

Summary

Fixes HMR / fast refresh not working when running bun --bun next dev through portless, and improves bun package runner support across all frameworks.

Root cause: When Bun uses its native runtime (--bun flag), it reads the HOST environment variable to configure WebSocket origin validation. Portless was injecting HOST=127.0.0.1 into every child process, which caused Bun's WebSocket server to reject HMR connections coming from the proxy's public hostname (e.g. app.localhost), breaking fast refresh silently.

Fix:

  • Portless now detects the --bun flag and skips HOST=127.0.0.1 for those invocations — the same pattern already used for Expo in LAN mode. The server binds to 0.0.0.0 by default, so the proxy still reaches it via 127.0.0.1. Frameworks that require explicit binding (Vite, Astro, Angular, etc.) still receive --host 127.0.0.1 through injectFrameworkFlags.
  • bun is now recognized as a package runner alongside npx, bunx, and pnpm dlx. This means bun vite dev, bun --bun vite dev, and bun run vite dev all correctly receive the --port and --host flag injection that Vite requires.

Changes

File Change
src/cli.ts Detect bun --bun invocations and skip HOST=127.0.0.1
src/cli-utils.ts Add bun to PACKAGE_RUNNERS with "run" as a subcommand
src/cli-utils.test.ts 8 new tests covering bun runner and bun --bun patterns
CHANGELOG.md Document both fixes under Unreleased

Test plan

  • bun vite dev — injects --port and --host 127.0.0.1
  • bun --bun vite dev — injects --port and --host 127.0.0.1
  • bun run vite dev — injects --port and --host 127.0.0.1
  • bun run --bun vite dev — injects --port and --host 127.0.0.1
  • bun astro dev — injects --port and --host 127.0.0.1
  • bun --bun next dev — no flag injection (Next.js reads PORT env var); HOST is omitted
  • bun run next dev — no flag injection
  • bun run dev (generic script) — no injection, no regression
  • Manual test: portless run --name test bun --bun next dev started Next.js on assigned port with no HOST in env, and fast refresh worked through the proxy
  • All 413 existing tests pass
  • pnpm lint, pnpm type-check, and pnpm build pass clean

Closes #64

…unner (vercel-labs#64)

- Skip HOST=127.0.0.1 when bun --bun is detected: Bun's native runtime
  uses HOST to configure WebSocket origin validation, which causes the
  proxy's public hostname (e.g. app.localhost) to be rejected for HMR
  WebSocket connections. Omitting HOST lets Next.js bind to 0.0.0.0 so
  the proxy still reaches it via 127.0.0.1, while frameworks that need
  explicit binding (Vite, Astro, etc.) still get --host 127.0.0.1 via
  injectFrameworkFlags.

- Add bun to PACKAGE_RUNNERS with "run" as a recognized subcommand so
  that bun vite dev, bun --bun vite dev, and bun run vite dev all receive
  the correct --port and --host flag injection.

Closes vercel-labs#64
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 19, 2026

@creativoma is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fast refresh doesn't work with "Bun"

1 participant