Skip to content

Conversation

@huseeiin
Copy link
Contributor

my first feature PR to nitro. might've made mistakes.
i tested and it opens http://[::1]:3000/ in the browser instead of http://localhost:3000. might need changes?

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@huseeiin huseeiin requested a review from pi0 as a code owner December 13, 2025 10:27
@vercel
Copy link

vercel bot commented Dec 13, 2025

@huseeiin is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Dec 13, 2025

πŸ“ Walkthrough

Walkthrough

A new CLI flag open is added to the dev command, allowing developers to automatically open the dev server in the default browser. The open package dependency is introduced and integrated into the dev command's startup flow to enable this functionality.

Changes

Cohort / File(s) Summary
Package dependencies
package.json
Added open ^11.0.0 as a new runtime dependency for opening URLs in the default browser
Dev command implementation
src/cli/commands/dev.ts
Imported open package; added open boolean flag to dev command arguments with description "open dev server in default browser"; integrated conditional logic to launch browser URL when flag is enabled

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • The changes follow a straightforward pattern: dependency addition + flag definition + conditional invocation
  • Limited scope with localized modifications to a single command file
  • No complex logic density or structural refactoring required

Pre-merge checks and finishing touches

βœ… Passed checks (3 passed)
Check name Status Explanation
Description check βœ… Passed The description relates to the changeset by discussing the new browser-opening feature, including testing observations and concerns about URL format, though it lacks detail about the implementation.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check βœ… Passed The pull request title follows conventional commits format with 'feat' type and 'cli' scope, and accurately describes the main change of adding browser-opening functionality to the dev command.
✨ Finishing touches
  • πŸ“ Generate docstrings
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

πŸ“œ Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between effb2c6 and 346f20a.

β›” Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
πŸ“’ Files selected for processing (2)
  • package.json (1 hunks)
  • src/cli/commands/dev.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/cli/commands/dev.ts (1)
src/runtime/internal/vite/node-runner.mjs (2)
  • url (289-289)
  • server (170-183)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: tests-rollup (ubuntu-latest)
  • GitHub Check: tests-rolldown (windows-latest)
  • GitHub Check: tests-rollup (windows-latest)
πŸ”‡ Additional comments (4)
src/cli/commands/dev.ts (3)

8-8: LGTM!

The import statement is correct for the open package.


19-22: LGTM!

The CLI flag definition is clear and follows the existing pattern for command arguments.


68-73: LGTM!

Capturing the URL from server.listen() is necessary for the browser opening feature.

package.json (1)

71-71: The open package version 11.0.0 exists on npm and has no known security vulnerabilities. No action is required.

})
).url;

if (args.open && url) open(url);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cat src/cli/commands/dev.ts 2>/dev/null | head -100

Repository: nitrojs/nitro

Length of output: 2283


🏁 Script executed:

rg "^import.*from.*open" --type ts --type js

Repository: nitrojs/nitro

Length of output: 361


🏁 Script executed:

rg "args\.open|open\(" --type ts --type js -B 3 -A 3

Repository: nitrojs/nitro

Length of output: 1332


🏁 Script executed:

rg -A 30 "listen\(" src/dev/server.ts | grep -A 30 "listen"

Repository: nitrojs/nitro

Length of output: 907


🏁 Script executed:

cat -n src/dev/server.ts | head -200

Repository: nitrojs/nitro

Length of output: 6855


🏁 Script executed:

# Search for IPv6 related issues or comments in the codebase
rg "\[::1\]|IPv6" --type ts --type js

Repository: nitrojs/nitro

Length of output: 188


🏁 Script executed:

# Check if there are any recent commits or PRs about this
git log --all --oneline --grep="IPv6\|localhost\|\[::1\]" | head -20

Repository: nitrojs/nitro

Length of output: 39


🏁 Script executed:

# Look for test files that might show expected URL format
fd ".*test.*" src/ --type f | xargs grep -l "open\|url\|listen" | head -5

Repository: nitrojs/nitro

Length of output: 39


🏁 Script executed:

# Check the open package type definitions or usage
rg "typeof.*open|open.*Promise" --type ts

Repository: nitrojs/nitro

Length of output: 137


🏁 Script executed:

# Check the common args to see what defaults are set
cat src/cli/common.ts

Repository: nitrojs/nitro

Length of output: 344


🏁 Script executed:

# Search for devServer configuration in nitro
rg "devServer" src/ --type ts -A 3 | head -40

