-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
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 tohttpinstead of the defaulthttps)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:
- fix(cli): Don't overwrite config.server section with
--live-reload#7528 — PR by @ZeroDX255 (Jul 2024): "fix(livereload): Don't overwrite the whole config.server section in editCapConfigForLiveReload function" — proposed exactly the spread-operator fix, but was closed without merge. - fix(cli): enable cleartext for live reload #7563 — PR by @jcesarmobile (merged Jul 2024): "fix(cli): enable cleartext for live reload" — only partially addressed the issue by adding
cleartext: trueto the replacement object, but still overwrites all other fields (androidScheme,allowNavigation, etc.). - feat: Make livereload use https if server.cleartext=false #7865 — Draft PR by @mofe23 (Feb 2025): "feat: Make livereload use https if server.cleartext=false" — related, still open.
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.