[TW-6425] fix(@ownmail/app): refresh mutable draft and mailbox state - #269
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b04b70a551
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| queryClient.setQueryData(mailboxInfoQueryOptions().queryKey, { | ||
| ...info, | ||
| displayName: account.displayName, | ||
| }) |
There was a problem hiding this comment.
Avoid refreshing the cache from stale Settings data
When the user changes only a browser preference, account is built from persistedDisplayName without contacting the server, but this unconditional write marks the loader's mailbox snapshot fresh. If the display name changed on another device after Settings loaded, navigating to Mail now reuses the old name instead of fetching the current mailbox info; update this cache only after a display-name mutation, or invalidate/refetch it for preference-only saves.
Useful? React with 👍 / 👎.
Summary
@ownmail/apppatch changesetRoot cause
Mail-version synchronization correctly invalidates inactive draft-detail queries after external changes. The compose loader used
ensureQueryData, which returns any cached entry without awaiting a refetch, including an invalidated entry. Compose then initialized local editor state from that stale value and did not subscribe to the draft query, so reopening and saving could overwrite newer server content.Mailbox information was also mutable but modeled as immutable. The Mail parent route and its mailbox-info query both used infinite staleness, while Mail rendered the loader snapshot directly. Settings saved the display name to the server and browser preferences without updating that query, so AppRailNav continued receiving the old nonempty server name and never reached its browser-preference fallback.
The compose loader now uses
fetchQuery, which reuses fresh entries but awaits stale or invalidated ones. Mail now observes a shared mailbox-info query with a 30-second freshness window, and Settings writes the authoritative save result into that cache immediately.Impact
Drafts changed in another tab or device reopen with current server content. Display-name changes appear in Mail immediately after saving Settings and remain revalidatable for external account changes.
Validation
pnpm --filter @ownmail/app test— 1,898 tests passed, 100% coveragepnpm --filter @ownmail/app typecheckpnpm --filter @ownmail/app build:nodepnpm --filter @ownmail/app smoke:ssrpnpm lint— 0 warningspnpm commit:check -- .git/COMMIT_EDITMSGFollow-up to #267.
Jira: TW-6425