From 34ca7b1aabc9ce0e3f3a2b4891bc7e79014a679d Mon Sep 17 00:00:00 2001 From: Vincent Boucher Date: Mon, 27 Apr 2026 20:51:56 -0400 Subject: [PATCH] fix(ApiClient): respect force flag in init() to allow customServerUrl reload When a user changes the Server URL via login settings, the new URL is persisted to Capacitor Preferences but is not picked up by the API client until the app is force-stopped and reopened. Root cause: init(force) accepts a force flag intended to bypass the cached state and re-read customServerUrl from Preferences. However, the first check in the function returns the existing initPromise whenever it is set, regardless of whether force is true. After the first init, initPromise is a resolved promise; calling init(true) from LoginSettings returns this same resolved promise without ever invoking _doInit() again, so customServerURL is never updated. Fix: reset initPromise and initialized at the top of init() when force=true, so the subsequent checks fall through and _doInit() is invoked again to re-read Preferences. --- src/utils/ApiClient.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/utils/ApiClient.js b/src/utils/ApiClient.js index 1fa60afe..82e6cf8f 100644 --- a/src/utils/ApiClient.js +++ b/src/utils/ApiClient.js @@ -17,11 +17,16 @@ class ApiClient { } async init(force = false) { + if (force) { + this.initPromise = null + this.initialized = false + } + if (this.initPromise) { return this.initPromise } - if (this.initialized && !force) { + if (this.initialized) { return Promise.resolve() }