Repository navigation
fix(mobile): apply saved home filters before the first render - #6484
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThe mobile home screen and new-chat flow now wait for persisted workspace filters and session preferences to hydrate before selecting projects, hosts, targets, or rendering the empty-workspace state. ChangesMobile hydration guards
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This localized change prevents saved home and session filters from being replaced by defaults during startup; no actionable merge-blocking risk remains beyond normal checks. Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The workspace filters (project / host / sort) and the composer's saved project/agent picks were already persisted to AsyncStorage, and they do come back — but rehydration is async and lands ~165ms after the store is created, so every consumer spends that window reading the defaults. On a cold start the home screen therefore resolves the first *online* host instead of the saved one, lists that host's most recently updated project instead of the filtered one, and fires the workspace/terminal/ project queries against it before swapping — which is what reads as "the filters reset on restart". The composer picks a default target over the last used one in the same window. Both stores now expose `hasHydrated`, flipped from `onRehydrateStorage` (including on read errors, so a failed read still falls back to the defaults). `useSelectedHost` returns null, `HomeScreen` holds its project pick and empty state, and `useNewChatTargets` holds its default target until storage has answered.
dcac9cb to
bb46174
Compare
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
What was wrong
Not a missing-persistence bug —
workspacesFilterStoreandnewSessionPreferencesStorewere already wrapped in zustandpersistover AsyncStorage, nothing resets them programmatically, and the values are written and do come back.It's lead #1: the async rehydration window. Instrumented on the simulator, a cold start looks like this:
For those ~165 ms every consumer reads the defaults, so the home screen resolves the first online host instead of the saved one, lists that host's most recently updated project instead of the filtered one, and fires the workspace / terminal / project queries against it before swapping. That is what reads as "the filters reset on restart". Whether the window is even visible depends on whether the auth session or AsyncStorage resolves first, which varies run to run.
Lead #2 (a stale projects/hosts list invalidating the saved id) was ruled out: nothing validates or clears the persisted id, and the only callers of the setters are the three filter screens.
newSessionPreferencesStorehas the identical bug — the composer picks a default target over the last used one in the same window, and a send landing there would create the workspace on the wrong project. Fixed too.The fix
Both stores expose
hasHydrated, flipped fromonRehydrateStorage— including on read errors, so a failed read falls back to the defaults instead of hanging. It's excluded frompartializeso it never reaches disk. Consumers wait on it:useSelectedHostreturnsnull(all four call sites already handle null)HomeScreenholds its project pick and suppresses the empty stateuseNewChatTargetsholds its default target until both stores have answeredVerification
On the iOS simulator, against
RCTAsyncLocalStorage_V1/manifest.jsonand the Metro console:xcrun simctl terminate booted sh.superset.mobile, relaunchhasHydratedflips with the saved values intact and never appears on diskCaveat: this simulator has no hosts/projects/workspaces (the worktree's local stack isn't running), so the project/host filter rows couldn't be visually confirmed against real data — those were verified at the store level (persisted values rehydrate and reach
HomeScreen's derivedselectedProjectId) plus the disk manifest.bun run lint:fixandbun run typecheckclean inapps/mobile(afterbuild:typesinpackages/host-service). Rootscripts/lint.shreports 2 errors, both in untouchedapps/desktopfiles inherited frommain; all four guard scripts pass.No tests added, per repo preference.
Summary by cubic
Apply saved home filters and composer preferences before the first render to remove the cold-start reset flash and prevent queries against the wrong host. Previously consumers read defaults until storage rehydrated (~165 ms) and resolved the first online host/project; now consumers wait for hydration.
Written for commit bb46174. Summary will update on new commits.
Summary by CodeRabbit