Skip to content

Commit a57efde

Browse files
fix(console): keep the browser copies of favorites, recents, last app and the pinned list view per organization (#36341)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbUq2j5tRRVo3TVY3wcS1Fdg)_ Fixes #36244 Clause-②: no Metadata-protocol: none ## 维护者速读 - 同时属于两个组织的用户,用同一个浏览器切换组织后,不再在新组织里先看到旧组织的收藏、最近访问、上次应用和固定视图;单组织与无组织部署的用户原有内容保留。 - 为个人设置清点中您接受的建议(p2):浏览器里的副本跟服务器一样按组织分开保存。 - 出错时最坏是某个组织里的收藏或固定视图首次显示为空、等服务器读回后恢复;不涉及他人数据,撤回本改动即回到原行为。 - 无。 ## What changes - `scopedKey(base, userId, orgId?)` (`UserStateAdapters`) spells `BASE:u:USER:o:ORG` when an organization is active; without one (no organization feature, a preview, the boot before an organization is known) it is the user-only key as before. - The organization is `ActiveOrganizationStorage`'s id, read synchronously (`useOrganizationScope`): the same id the console stamps on the `sys_user_preference` reads as `X-Tenant-ID`, and the one `switchOrganization` stores before the switch reloads the console, so the first paint after a switch reads the new organization's copy. - `FavoritesProvider`, `RecentItemsProvider`, `LastAppProvider`, `FlowPaletteRecentsProvider` read and write their browser copy under that key, and re-load when the organization changes. `FavoritesProvider`'s hydrate push-back now reads this organization's local copy, so it can only carry this organization's own nav-pin extras into its row. - The pinned list view (`list.view.pinned`) is read through `usePinnedListView` (new, `views/pinnedListView.ts`), whose slot is `os:pref:list.view.pinned@object:OBJECT@org:ORG`. Only this preference is keyed this way; the `os:pref` mechanism and every other workspace preference are unchanged. - **Carry-over rule (Done-when 4):** an organization that finds no copy of its own adopts the copy kept before the organization was part of the key (the user-only `ui.*` copy, and the per-object pin slot): the value moves under that organization's key and the old key is removed, so exactly one organization, the first to read it, inherits it. A single-organization person keeps everything; a deployment with no organization keeps the user-only key unchanged. The first reader is in practice the organization the old copy mirrors: every hydrate rewrote it with the active organization's row, and the first page-load on this code boots into the organization the browser last held. - Sign-out and change-of-user purges are keep-list sweeps (`purgeSignedOutUserClientState`, `@object-ui/auth`); the new keys are not on the keep list, so they are swept exactly as today's are. A pin in `signOutPurge.test.tsx` holds that for all five new spellings. - Round 2 (this head): the red `Type Check UI` / `Lint UI` (build) / `Test UI (8/16)` on `f957b6e1` had two causes, both read from the job logs before the fix. (1) `pinnedListView.ts(35,18): error TS2322` — the org slot was built from `objectPreferenceScope()`'s union and could spell `user@org:…`; it is now spelled `object:OBJECT@org:ORG` directly. (2) `FavoritesProvider.test.tsx` "favorites and a nav pin set in A …" read 21 ids — the suite above it leaves its last list under the user-only key, which org A then adopted as designed; the new suite's `beforeEach` now clears storage and resets the mocked user. No production behaviour changed in round 2. `origin/main` was merged once (`b3bcfefc`); it touched only one comment line in `workspacePreference.ts` among this diff's files. ## Tests Reach measured once, before the fix, by the round-1 dev with a unit harness (no running console with two memberships in this container): real `ActiveOrganizationStorage`, a fake server answering one `ui.favorites` row per stamped organization, favorite + nav pin in A, switch (remount) to B. On base `c30ce97c`: B's first paint `["object:a_obj","nav:a_menu"]` (A's list); B's server row after hydrate `["nav:a_menu"]` (A's nav pin pushed into B); pinned view read in B `"pv_in_org_a"`, back in A after pinning in B `"pv_in_org_b"`, one key `os:pref:list.view.pinned@object:crm_lead`. Both mechanisms reproduce. All readings below are on head `af1438fd`, under `scripts/pm/os-verify-lock.sh`. <details><summary>Committed pins — 6 files, 67 tests, green</summary> `cd ui && pnpm exec vitest run --maxWorkers=2` FavoritesProvider, RecentItemsProvider, FlowPaletteRecentsProvider, LastAppProvider, signOutPurge (context/__tests__) and views/pinnedListView-36244: `Test Files 6 passed (6)` · `Tests 67 passed (67)` · `VERDICT command-exit 0`. Neighbours that read the pin or the preference store (ObjectView.personalViews-29635, ObjectView.titleViewSwitcher-27594, consoleListStateWall-12418, consoleUserPreferenceBudget): `Test Files 4 passed (4)` · `Tests 45 passed (45)` · `VERDICT command-exit 0`. `ui/packages/app-shell` `pnpm run type-check` (both `tsc --noEmit` and `tsc -p tsconfig.test.json`): `VERDICT command-exit 0`, no `error TS`. </details> <details><summary>Four ablations — each red on its own pins, each restored to the HEAD blob</summary> Mutations through `scripts/ablation-replace.mjs` (WRAP mode: anchor must hit once, blob must change, restore proven by blob == HEAD and empty `git diff HEAD`). Same 6-file run each time; tests import `src` relatively, so no `dist/` leg applies. - A1 `scopedKey` ignores the organization (`UserStateAdapters.tsx`, blob `94bba20a → 67dd65bb`): `Tests 8 failed | 59 passed` — the per-organization and the adoption pins of all four providers. - A2 no adoption (`if (own !== null || !userId || !orgId) return own;` → unconditional return; blob `94bba20a → e9c51a34`): `Tests 4 failed | 63 passed` — the four "a single organization keeps the copy …" pins. The first A2 attempt was refused by the tool before anything ran (its replacement text already occurred in the anchor line, so the count did not rise); retried with a distinct replacement. - A3 pin slot ignores the organization (`pinnedListView.ts`, blob `b49631f8 → af9680b7`): `Tests 2 failed | 65 passed` — the round-trip pin and the single-organization pin. - A4 no pin adoption (blob `b49631f8 → 6f653efc`): `Tests 1 failed | 66 passed` — the single-organization pin. After the script: both files' blob equals `HEAD`'s (`94bba20a…`, `b49631f8…`), `git status` clean on both. </details> ## Acceptance notes - The `os:pref:*` pin slot carries no user. The organization in the slot does not change that, but a different account signing in on the same browser runs the change-of-user purge, which sweeps every key not on its keep list (all `os:pref:*` included), so a second account does not read the first's pin. - On a browser that holds no active organization yet (first boot, or after the server answered none), the copy is the user-only one until the organization resolves, then the organization adopts it; that boot window also costs one extra preference read when the organization arrives. - Quiet hours (`notificationPreferences`) still use the user-only key: out of this card. ## Verification Two-minute check: `cd ui && pnpm exec vitest run packages/app-shell/src/views/pinnedListView-36244.test.tsx` — 3 passing tests expected. Files to read first: `ui/packages/app-shell/src/context/UserStateAdapters.tsx` (`readScopedCopy`, `useOrganizationScope` — the adoption move), `ui/packages/app-shell/src/views/pinnedListView.ts` (slot spelling and pin adoption), `ui/packages/app-shell/src/context/FavoritesProvider.tsx` (hydrate push-back). <details><summary>Gates</summary> Local, `dispatch-gates --commands --repo objectstack-ai/objectstack` at `af1438fd`: 38 commands; 36 of the 37 non-vitest families exit 0 (exit captured before any pipe). `pnpm check:type-check-debt` exit 3 — its closure build queued past the lock budget (`VERDICT queue-timeout`), NOT MEASURED locally; CI's `Type Check · debt ledger` is success on this head. `pnpm --dir ui exec vitest run scripts/`: `Test Files 172 passed | 2 skipped (174)` · `Tests 5127 passed | 2 skipped`, `VERDICT command-exit 0`. `--ran` (with `:: exit` codes): `38 derived famil(ies) accounted for — 37 run, 1 NOT-MEASURED (1 DERIVED from a recorded exit 3)`. `overlap-check` before push: `VERDICT clean exit 0` (main and #36343, #36342 merge cleanly). CI on `af1438fd`: 52 check-runs, 39 success, 13 skipped, 0 failed — among them `Lint & Repo Gates`, `TypeScript Type Check`, `Test Core`, `Governed Surface Queue Guard`, `Lint UI`, `Type Check UI`, `Test UI`, `Build & E2E UI`, `Live E2E UI`, `Dogfood Regression Gate`, `Check Changeset`. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QsR2jV3scu6UYPb42n5okQ <!-- signed: repo:objectstack#7 · zhuangjianguo · session_01QsR2jV3scu6UYPb42n5okQ --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4e55e4e commit a57efde

15 files changed

Lines changed: 613 additions & 71 deletions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(console): favorites, recent items, the last app and the pinned list view are kept per organization in the browser
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A person's favorites, recent items, last app and flow palette recents are saved on the server per organization, but the console's browser copy of them was kept per user only. A person in two organizations who switched from A to B saw A's favorites, recent items and last app on B's first paint, and the nav pins set in A were merged into B's saved favorites. The browser copy is now kept per user and organization, under the organization the console stamps on its requests, so B paints and saves only B's own lists.
11+
12+
The pinned list view of an object (the 📌 in the list title's view switcher) was one browser slot per object, so a view pinned in A, which may be a personal view that exists only in A, was read in B and pinned over by B. It is now kept per organization as well: a pin set in A is still there on return to A, and B holds its own. The other per-browser list preferences (column widths, row height, tab order) are unchanged.
13+
14+
Nothing a person has is lost: the first organization that reads its copy takes over the copy kept before this change (once, after which the old copy is removed), so a person in a single organization keeps their favorites, recents, last app and pins as they were. A deployment without organizations keeps the per-user copy it always had.

‎ui/packages/app-shell/src/context/FavoritesProvider.tsx‎

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
* - localStorage stays in sync so offline / pre-auth sessions still work and
1313
* gives an instant first paint after sign-in.
1414
* - The local key is scoped per `user.id` so different accounts on the same
15-
* browser don't cross-contaminate.
15+
* browser don't cross-contaminate, and per active organization, like the
16+
* server row it mirrors, so one person's organizations don't either
17+
* (objectstack#36244).
1618
*
1719
* @module
1820
*/
@@ -30,7 +32,9 @@ import {
3032
import { useAuth } from '@object-ui/auth';
3133
import {
3234
createDebouncedFlush,
35+
readScopedCopy,
3336
scopedKey,
37+
useOrganizationScope,
3438
useStorageSync,
3539
useUserStateAdapter,
3640
} from './UserStateAdapters.js';
@@ -240,18 +244,18 @@ function withNamedOrder(
240244
return changed ? next : items;
241245
}
242246

243-
function loadFavorites(userId?: string | null): FavoriteItem[] {
247+
function loadFavorites(userId?: string | null, orgId?: string | null): FavoriteItem[] {
244248
try {
245-
const raw = localStorage.getItem(scopedKey(STORAGE_BASE_KEY, userId));
249+
const raw = readScopedCopy(STORAGE_BASE_KEY, userId, orgId);
246250
return raw ? JSON.parse(raw) : [];
247251
} catch {
248252
return [];
249253
}
250254
}
251255

252-
function saveFavorites(items: FavoriteItem[], userId?: string | null) {
256+
function saveFavorites(items: FavoriteItem[], userId?: string | null, orgId?: string | null) {
253257
try {
254-
localStorage.setItem(scopedKey(STORAGE_BASE_KEY, userId), JSON.stringify(items));
258+
localStorage.setItem(scopedKey(STORAGE_BASE_KEY, userId, orgId), JSON.stringify(items));
255259
} catch {
256260
// Storage full — silently ignore
257261
}
@@ -340,20 +344,22 @@ interface FavoritesProviderProps {
340344
export function FavoritesProvider({ children }: FavoritesProviderProps) {
341345
const { user } = useAuth();
342346
const userId = user?.id ?? null;
347+
const orgId = useOrganizationScope();
343348
const adapter = useUserStateAdapter<FavoriteItem>('favorites');
344349

345-
const [favorites, setFavorites] = useState<FavoriteItem[]>(() => loadFavorites(userId));
350+
const [favorites, setFavorites] = useState<FavoriteItem[]>(() => loadFavorites(userId, orgId));
346351

347-
// Re-load from localStorage whenever the active user changes (sign-in /
348-
// account switch). Prevents one account from seeing another's favorites.
352+
// Re-load from localStorage whenever the active user or organization
353+
// changes (sign-in / account switch / the organization becoming known).
354+
// Prevents one account, or one organization, from seeing another's favorites.
349355
useEffect(() => {
350-
setFavorites(loadFavorites(userId));
351-
}, [userId]);
356+
setFavorites(loadFavorites(userId, orgId));
357+
}, [userId, orgId]);
352358

353359
// Cross-tab sync: when another tab writes the same scoped key, mirror the
354360
// change locally. `storage` events do not fire in the tab that wrote them,
355361
// so this never echoes our own mutations.
356-
useStorageSync<FavoriteItem[]>(scopedKey(STORAGE_BASE_KEY, userId), value => {
362+
useStorageSync<FavoriteItem[]>(scopedKey(STORAGE_BASE_KEY, userId, orgId), value => {
357363
setFavorites(
358364
Array.isArray(value)
359365
? capByBucket(value.filter(it => it && typeof (it as any).id === 'string'))
@@ -383,8 +389,10 @@ export function FavoritesProvider({ children }: FavoritesProviderProps) {
383389

384390
// Re-read the local snapshot — it may contain nav-pin favorites that
385391
// were added (or migrated) before the adapter arrived. Without this
386-
// merge, signing in would silently wipe a user's offline pins.
387-
const local = loadFavorites(userId);
392+
// merge, signing in would silently wipe a user's offline pins. It is
393+
// THIS organization's copy, so the push-back below can only carry this
394+
// organization's own extras into its row (objectstack#36244).
395+
const local = loadFavorites(userId, orgId);
388396
const remoteNavIds = new Set(
389397
sane.filter(f => f.type === 'nav' && f.navId).map(f => f.navId!),
390398
);
@@ -406,7 +414,7 @@ export function FavoritesProvider({ children }: FavoritesProviderProps) {
406414
}
407415

408416
setFavorites(merged);
409-
saveFavorites(merged, userId);
417+
saveFavorites(merged, userId, orgId);
410418
if (pushBack) flusher.schedule(merged);
411419
} catch {
412420
// Keep localStorage state — adapter degrade-to-noop is acceptable.
@@ -415,7 +423,7 @@ export function FavoritesProvider({ children }: FavoritesProviderProps) {
415423
return () => {
416424
cancelled = true;
417425
};
418-
}, [adapter, userId]);
426+
}, [adapter, userId, orgId]);
419427

420428
// Offline / pre-auth migration: when there is no adapter to push to, fold
421429
// legacy nav-pins into the localStorage baseline immediately so the very
@@ -427,10 +435,10 @@ export function FavoritesProvider({ children }: FavoritesProviderProps) {
427435
const { migrated, didMigrate } = migrateLegacyNavPins(prev);
428436
if (!didMigrate) return prev;
429437
const next = capByBucket(migrated);
430-
saveFavorites(next, userId);
438+
saveFavorites(next, userId, orgId);
431439
return next;
432440
});
433-
}, [adapter, userId]);
441+
}, [adapter, userId, orgId]);
434442

435443
// Debounced write-through to backend.
436444
const flusher = useMemo(
@@ -444,10 +452,10 @@ export function FavoritesProvider({ children }: FavoritesProviderProps) {
444452

445453
const commit = useCallback(
446454
(next: FavoriteItem[]) => {
447-
saveFavorites(next, userId);
455+
saveFavorites(next, userId, orgId);
448456
if (adapter) flusher.schedule(next);
449457
},
450-
[userId, adapter, flusher],
458+
[userId, orgId, adapter, flusher],
451459
);
452460

453461
const addFavorite = useCallback(

‎ui/packages/app-shell/src/context/FlowPaletteRecentsProvider.tsx‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ import {
3434
import { useAuth } from '@object-ui/auth';
3535
import {
3636
createDebouncedFlush,
37+
readScopedCopy,
3738
scopedKey,
39+
useOrganizationScope,
3840
useStorageSync,
3941
useUserStateAdapter,
4042
} from './UserStateAdapters.js';
@@ -69,18 +71,18 @@ function sanitize(list: unknown): string[] {
6971
: [];
7072
}
7173

72-
function loadLocal(userId?: string | null): string[] {
74+
function loadLocal(userId?: string | null, orgId?: string | null): string[] {
7375
try {
74-
const raw = localStorage.getItem(scopedKey(STORAGE_BASE_KEY, userId));
76+
const raw = readScopedCopy(STORAGE_BASE_KEY, userId, orgId);
7577
return raw ? sanitize(JSON.parse(raw)) : [];
7678
} catch {
7779
return [];
7880
}
7981
}
8082

81-
function saveLocal(list: string[], userId?: string | null) {
83+
function saveLocal(list: string[], userId?: string | null, orgId?: string | null) {
8284
try {
83-
localStorage.setItem(scopedKey(STORAGE_BASE_KEY, userId), JSON.stringify(list));
85+
localStorage.setItem(scopedKey(STORAGE_BASE_KEY, userId, orgId), JSON.stringify(list));
8486
} catch {
8587
// storage full / privacy mode — recents are a nicety, never an error
8688
}
@@ -131,12 +133,15 @@ const FlowPaletteRecentsContext = createContext<FlowPaletteRecentsValue | null>(
131133
export function FlowPaletteRecentsProvider({ children }: { children: ReactNode }) {
132134
const { user } = useAuth();
133135
const userId = user?.id ?? null;
136+
// The browser copy is kept per organization, like the server row it mirrors
137+
// (objectstack#36244).
138+
const orgId = useOrganizationScope();
134139
const adapter = useUserStateAdapter<string>('flowPaletteRecents');
135140

136-
const [recents, setRecents] = useState<string[]>(() => loadLocal(userId));
141+
const [recents, setRecents] = useState<string[]>(() => loadLocal(userId, orgId));
137142

138143
// Cross-tab sync — see FavoritesProvider for the rationale.
139-
useStorageSync<string[]>(scopedKey(STORAGE_BASE_KEY, userId), (value) => {
144+
useStorageSync<string[]>(scopedKey(STORAGE_BASE_KEY, userId, orgId), (value) => {
140145
setRecents(sanitize(value));
141146
});
142147

@@ -151,10 +156,10 @@ export function FlowPaletteRecentsProvider({ children }: { children: ReactNode }
151156

152157
const commit = useCallback(
153158
(next: string[]) => {
154-
saveLocal(next, userId);
159+
saveLocal(next, userId, orgId);
155160
if (adapter) flusher.schedule(next);
156161
},
157-
[userId, adapter, flusher],
162+
[userId, orgId, adapter, flusher],
158163
);
159164

160165
// Hydrate (and fold legacy) on mount and whenever the user or attached
@@ -166,19 +171,19 @@ export function FlowPaletteRecentsProvider({ children }: { children: ReactNode }
166171
const token = ++hydrationToken.current;
167172
let cancelled = false;
168173
void (async () => {
169-
const local = loadLocal(userId);
174+
const local = loadLocal(userId, orgId);
170175
const remote = adapter ? sanitize(await adapter.load().catch(() => [])) : [];
171176
if (cancelled || token !== hydrationToken.current) return;
172177
const base = remote.length ? remote : local;
173178
const { list, didMigrate } = migrateLegacy(base, userId);
174179
setRecents(list);
175-
saveLocal(list, userId);
180+
saveLocal(list, userId, orgId);
176181
if (didMigrate && adapter) flusher.schedule(list);
177182
})();
178183
return () => {
179184
cancelled = true;
180185
};
181-
}, [adapter, userId, flusher]);
186+
}, [adapter, userId, orgId, flusher]);
182187

183188
const recordRecent = useCallback(
184189
(type: string) => {

‎ui/packages/app-shell/src/context/LastAppProvider.tsx‎

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ import {
3131
import { useAuth } from '@object-ui/auth';
3232
import {
3333
createDebouncedFlush,
34+
readScopedCopy,
3435
scopedKey,
36+
useOrganizationScope,
3537
useStorageSync,
3638
useUserStateAdapter,
3739
} from './UserStateAdapters.js';
@@ -57,18 +59,18 @@ function sanitize(value: unknown): string | null {
5759
return typeof first === 'string' && first ? first : null;
5860
}
5961

60-
function loadLocal(userId: string | null): string | null {
62+
function loadLocal(userId: string | null, orgId: string | null): string | null {
6163
try {
62-
const raw = localStorage.getItem(scopedKey(LAST_APP_PREFERENCE_KEY, userId));
64+
const raw = readScopedCopy(LAST_APP_PREFERENCE_KEY, userId, orgId);
6365
return raw ? sanitize(JSON.parse(raw)) : null;
6466
} catch {
6567
return null;
6668
}
6769
}
6870

69-
function saveLocal(name: string, userId: string | null) {
71+
function saveLocal(name: string, userId: string | null, orgId: string | null) {
7072
try {
71-
localStorage.setItem(scopedKey(LAST_APP_PREFERENCE_KEY, userId), JSON.stringify([name]));
73+
localStorage.setItem(scopedKey(LAST_APP_PREFERENCE_KEY, userId, orgId), JSON.stringify([name]));
7274
} catch {
7375
// storage full / privacy mode: the server row still carries it
7476
}
@@ -79,25 +81,29 @@ const LastAppContext = createContext<LastAppValue | null>(null);
7981
export function LastAppProvider({ children }: { children: ReactNode }) {
8082
const { user } = useAuth();
8183
const userId = user?.id ?? null;
84+
// The browser copy is kept per organization, like the server row it mirrors
85+
// (objectstack#36244): an app of one organization is no landing in another.
86+
const orgId = useOrganizationScope();
8287
// A list-shaped adapter, like every slot: the list holds the one name.
8388
const adapter = useUserStateAdapter<string>('lastApp');
8489

85-
const [local, setLocal] = useState<{ userId: string | null; name: string | null }>(() => ({
90+
const [local, setLocal] = useState<{ userId: string | null; orgId: string | null; name: string | null }>(() => ({
8691
userId,
87-
name: loadLocal(userId),
92+
orgId,
93+
name: loadLocal(userId, orgId),
8894
}));
8995
const [remote, setRemote] = useState<{ adapter: unknown; name: string | null } | null>(null);
9096
// A pick made in this session beats any read that lands after it.
9197
const picked = useRef<string | null>(null);
9298

93-
if (local.userId !== userId) {
94-
// Adjusted while rendering, on the signed-in user changing.
95-
setLocal({ userId, name: loadLocal(userId) });
99+
if (local.userId !== userId || local.orgId !== orgId) {
100+
// Adjusted while rendering, on the signed-in user or organization changing.
101+
setLocal({ userId, orgId, name: loadLocal(userId, orgId) });
96102
picked.current = null;
97103
}
98104

99-
useStorageSync<string[]>(scopedKey(LAST_APP_PREFERENCE_KEY, userId), (value) => {
100-
setLocal({ userId, name: sanitize(value) });
105+
useStorageSync<string[]>(scopedKey(LAST_APP_PREFERENCE_KEY, userId, orgId), (value) => {
106+
setLocal({ userId, orgId, name: sanitize(value) });
101107
});
102108

103109
const flusher = useMemo(
@@ -119,23 +125,25 @@ export function LastAppProvider({ children }: { children: ReactNode }) {
119125
if (cancelled) return;
120126
const name = sanitize(items);
121127
setRemote({ adapter, name });
122-
if (name && !picked.current) saveLocal(name, userId);
128+
if (name && !picked.current) saveLocal(name, userId, orgId);
123129
});
124130
return () => {
125131
cancelled = true;
126132
};
127-
}, [adapter, userId]);
133+
}, [adapter, userId, orgId]);
128134

129135
const rememberApp = useCallback(
130136
(name: string) => {
131137
if (!name) return;
132138
picked.current = name;
133-
setLocal((prev) => (prev.name === name && prev.userId === userId ? prev : { userId, name }));
134-
if (loadLocal(userId) === name && remote?.name === name) return;
135-
saveLocal(name, userId);
139+
setLocal((prev) =>
140+
prev.name === name && prev.userId === userId && prev.orgId === orgId ? prev : { userId, orgId, name },
141+
);
142+
if (loadLocal(userId, orgId) === name && remote?.name === name) return;
143+
saveLocal(name, userId, orgId);
136144
if (adapter) flusher.schedule([name]);
137145
},
138-
[userId, adapter, flusher, remote?.name],
146+
[userId, orgId, adapter, flusher, remote?.name],
139147
);
140148

141149
const remoteName = remote && remote.adapter === adapter ? remote.name : null;

0 commit comments

Comments
 (0)