Skip to content

Conversation

@VasuS609
Copy link
Contributor

@VasuS609 VasuS609 commented Dec 8, 2025

Added tauri-dev-auto-port.js for dynamic port selection

  • Scan ports 5173-5182 to find available port
  • Update package.json to use auto-port script
  • Prevent conflicts when running multiple dev instances

Features:

  • Automatic port conflict resolution
  • Supports multiple simultaneous dev environments
  • Graceful fallback if all ports occupied
  • Environment variables set correctly (VITE_PORT, TAURI_MODE)

Resolves issue where multiple dev environments couldn't run simultaneously due to hardcoded port configuration

Summary by CodeRabbit

  • New Features
    • Adds a development helper that automatically finds an available port and starts the Tauri dev server, simplifying local startup and eliminating manual port configuration.

✏️ Tip: You can customize this high-level summary in your review settings.

- Add tauri-dev-auto-port.js for dynamic port selection
- Scan ports 5173-5182 to find available port
- Update package.json to use auto-port script
- Prevent conflicts when running multiple dev instances

Features:
- Automatic port conflict resolution
- Supports multiple simultaneous dev environments
- Graceful fallback if all ports occupied
- Environment variables set correctly (VITE_PORT, TAURI_MODE)

Resolves issue where multiple dev environments couldn't run
simultaneously due to hardcoded port configuration
@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2025

⚠️ No issue was linked in the PR description.
Please make sure to link an issue (e.g., 'Fixes #issue_number')

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 8, 2025

Walkthrough

Adds an npm script and Node.js utility that probe ports 5173–5182, set environment variables (VITE_PORT, TAURI_CLI_PORT, TAURI_DEV_HOST), and launch the Tauri development server with the detected available port.

Changes

Cohort / File(s) Change Summary
Tauri dev automation
frontend/package.json
Added tauri:dev npm script that runs the automatic-port utility.
Port discovery utility
frontend/scripts/tauri-dev-auto-port.js
New script that sequentially checks ports 5173–5182, selects the first available port, sets env vars, and spawns npm run tauri dev with appropriate CLI flags and error handling.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Inspect TCP port probing and socket cleanup for race conditions.
  • Verify environment variables are set and passed to the spawned process.
  • Validate spawn/error handling and exit-code propagation.

Poem

🐰 I sniffed the ports from five-one-seven-three,
Hopped till I found one waiting just for me.
I set the vars, gave a cheerful thump,
And watched the Tauri dev server jump! 🚀

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'add automatic port detection for Tauri dev server' directly and clearly summarizes the main change: adding automatic port detection functionality for the Tauri development server, which matches the core implementation of the new tauri-dev-auto-port.js script.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ 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.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2025

⚠️ No issue was linked in the PR description.
Please make sure to link an issue (e.g., 'Fixes #issue_number')

Copy link
Contributor

@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: 2

🧹 Nitpick comments (1)
frontend/scripts/tauri-dev-auto-port.js (1)

87-99: Clarify environment variable usage and subprocess invocation.

A few observations:

  1. Line 88: Setting VITE_PORT on process.env has no effect since it's set after the spawn environment is constructed. However, line 98 does pass it correctly.
  2. The beforeDevCommand explicitly sets --port, so VITE_PORT may be redundant unless consumed elsewhere.
  3. Line 95: Spawning npm run tauri dev creates a chain (node → npm → tauri → npm → vite). Consider invoking tauri directly via npx to reduce indirection.

Consider simplifying the spawn:

