Fix Next.js fast refresh broken with bun --bun (issue #64)#238
Open
creativoma wants to merge 1 commit intovercel-labs:mainfrom
Open
Fix Next.js fast refresh broken with bun --bun (issue #64)#238creativoma wants to merge 1 commit intovercel-labs:mainfrom
creativoma wants to merge 1 commit intovercel-labs:mainfrom
Conversation
…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
|
@creativoma is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes HMR / fast refresh not working when running
bun --bun next devthrough portless, and improvesbunpackage runner support across all frameworks.Root cause: When Bun uses its native runtime (
--bunflag), it reads theHOSTenvironment variable to configure WebSocket origin validation. Portless was injectingHOST=127.0.0.1into 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:
--bunflag and skipsHOST=127.0.0.1for those invocations — the same pattern already used for Expo in LAN mode. The server binds to0.0.0.0by default, so the proxy still reaches it via127.0.0.1. Frameworks that require explicit binding (Vite, Astro, Angular, etc.) still receive--host 127.0.0.1throughinjectFrameworkFlags.bunis now recognized as a package runner alongsidenpx,bunx, andpnpm dlx. This meansbun vite dev,bun --bun vite dev, andbun run vite devall correctly receive the--portand--hostflag injection that Vite requires.Changes
src/cli.tsbun --buninvocations and skipHOST=127.0.0.1src/cli-utils.tsbuntoPACKAGE_RUNNERSwith"run"as a subcommandsrc/cli-utils.test.tsbunrunner andbun --bunpatternsCHANGELOG.mdUnreleasedTest plan
bun vite dev— injects--portand--host 127.0.0.1bun --bun vite dev— injects--portand--host 127.0.0.1bun run vite dev— injects--portand--host 127.0.0.1bun run --bun vite dev— injects--portand--host 127.0.0.1bun astro dev— injects--portand--host 127.0.0.1bun --bun next dev— no flag injection (Next.js readsPORTenv var);HOSTis omittedbun run next dev— no flag injectionbun run dev(generic script) — no injection, no regressionportless run --name test bun --bun next devstarted Next.js on assigned port with noHOSTin env, and fast refresh worked through the proxypnpm lint,pnpm type-check, andpnpm buildpass cleanCloses #64