Repository navigation
Conversation
The theme, text scale, text weight, high contrast, custom theme variable and custom CSS caches in localStorage were untagged, so on a shared browser a second account inherited the first account's appearance: with no server value of its own, every fallback resolved to whatever the previous account had stored, and the leftover `silo-theme` key also suppressed the admin-configured default theme for the new account. DateTimeFormatProvider already solved this by stamping its cache with the authenticated user id and refusing another account's values. Extract that mechanism into `createOwnedCache` in utils/storage.ts (where key namespacing lives) and put all three groups behind it, so appearance and custom theme get the same protection instead of a third copy of the rule. - Each group carries its own owner stamp. A shared stamp would be unsafe: the groups are written by hooks nested inside each other, and effects run inner-first, so whichever hook stamped first would vouch for the other's still-stale values. - A null owner (auth bootstrapping, or signed out) still trusts the cache, which keeps the warm start and the login screen's last look. - An unstamped cache is not trusted once an account is known, so existing users take a one-time appearance reset on first load rather than a chance of seeing someone else's settings. - When a foreign cache is detected the values are dropped and the empty cache is handed to the new account, so a later single save cannot re-trust the rest of the previous account's state. Owner is the user id because /settings is user-scoped server side; it lives in one helper (`appearanceCacheOwner`) so it can be widened if appearance moves to profile scope. `shouldLoadApiTheme` is gone: it had become a synonym for `appearanceCacheOwner(...) !== null` with no callers left. Part of #376 AI-use disclosure: implemented with Claude Code. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
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
A second account signing in on the same browser inherits the first account's appearance until it saves its own value. Theme, text scale, text weight, high contrast, custom theme variables, and custom CSS are all read from
localStoragewith no check on who stored them, and are kept when the newly authenticated account has no server value.Incognito is not the leaking case — it starts with an empty cache. The bug is two accounts in one regular browser profile.
Verified finding from #376 (P2).
Fix
useDateTimeFormatalready solved this correctly by tagging its warm cache with the authenticated user ID and rejecting another account's cache. This extracts that mechanism instead of copy-pasting it a third time.createOwnedCache(ownerKey, memberKeys)inweb/src/utils/storage.tsexposesisTrusted/get/set/clear:setstamps;cleardrops every member key and hands an empty cache to the new owner.Three instances:
appearanceCache,customThemeCache, anddateTimeFormatCache(reusing the existing owner key so nobody loses their warm start). The groups keep separate stamps on purpose — they are written by hooks nested inside one another and React runs effects inner-first, so one shared stamp would let whichever hook resolved first vouch for the other's still-stale values.useTheme.tsxanduseCustomTheme.tsderive an owner, read trust once per render before any effect re-stamps, gate everyapiValue ?? localValuefallback on it, and clear + reset to defaults when the cache belongs to another account. That also restores the admin default theme for the new account, which a leftoversilo-themekey was suppressing.useDateTimeFormat.tsxis refactored onto the shared mechanism with no behavior change.Verification
pnpm exec vitest run src/hooks src/utils→ 36 files, 148 tests passpnpm exec tsc -b→ cleanpnpm run format:check→ cleanpnpm run lint→ 0 errors, 160 warnings (same count asmain)expected 'large' to be 'default',expected 'cobalt-studio' to be null, admin default not applied).pnpm testhas 6 pre-existing failures inSeasonContent.test.tsxandServerStorageStep.test.tsx, allNo QueryClient set. Confirmed pre-existing by stashing the whole change and re-running; neither file touches theme, appearance, or storage.Known limits
useDateTimeFormatalready shipped; stamping the existing cache with whoever signs in first would reintroduce the leak./settings. Household profiles share auser_id, so profile switching still shares the cache. docs: define cross-platform user settings contract #377 moves appearance to profile scope — that is a one-line change inappearanceCacheOwner().Part of #376.
AI-use disclosure
Implemented with AI assistance (Claude Opus 5) under maintainer direction, and independently re-verified (tests, tsc, lint, format re-run; ownership logic read against the shipped
useDateTimeFormatpattern).