fix(ApiClient): respect force flag in init() to allow customServerUrl reload#96
Open
VBoucher wants to merge 1 commit into
Open
fix(ApiClient): respect force flag in init() to allow customServerUrl reload#96VBoucher wants to merge 1 commit into
VBoucher wants to merge 1 commit into
Conversation
… 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.
Author
|
Note: this code was done by Claude Code. Review is necessary. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
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.
This results in confusing UX: the user updates their self-hosted server URL, taps Save, then attempts to log in — and gets
Login Failedbecause the request is still being sent to the previous URL (e.g. the defaultAPI_URL).Root cause
ApiClient.init(force)accepts aforceflag intended to bypass the cached state and re-readcustomServerUrlfrom Preferences. However, the first check in the function returns the existinginitPromisewhenever it is set, regardless of whetherforceistrue:After the first init,
initPromiseis a resolved promise that resolves with the original URL. Callinginit(true)fromLoginSettings.jsxafter the user updates the server URL returns this same resolved promise without ever invoking_doInit()again — socustomServerURLis never updated and subsequent requests keep going to the old URL.Fix
Reset
initPromiseandinitializedat the top ofinit()whenforce=true, so the subsequent checks fall through and_doInit()is invoked again to re-read Preferences.Reproduction
customServerUrlpreviously set to default (or empty)After this fix, step 4 succeeds without needing to force-stop.
Diff
src/utils/ApiClient.js: +5 / -1 lines.