From 1b5e23e3d457cefad1a29fca92c88f19ea404eed Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Sat, 4 Apr 2026 11:21:56 +0200 Subject: [PATCH] fix: keep font settings visible during repo navigation - resetFiles() no longer clears userSettings so FontChange stays visible while navigating between repos (old fonts show until new ones load) - Add _requestId counter to setUserRepo() to discard stale async callbacks from previous navigations, preventing state corruption on quick nav - Load savedRepo and userSettings caches in parallel with Promise.all, reducing yield points so cache hits apply before first render Co-Authored-By: Claude Sonnet 4.6 --- src/modules/repo/store/userRepo.store.ts | 35 ++++++++++++++---------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/modules/repo/store/userRepo.store.ts b/src/modules/repo/store/userRepo.store.ts index 44a7958..1952763 100644 --- a/src/modules/repo/store/userRepo.store.ts +++ b/src/modules/repo/store/userRepo.store.ts @@ -20,6 +20,7 @@ interface State { readme?: string | null userSettings?: UserSettings | null needToLogin: boolean + _requestId: number } export const useUserRepoStore = defineStore("USER_REPO_STATE", { @@ -29,40 +30,44 @@ export const useUserRepoStore = defineStore("USER_REPO_STATE", { files: [], readme: undefined, userSettings: undefined, - needToLogin: false + needToLogin: false, + _requestId: 0 }), actions: { async setUserRepo(user: string, repo: string) { + const requestId = ++this._requestId this.user = user this.repo = repo const savedRepoId = data.generateId(DataType.SavedRepo, `${user}-${repo}`) - const cachedSavedRepo = await data.get( - savedRepoId - ) + const userSettingsId = `UserSetting-${user}-${repo}` + + const [cachedSavedRepo, cachedUserSettings] = await Promise.all([ + data.get(savedRepoId), + data.get(userSettingsId) + ]) + + if (requestId !== this._requestId) return if (cachedSavedRepo) { this.files = cachedSavedRepo.files } + if (cachedUserSettings) { + this.userSettings = cachedUserSettings + } + try { await refreshToken() } catch (error) { console.warn("impossible to refresh token", error) } - const userSettingsId = `UserSetting-${user}-${repo}` - const cachedUserSettings = await data.get< - DataType.UserSettings, - UserSettings - >(userSettingsId) - - if (cachedUserSettings) { - this.userSettings = cachedUserSettings - } + if (requestId !== this._requestId) return getFiles(user, repo) .then(async (files) => { + if (requestId !== this._requestId) return data.update({ _id: savedRepoId, $type: DataType.SavedRepo, @@ -74,6 +79,7 @@ export const useUserRepoStore = defineStore("USER_REPO_STATE", { return getUserSettingsContent(user, repo, files) }) .then((userSettings) => { + if (requestId !== this._requestId) return const chosenFontFamily = userSettings?.fontFamilies?.find( (font) => font === this.userSettings?.chosenFontFamily ) @@ -109,6 +115,7 @@ export const useUserRepoStore = defineStore("USER_REPO_STATE", { }) getCachedMainReadme(user, repo).then(async (cachedReadme) => { + if (requestId !== this._requestId) return this.readme = cachedReadme this.readme = await getMainReadme(user, repo) }) @@ -142,11 +149,11 @@ export const useUserRepoStore = defineStore("USER_REPO_STATE", { this.user = "" this.repo = "" this.resetFiles() + this.userSettings = undefined }, resetFiles() { this.files = [] this.readme = null - this.userSettings = undefined }, setFontFamily(fontFamily: string) { if (!this.userSettings) {