The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 24, 00:15 UTC
fix(mobile): preserve multiple model favorites (#12505)
Julius Marminge committed
Sep 18, 2026 at 14:23 UTC
82cd1d1aabe8baa4a5ae23f3c7b08b3fce092e08
3 files changed
+63
-19
apps/mobile/src/features/threads/ThreadSettingsSheet.tsx
+8
-7
@@ -47,7 +47,6 @@ import type { ModelOption, ProviderGroup } from "../../lib/modelOptions";
47
import { applyProviderOptionSelection } from "../../lib/providerOptions";
48
import { resolveProviderOptionDescriptors } from "../../lib/providerOptions";
49
import { useUniwindTheme } from "../../lib/useUniwindTheme";
50
-import type { Preferences } from "../../persistence/mobile-preferences";
50
import {
51
NativeHeaderToolbar,
52
NativeStackScreenOptions,
@@ -331,12 +330,14 @@ function ThreadSettingsSessionProvider(
330
(option: ModelOption) => {
331
if (!favoritesLoaded) return;
332
void Haptics.selectionAsync();
334
- savePreferences((current: Preferences) => ({
335
- modelFavorites: toggleModelFavorite(
336
- current.modelFavorites ?? EMPTY_MODEL_FAVORITES,
337
- option,
338
- ),
339
- }));
333
+ savePreferences({
334
+ transform: (current) => ({
335
+ modelFavorites: toggleModelFavorite(
336
+ current.modelFavorites ?? EMPTY_MODEL_FAVORITES,
337
+ option,
338
+ ),
339
+ }),
340
+ });
341
},
342
[favoritesLoaded, savePreferences],
343
);
apps/mobile/src/state/preferences.test.ts
+45
-8
@@ -5,6 +5,9 @@ import * as Option from "effect/Option";
5
import { AsyncResult, Atom, AtomRegistry } from "effect/unstable/reactivity";
6
import { vi } from "vite-plus/test";
7
import { ProviderInstanceId } from "@t3tools/contracts";
8
+import { RegistryContext, useAtomSet } from "@effect/atom-react";
9
+import { createElement } from "react";
10
+import { renderToString } from "react-dom/server";
11
12
vi.mock("expo-secure-store", () => ({
13
getItemAsync: vi.fn(),
@@ -125,12 +128,16 @@ describe("mobile preferences state", () => {
128
}),
129
);
130
128
- it.effect("keeps both favorites when updates are sent before a render", () =>
131
+ it.effect("keeps both favorites when the React setter sends updates before a render", () =>
132
Effect.gen(function* () {
133
let persisted: Preferences = { modelFavorites: [] };
134
const state = makePreferencesState({
135
load: Effect.succeed(persisted),
133
- savePatch: () => Effect.die(new Error("Favorite updates must use a transform.")),
136
+ savePatch: (patch) =>
137
+ Effect.sync(() => {
138
+ persisted = { ...persisted, ...patch };
139
+ return persisted;
140
+ }),
141
update: (transform) =>
142
Effect.sync(() => {
143
persisted = { ...persisted, ...transform(persisted) };
@@ -142,13 +149,31 @@ describe("mobile preferences state", () => {
149
const unmountUpdate = registry.mount(state.updatePreferencesAtom);
150
yield* AtomRegistry.getResult(registry, state.preferencesAtom, { suspendOnWaiting: true });
151
152
+ function useSavePreferences() {
153
+ return useAtomSet(state.updatePreferencesAtom);
154
+ }
155
+ const setters: Array<ReturnType<typeof useSavePreferences>> = [];
156
+ function CaptureSetter() {
157
+ setters.push(useSavePreferences());
158
+ return null;
159
+ }
160
+ // Exercise the real React setter, which treats bare functions as updates
161
+ // to the atom's read value. Direct registry.set calls bypass that behavior.
162
+ renderToString(
163
+ createElement(RegistryContext.Provider, { value: registry }, createElement(CaptureSetter)),
164
+ );
165
+ const savePreferences = setters[0]!;
166
const provider = ProviderInstanceId.make("codex");
146
- registry.set(state.updatePreferencesAtom, (current) => ({
147
- modelFavorites: [...(current.modelFavorites ?? []), { provider, model: "astra" }],
148
- }));
149
- registry.set(state.updatePreferencesAtom, (current) => ({
150
- modelFavorites: [...(current.modelFavorites ?? []), { provider, model: "sol" }],
151
- }));
167
+ savePreferences({
168
+ transform: (current) => ({
169
+ modelFavorites: [...(current.modelFavorites ?? []), { provider, model: "astra" }],
170
+ }),
171
+ });
172
+ savePreferences({
173
+ transform: (current) => ({
174
+ modelFavorites: [...(current.modelFavorites ?? []), { provider, model: "sol" }],
175
+ }),
176
+ });
177
yield* AtomRegistry.getResult(registry, state.updatePreferencesAtom, {
178
suspendOnWaiting: true,
179
});
@@ -158,6 +183,18 @@ describe("mobile preferences state", () => {
183
{ provider, model: "sol" },
184
]);
185
186
+ savePreferences({
187
+ transform: (current) => ({
188
+ modelFavorites: (current.modelFavorites ?? []).filter(
189
+ (favorite) => favorite.model !== "astra",
190
+ ),
191
+ }),
192
+ });
193
+ yield* AtomRegistry.getResult(registry, state.updatePreferencesAtom, {
194
+ suspendOnWaiting: true,
195
+ });
196
+ expect(persisted.modelFavorites).toEqual([{ provider, model: "sol" }]);
197
+
198
unmountUpdate();
199
unmountPreferences();
200
registry.dispose();
apps/mobile/src/state/preferences.ts
+10
-4
@@ -15,7 +15,11 @@ interface OptimisticPreferences {
15
readonly versions: Partial<Record<keyof Preferences, number>>;
16
}
17
18
-type PreferencesUpdate = Partial<Preferences> | ((current: Preferences) => Partial<Preferences>);
18
+// A bare function is interpreted by useAtomSet as an update to the command's
19
+// AsyncResult, not as a preference transform. Keep transforms inside a payload.
20
+type PreferencesUpdate =
21
+ | Partial<Preferences>
22
+ | { readonly transform: (current: Preferences) => Partial<Preferences> };
23
24
/**
25
* Owns the device preference blob for the lifetime of the app registry.
@@ -62,8 +66,10 @@ export function createMobilePreferencesState(runtime: Atom.AtomRuntime<MobilePre
66
(update: PreferencesUpdate, get) => {
67
const currentPreferences = get(preferencesAtom);
68
const patch =
65
- typeof update === "function"
66
- ? update(AsyncResult.isSuccess(currentPreferences) ? currentPreferences.value : {})
69
+ "transform" in update
70
+ ? update.transform(
71
+ AsyncResult.isSuccess(currentPreferences) ? currentPreferences.value : {},
72
+ )
73
: update;
74
const version = ++nextPatchVersion;
75
const current = get(optimisticPatchAtom);
@@ -77,7 +83,7 @@ export function createMobilePreferencesState(runtime: Atom.AtomRuntime<MobilePre
83
});
84
return MobilePreferencesStore.pipe(
85
Effect.flatMap((store) =>
80
- typeof update === "function" ? store.update(update) : store.savePatch(patch),
86
+ "transform" in update ? store.update(update.transform) : store.savePatch(patch),
87
),
88
Effect.tap((saved) =>
89
Effect.sync(() => {