Skip to content

[Bug]: editCapConfigForLiveReload destructively replaces server object, stripping existing config fields #8352

@vidyu-ms

Description

@vidyu-ms

Capacitor Version

@capacitor/cli: 8.0.0
@capacitor/core: 8.0.0
@capacitor/android: 8.0.0
@capacitor/ios: 8.0.0

Bug also present on main branch as of June 2025.

Other API Details

  • Node: 24.13.0
  • macOS 15
  • Android Studio Meerkat 2024.3
  • Vite 6.2
  • Using capacitor.config.ts (TypeScript config)

Platforms Affected

  • iOS
  • Android
  • Web

Current Behavior

When running npx cap run android --live-reload --external, the editCapConfigForLiveReload function in cli/src/util/livereload.ts destructively replaces the entire server object in the native capacitor.config.json with just { url }.

This strips all other server fields, including:

  • androidScheme (needed when set to http instead of the default https)
  • cleartext (needed for HTTP connections on Android)
  • allowNavigation (needed for CORS/navigation rules)

Root cause in source code:

In cli/src/util/livereload.ts, editCapConfigForLiveReload does:

configJson.server = { url };

Similarly, editExtConfigForLiveReload does:

extConfigJson.server = { url };

Both assignments replace the entire server object rather than merging the url into the existing config.

Example:

Before live reload, native capacitor.config.json contains:

{
  "server": {
    "androidScheme": "http",
    "cleartext": true,
    "allowNavigation": ["*.meinestadt.de"]
  }
}

After editCapConfigForLiveReload, it becomes:

{
  "server": {
    "url": "http://localhost:8080"
  }
}

The androidScheme, cleartext, and allowNavigation fields are lost.

Expected Behavior

editCapConfigForLiveReload and editExtConfigForLiveReload should merge the url into the existing server object instead of replacing it:

// Instead of:
configJson.server = { url };

// Should be:
configJson.server = { ...configJson.server, url };

And similarly:

// Instead of:
extConfigJson.server = { url };

// Should be:
extConfigJson.server = { ...extConfigJson.server, url };

This preserves all existing server fields (androidScheme, cleartext, allowNavigation, etc.) while adding/overriding the url for live reload.

Project Reproduction

N/A — the bug is in the CLI internals (cli/src/util/livereload.ts), not in app code. It can be verified by reading the two assignment lines in editCapConfigForLiveReload and editExtConfigForLiveReload.

Additional Information

This bug has been reported before but was never properly fixed:

The root cause remains: editCapConfigForLiveReload and editExtConfigForLiveReload use assignment (=) instead of spread ({ ...existing, url }) when setting server. The fix is a one-line change in two places — happy to submit a PR.

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions