fix: preserve paginated emails during background refresh#235
Merged
andrinoff merged 3 commits intofloatpane:masterfrom Mar 4, 2026
Merged
fix: preserve paginated emails during background refresh#235andrinoff merged 3 commits intofloatpane:masterfrom
andrinoff merged 3 commits intofloatpane:masterfrom
Conversation
EmailsRefreshedMsg was overwriting m.emailsByAcct and rebuilding m.emails from scratch, discarding any emails loaded via pagination. This caused a race where paginated emails appeared in the inbox list but could not be opened because they no longer existed in the main model's email store. Merge refreshed emails with existing paginated emails instead of replacing them. Also remove an unnecessary getEmailByUIDAndAccount lookup in ViewEmailMsg that silently blocked opening emails not yet in the store, and drop the unused email parameter from fetchEmailBodyCmd.
Keep the pre-fetch check to avoid unnecessary IMAP server calls for emails not in the local store. The merge fix in EmailsRefreshedMsg ensures paginated emails are preserved, so this guard now works correctly.
andrinoff
requested changes
Mar 4, 2026
Member
andrinoff
left a comment
There was a problem hiding this comment.
There is an issue, that when you open an email that was loaded, it closes after opening
Three interconnected issues caused the email view to auto-close when opening an email that was loaded via pagination: 1. The inbox's EmailsRefreshedMsg handler overwrote its internal email data with the raw (unmerged) refresh response, discarding paginated emails. Since main.go already merges the data and pushes it via SetEmails, the inbox handler now only clears the refreshing flag. 2. EmailsRefreshedMsg was forwarded to m.current twice: once at the top of Update (line 110) and again explicitly. This second call could target the wrong component or overwrite correctly merged data. Fixed by calling m.inbox.Update() directly to clear the refreshing state. 3. The EmailsFetchedMsg handler unconditionally set m.current = m.inbox, which would close the email view if a pagination fetch with offset 0 completed while the user was reading an email. Fixed by only switching to inbox from a loading screen, not from an active email view. Signed-off-by: drew <me@andrinoff.com>
andrinoff
approved these changes
Mar 4, 2026
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.
Summary
EmailsRefreshedMsgoverwritesm.emailsByAcctandm.emails, discarding emails loaded via paginationRoot Cause
When the user scrolls down to paginate,
EmailsAppendedMsgadds new emails to both the inbox's internal list andm.emails. However, the background refresh (EmailsRefreshedMsg) races with pagination and replacesm.emailsByAcctentirely with only the initial batch, wiping paginated emails fromm.emails. The inbox list still displays them, but pressing Enter fails because the email can no longer be found inm.emails.Fix
EmailsRefreshedMsgnow merges refreshed emails with existing paginated emails instead of replacing them. The same fix is applied to the sent mailbox path.Test plan
rto refresh while paginated emails are loaded — paginated emails preservedgo test ./...passesFixes #234