Keep bookmark search results when a folder deletion is committed - #9728
Open
mnlmato wants to merge 1 commit into
Open
Keep bookmark search results when a folder deletion is committed#9728mnlmato wants to merge 1 commit into
mnlmato wants to merge 1 commit into
Conversation
The bookmarks screen had two producers writing to _itemsToDisplay: the folder scoped Flow, collected in a coroutine that was never cancelled, and the full tree loaded when the search bar opens. Committing a pending folder deletion made the still active folder collector re-emit and overwrite the search list with the current folder contents, leaving the search empty. Both sources now go through a single displayItemsFrom, whose collection is held in a ConflatedJob, so switching source cancels the previous one. The hidden ids filter applies to both, keeping folders pending deletion out of the search results. Fixes duckduckgo#6062
mnlmato
force-pushed
the
fix/mnlmato/bookmarks-search-after-folder-delete
branch
from
September 5, 2026 20:17
f84fa4f to
952f3b0
Compare
mnlmato
marked this pull request as ready for review
September 5, 2026 20:23
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.
Task/Issue URL: #6062
Tech Design URL (if applicable):
API Proposals URL(s) (if applicable): None
Description
BookmarksViewModelhad two producers writing to the same_itemsToDisplay:fetchBookmarksAndFolders(parentId)collectsgetSavedSites(parentId)in a coroutine that is never cancelled, and a new collector is added every time the search bar is closed.fetchAllBookmarksAndFolders(), called when the search bar opens, overwrites that same state with the whole tree.Deleting a folder is only committed to the database when the undo snackbar is dismissed. That write makes the still active folder scoped collector re-emit and overwrite the search list with the current folder contents, which are now empty, so the search shows no results at all. It is also why the failure only reproduces when the search bar is opened while the snackbar is still on screen.
Both sources now go through a single
displayItemsFrom(source: Flow<SavedSites>)that owns the displayed list and holds its collection in aConflatedJob, so switching source cancels the previous one. The hidden ids filtering that already existed for the folder listing now applies to both sources, which also keeps folders pending deletion out of the search results (the stale folder half of #5671).Two unit tests were added to
BookmarksViewModelTest; both fail ondevelopand pass with this change. The 45 existing tests are untouched and still pass. No public API is touched.While investigating I found an adjacent issue that I deliberately left out of this PR:
BookmarksActivity.observeItemsToDisplay()pushes list updates straight to the adapter without re-applying the current query, so any update that lands while the search bar is open repaints the unfiltered list. That behaviour predates this change and lives in a different layer. Happy to follow up separately if you would like it addressed.Steps to test this PR
Search results survive a folder deletion being committed
UI changes
before-search-cleared-when-snackbar-expires.mp4
after-search-preserved-when-snackbar-expires.mp4
Note
Medium Risk
Scoped to bookmarks UI state and coroutine lifecycle; behavior changes when toggling search and during deferred deletes, but no API or persistence changes.
Overview
Fixes bookmark search clearing when an undo snackbar times out during search. Folder-scoped and whole-tree bookmark loading both wrote to
itemsToDisplay; the folderFlowkept collecting after search opened, so a committed folder delete re-emitted and replaced the search list with empty folder contents.Both
fetchBookmarksAndFoldersandfetchAllBookmarksAndFoldersnow feed a shareddisplayItemsFrompath backed byConflatedJob, so switching modes cancels the prior collector and only one source owns the list. The existinghiddenIdsfilter is applied in that path for both sources, so folders pending deletion stay out of search results. Favicon prompt logic moves toonStarton the folder flow.Two
BookmarksViewModelTestcases cover search surviving folder delete and hiding pending-delete folders while searching.Reviewed by Cursor Bugbot for commit 952f3b0. Bugbot is set up for automated code reviews on this repo. Configure here.