Repository: nitrojs/nitro

Length of output: 1905


🏁 Script executed:

# Check the srvx package to understand how it formats URLs
rg "serve\(" src/dev/server.ts -B 2 -A 10

Repository: nitrojs/nitro

Length of output: 406


🏁 Script executed:

# Check what args.port and args.host default to
rg -B 5 -A 5 "listen.*args" src/cli/commands/dev.ts

Repository: nitrojs/nitro

Length of output: 39


🏁 Script executed:

# Search for srvx in package.json to understand the package
cat package.json | grep -A 2 -B 2 "srvx"

Repository: nitrojs/nitro

Length of output: 195


🏁 Script executed:

# Look for how server address is determined
rg "localhost|127\.0\.0\.1" src/ --type ts | head -20

Repository: nitrojs/nitro

Length of output: 667


🏁 Script executed:

# Check if args.open, args.host, args.port are actually defined as command args
rg -A 30 "args:" src/cli/commands/dev.ts | grep -E "open|host|port" -A 2

Repository: nitrojs/nitro

Length of output: 307


🏁 Script executed:

# Search for any bug reports or issues about IPv6
git log --all --oneline | grep -i "ipv6\|open.*url\|browser" | head -10

Repository: nitrojs/nitro

Length of output: 157


🏁 Script executed:

# Check how the open package from npm handles IPv6 URLs
npm info open | head -40 2>/dev/null || echo "npm info not available in sandbox"

Repository: nitrojs/nitro

Length of output: 933


🏁 Script executed:

# Get more details about the open feature commit
git show 346f20a | head -100

Repository: nitrojs/nitro

Length of output: 2854


🏁 Script executed:

git show 346f20a -- src/cli/commands/dev.ts

Repository: nitrojs/nitro

Length of output: 2705


🏁 Script executed:

# Check if there are any similar patterns in the codebase where open is used
rg "open\(" src/ --type ts --type js | grep -v "open()" | head -10

Repository: nitrojs/nitro

Length of output: 119


Add error handling and await the open() call.

The open() function returns a Promise and must be awaited to properly handle errors. Without await and error handling, an unhandled promise rejection could occur if the browser fails to open.

Apply this diff:

-      if (args.open && url) open(url);
+      if (args.open && url) {
+        try {
+          await open(url);
+        } catch (error) {
+          consola.warn("Failed to open browser:", error);
+        }
+      }
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (args.open && url) open(url);
if (args.open && url) {
try {
await open(url);
} catch (error) {
consola.warn("Failed to open browser:", error);
}
}
πŸ€– Prompt for AI Agents
In src/cli/commands/dev.ts around line 75, the call if (args.open && url)
open(url); must be converted to an awaited call with error handling: change it
to await the open(url) inside a try/catch (or Promise.catch) so any rejection is
handled and logged or reported appropriately; ensure the enclosing function is
async or use an IIFE to await, and in the catch block log a concise message
including the error so failures to launch the browser don't cause unhandled
promise rejections.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 13, 2025

Open in StackBlitz

npm i https://pkg.pr.new/nitrojs/nitro@3871

commit: 346f20a

"jiti": "^2.6.1",
"ofetch": "^2.0.0-alpha.3",
"ohash": "^2.0.11",
"open": "^11.0.0",
Copy link
Member

Choose a reason for hiding this comment

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

Ideally we should avoid additional dependencies or bundle them open adds 11 subdeps

Copy link
Member

Choose a reason for hiding this comment

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

Wondering what vite CLI does use for this feature

Copy link
Contributor Author

Choose a reason for hiding this comment

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

open as well, i'm pretty sure

Copy link
Contributor Author

@huseeiin huseeiin Dec 16, 2025

Choose a reason for hiding this comment

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

side idea: what if we base standalone nitro on vite? meaning like vite-plugin-nitro, but it only does backend and doesn't use index.html. this way we can inherit all of vite's support for --open, https, http2, etc.

it'd be like:
vite-plugin-nitro: plugin for nitro-based frameworks
standalone nitro: a vite-based framework in of itself

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally we should avoid additional dependencies or bundle them open adds 11 subdeps

maybe stupid question: what difference does bundling it make? the dependencies will still be there, just bundled

@pi0 pi0 changed the title feat: open dev server in browser feat(cli): support opening in browser with dev command Dec 15, 2025
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.

2 participants