- const tauri = spawn('npm', ['run', 'tauri', 'dev'], {
+ const tauri = spawn('npx', ['tauri', 'dev'], {
    stdio: 'inherit',
    shell: true,
    env: { ...process.env, VITE_PORT: port.toString() }
  });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d07d817 and 8906c8d.

📒 Files selected for processing (2)
  • frontend/package.json (1 hunks)
  • frontend/scripts/tauri-dev-auto-port.js (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
frontend/scripts/tauri-dev-auto-port.js (1)
scripts/setup.js (1)
  • __dirname (8-8)
⏰ 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). (4)
  • GitHub Check: Backend Tests
  • GitHub Check: Tauri Build Check (macos-latest, --target aarch64-apple-darwin)
  • GitHub Check: Tauri Build Check (ubuntu-22.04)
  • GitHub Check: Tauri Build Check (windows-latest)
🔇 Additional comments (3)
frontend/package.json (1)

13-13: LGTM!

The new script entry correctly references the auto-port detection script and follows the existing naming conventions.

frontend/scripts/tauri-dev-auto-port.js (2)

39-46: LGTM!

The port scanning logic is clean and correctly returns the first available port in the range.


106-109: LGTM!

The top-level error handler correctly catches and reports any uncaught errors from the main function.

- Use --dev-url and --port CLI flags
- Remove config file modification to prevent git conflicts
- Improve error handling with specific warnings
- Bind explicitly to localhost for security

Addresses CodeRabbit feedback
@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2025

⚠️ No issue was linked in the PR description.
Please make sure to link an issue (e.g., 'Fixes #issue_number')

1 similar comment
@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2025

⚠️ No issue was linked in the PR description.
Please make sure to link an issue (e.g., 'Fixes #issue_number')

Copy link
Contributor

@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 8906c8d and 966b0a7.

📒 Files selected for processing (1)
  • frontend/scripts/tauri-dev-auto-port.js (1 hunks)
⏰ 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). (4)
  • GitHub Check: Backend Tests
  • GitHub Check: Tauri Build Check (macos-latest, --target aarch64-apple-darwin)
  • GitHub Check: Tauri Build Check (ubuntu-22.04)
  • GitHub Check: Tauri Build Check (windows-latest)
🔇 Additional comments (5)
frontend/scripts/tauri-dev-auto-port.js (5)

1-6: LGTM! Well-defined constants.

The port range (5173-5182) provides sufficient options for multiple simultaneous dev instances while staying within Vite's typical port range.


13-33: LGTM! Robust port checking implementation.

The error handling improvements from the previous review have been properly implemented. The explicit localhost binding and detailed error logging make this function reliable.


39-46: LGTM! Clean port discovery logic.

The sequential scan approach is straightforward and the null return value provides a clear signal when all ports are occupied.


104-107: LGTM! Proper top-level error handling.

The catch block ensures unhandled errors in main() are logged and result in a non-zero exit code.


69-92: No issues found with the Tauri CLI configuration.

The flags and environment variables are correctly configured:

  • --dev-url http://localhost:${port} points Tauri to your external Vite dev server
  • --port ${port} configures Tauri's built-in static file server (a separate feature)
  • VITE_PORT tells Vite which port to use
  • TAURI_CLI_PORT and --port are redundant but harmless (env var alternative to the flag)
  • TAURI_DEV_HOST='localhost' is automatically managed by Tauri CLI; explicitly setting it is benign

These are not conflicting configurations—they serve distinct purposes for the dev server setup.

Comment on lines +56 to +63
if (!port) {
console.error(
`\n❌ No available ports found in range ${PORT_RANGE_START}-${PORT_RANGE_END}`,
);
console.error(
'Please free up a port or manually configure the port in tauri.conf.json',
);
process.exit(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Update the error message to reflect the current approach.

The error message suggests manually configuring tauri.conf.json, but the PR's goal is to avoid modifying that file. Consider updating the message to suggest alternatives like closing other dev servers or adjusting the port range in this script.

Apply this diff:

   if (!port) {
     console.error(
       `\n❌ No available ports found in range ${PORT_RANGE_START}-${PORT_RANGE_END}`,
     );
     console.error(
-      'Please free up a port or manually configure the port in tauri.conf.json',
+      'Please close other dev servers or expand the PORT_RANGE in this script',
     );
     process.exit(1);
   }
🤖 Prompt for AI Agents
In frontend/scripts/tauri-dev-auto-port.js around lines 56 to 63, the error text
incorrectly tells users to edit tauri.conf.json; update the messages to reflect
the new non-invasive approach by telling users to close other running dev
servers or adjust the PORT_RANGE_START/PORT_RANGE_END in this script (or run
with a different port), and replace the two console.error calls accordingly so
they guide users to those alternatives instead of editing tauri.conf.json.

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.

1 participant