Skip to content

fix(cli): respect server config for host and port during live reload#8380

Open
fabiomartino wants to merge 1 commit intoionic-team:mainfrom
fabiomartino:fix/live-reload-config-inheritance
Open

fix(cli): respect server config for host and port during live reload#8380
fabiomartino wants to merge 1 commit intoionic-team:mainfrom
fabiomartino:fix/live-reload-config-inheritance

Conversation

@fabiomartino
Copy link

@fabiomartino fabiomartino commented Mar 6, 2026

Description

This PR implements a robust configuration inheritance system for the npx cap run --live-reload command. It allows the CLI to automatically detect and use the hostname, url, and port defined in the capacitor.config.ts file when they are not explicitly provided via command-line arguments.

Additionally, it ensures that the temporary server configuration generated for live reload is merged with the existing user configuration rather than overwriting it, preserving critical settings like custom schemes (e.g., androidScheme or iosScheme).

Change Type

  • Fix
  • Feature
  • Refactor
  • Breaking Change
  • Documentation

Rationale / Problems Fixed

As detailed in #8303, the current CLI behavior forces a default port of 3000 and ignores user-defined server settings during live reload. This creates significant friction for developers using modern bundlers (like Vite on 5173) who must manually pass flags for every run.

Key fixes in this PR:

  • Respects Configuration: CLI now looks at server.hostname and server.port (or parses server.url) as a secondary priority after CLI flags.
  • Preserves Custom Schemes: By performing a shallow merge of the server object in livereload.ts, settings like androidScheme or iosScheme are no longer lost when live reload is active.
  • Missing Type Definitions: Added the port property to the CapacitorConfig interface in declarations.ts, which was previously supported by the runtime but missing from the types.

Fixes #8303

Tests or Reproductions

Tested manually in a Capacitor + Vite project:

  1. Configured server: { port: 5173 } in capacitor.config.ts.
  2. Ran npx cap run android -l without specifying --port.
  3. Result: The app correctly connected to the dev server at port 5173.
  4. Verified that if --port 8080 is passed via CLI, it correctly takes precedence over the config file.
  5. Verified that androidScheme: 'https' in the config remains present in the temporary native config during the session.

Screenshots / Media

N/A

Platforms Affected

  • Android
  • iOS
  • Web

Notes / Comments

This PR provides a comprehensive fix for the issues described in #8303 and offers a more complete architectural solution than #8376 by aligning with the "Single Source of Truth" principle (respecting the project's centralized configuration).

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.

[Bug]: cap run ignores server config

1 participant