Skip to content

bug: port = 0 does not work because the actual bound port is never exposed #372

Description

@jiz4oh

Did you read the documentation and check existing issues?

Neovim version (nvim -v)

0.12.3

Operating system/version

macos 26.6

Browser/version

149.0.7827.200

Describe the bug

live-preview.nvim currently accepts a configured port, but port = 0 does not work as expected.

On systems where binding to port 0 should let the OS choose an ephemeral port, the plugin still keeps using the configured value 0 afterward when it:

  • checks whether the port is already in use
  • builds the preview URL
  • opens the browser
  • reports health/runtime state

As a result, users cannot use port = 0 to request a random available port, and the final assigned port is not exposed anywhere.

Using port = 0 is a standard way to avoid fixed-port conflicts, especially in:

  • remote development
  • SSH sessions
  • multiple concurrent Neovim instances
  • environments where a static preview port is frequently occupied

Steps To Reproduce

  1. Clone the plugin git clone https://github.com/brianhuster/live-preview.nvim
  2. Open Nvim with minimal repro file nvim -u minimal_init.lua
  3. ...

Expected Behavior

  • The server should bind successfully on an OS-assigned ephemeral port.
  • The plugin should discover the effective port after bind/listen.
  • The browser should open the real URL, for example http://127.0.0.1:54321/....
  • The effective port should be available to users, for example through plugin state or a public API.

Health

livepreview:                                                              1 ❌

- ❌ ERROR No healthcheck found for "livepreview" plugin.

Minimal config to reproduce

vim.cmd.set "rtp+=/path/to/live-preview.nvim"

require("livepreview.config").set({
  address = "127.0.0.1",
  port = 0,
})

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions