Skip to content

fix(mobile): apply saved home filters before the first render - #6484

Merged
saddlepaddle merged 1 commit into
mainfrom
mobile-filters-persist
Aug 14, 2026
Merged

saddlepaddle merged 1 commit into
mainfrom
mobile-filters-persist

Conversation

@saddlepaddle

@saddlepaddle saddlepaddle commented Aug 14, 2026 •

Copy link
Copy Markdown
Collaborator

What was wrong

Not a missing-persistence bug — workspacesFilterStore and newSessionPreferencesStore were already wrapped in zustand persist over 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:

[dbg] workspacesFilterStore module eval  +0ms
[dbg] rehydrate start                    +3ms
[dbg] HomeScreen render  {"projectFilter":null,  "selectedProjectId":null}   <- default
[dbg] HomeScreen render  {"projectFilter":null,  "selectedProjectId":null}   <- default
[dbg] raw workspaces-filter on disk:   +163ms  {"projectFilter":"…","hostFilter":"…","sort":"createdAt"}
[dbg] rehydrate done                   +164ms
[dbg] HomeScreen render  {"projectFilter":"…", "selectedProjectId":"…"}      <- correct

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.

newSessionPreferencesStore has 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 from onRehydrateStorage — including on read errors, so a failed read falls back to the defaults instead of hanging. It's excluded from partialize so it never reaches disk. Consumers wait on it:

  • useSelectedHost returns null (all four call sites already handle null)
  • HomeScreen holds its project pick and suppresses the empty state
  • useNewChatTargets holds its default target until both stores have answered

Verification

On the iOS simulator, against RCTAsyncLocalStorage_V1/manifest.json and the Metro console:

  • Set sort to "Date created" → written to disk
  • xcrun simctl terminate booted sh.superset.mobile, relaunch
  • Sort screen still shows "Date created" checked; hasHydrated flips with the saved values intact and never appears on disk

Caveat: 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 derived selectedProjectId) plus the disk manifest.

bun run lint:fix and bun run typecheck clean in apps/mobile (after build:types in packages/host-service). Root scripts/lint.sh reports 2 errors, both in untouched apps/desktop files inherited from main; 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.

  • Add hasHydrated to the workspaces filter store and the new-session preferences store; flip it in onRehydrateStorage (also on read errors) and exclude it from persistence.
  • HomeScreen defers selectedProjectId and suppresses the empty state until filters hydrate.
  • useSelectedHost returns null until the filter store hydrates.
  • useNewChatTargets defers defaultTarget until both stores hydrate to avoid creating a workspace on the wrong project.

Written for commit bb46174. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Improved home screen loading to prevent incorrect projects, workspaces, or hosts from appearing before saved preferences are restored.
    • Delayed empty-workspace messaging until workspace data and filters are fully ready.
    • Ensured new chats use the correct default target after preferences finish loading.
    • Improved handling of persisted filter settings when storage restoration encounters an error.

@coderabbitai

coderabbitai Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 84d2e71b-6cee-49ef-80d4-c85192575e49

📥 Commits

Reviewing files that changed from the base of the PR and between fef091a and dcac9cb.

📒 Files selected for processing (5)
  • apps/mobile/screens/(authenticated)/(home)/home/HomeScreen.tsx
  • apps/mobile/screens/(authenticated)/(home)/home/components/NewChatWidget/hooks/useNewChatTargets/useNewChatTargets.ts
  • apps/mobile/screens/(authenticated)/(home)/home/components/NewChatWidget/stores/newSessionPreferencesStore/newSessionPreferencesStore.ts
  • apps/mobile/screens/(authenticated)/(home)/home/stores/workspacesFilterStore/workspacesFilterStore.ts
  • apps/mobile/screens/(authenticated)/(home)/hooks/useSelectedHost/useSelectedHost.ts

📝 Walkthrough

Walkthrough

The 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.

Changes

Mobile hydration guards

Layer / File(s) Summary
Track persisted state hydration
apps/mobile/screens/(authenticated)/(home)/home/components/NewChatWidget/stores/..., apps/mobile/screens/(authenticated)/(home)/home/stores/...
The stores expose hasHydrated, exclude it from persisted data, and set it after rehydration.
Guard host and chat target selection
apps/mobile/screens/(authenticated)/(home)/hooks/..., apps/mobile/screens/(authenticated)/(home)/home/components/NewChatWidget/hooks/...
Host and new-chat target selection return null until the required stores hydrate, then recompute when hydration completes.
Defer home-screen rendering
apps/mobile/screens/(authenticated)/(home)/home/HomeScreen.tsx
Project selection and the empty-workspace state wait for workspace filter hydration.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to dcac9

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: kitenite

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title uses conventional commit format and clearly states that saved mobile home filters are applied before the first render.
Description check ✅ Passed The description explains the problem, implementation, verification, limitations, and tooling results, but omits the template's Checklist section.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mobile-filters-persist

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.
@saddlepaddle
saddlepaddle force-pushed the mobile-filters-persist branch from dcac9cb to bb46174 Compare August 14, 2026 21:51
@github-actions

github-actions Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ✅ Neon database branch

Thank you for your contribution! 🎉

This branch was previously deployed

1 inactive deployment
preview — bb461748 Deployed Aug 14, 2026 by saddlepaddle via Deploy Docs #7726
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant