Skip to content

Bug 2024810 - Fixed last saved folder cache updating#215

Closed
fmasalha wants to merge 1 commit into
mozilla-firefox:autolandfrom
fmasalha:bookmarkLastSaveFix
Closed

Bug 2024810 - Fixed last saved folder cache updating#215
fmasalha wants to merge 1 commit into
mozilla-firefox:autolandfrom
fmasalha:bookmarkLastSaveFix

Conversation

@fmasalha

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions

Copy link
Copy Markdown
Contributor

View this pull request in Lando to land it once approved.

exitBookmarks()
}
val popped = getNavController().popBackStack()
lifecycleScope.launch {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scope was changed to be a cancel able scope in February which made the following code not run since exitBookmarks would destroy the fragment which cancels the lifecycleScope causing the last saved pref not to get updated.

@fmasalha fmasalha force-pushed the bookmarkLastSaveFix branch from 156f54a to 7bbf6ec Compare April 15, 2026 18:42
scope.launch(ioDispatcher) {
val parentGuid = settings.lastSavedFolderCache.getGuid() ?: BookmarkRoot.Mobile.id
val parentNode = bookmarksStorage.getBookmark(parentGuid).getOrNull()
val targetParentFolderId =

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add a bookmark star to the toolbar which didnt have the previously added safeguard to the menudialog.

@segunfamisa segunfamisa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR. I added a comment about something I think we should fix once-and for all, but also okay with having this as a follow-up

Comment on lines +494 to +504
val targetParentFolderId =
settings.lastSavedFolderCache.getGuid() ?: BookmarkRoot.Mobile.id

val parentNode = bookmarksStorage.getBookmark(targetParentFolderId).getOrNull()
?: bookmarksStorage.getBookmark(BookmarkRoot.Mobile.id).getOrNull()
val parentGuid = parentNode?.guid ?: BookmarkRoot.Mobile.id

if (targetParentFolderId != parentGuid) {
settings.lastSavedFolderCache.setGuid(null)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I think that we should fix this once and for-all, and make our AddBookmarksUseCase do all of this dance.

This is pretty much duplicated code from the MenuDialogMiddleware, doing the same thing.

// get the last saved folder id
val targetParentFolderId = lastSavedFolderCache.getGuid() ?: BookmarkRoot.Mobile.id
// get the corresponding bookmark and fallback to mobile root bookmark node
// this is necessary because it's possible that the last saved folder no longer exists (
// e.g. if the folder is removed through sync)
val parentNode = bookmarksStorage.getBookmark(targetParentFolderId).getOrNull()
?: bookmarksStorage.getBookmark(BookmarkRoot.Mobile.id).getOrNull()
val parentGuid = parentNode?.guid ?: BookmarkRoot.Mobile.id
val guidToEdit = addBookmarkUseCase(
url = url,
title = selectedTab.content.title,
parentGuid = parentGuid,
)

We discussed this in January and we all kinda agreed that we need to unify this functionality. I think this is a good opportunity to do so.

I also see that you clear the last saved folder cache if for some reason, the resolved parentGuid is not matching the last saved parent folder. That's a good improvement

So, instead of duplicating this logic, we could consider the following:

  1. Move LastSavedFolderCache somewhere in our bookmarks package or something
  2. Add it as a parameter to our AddBookmarksUsecase
  3. Move this logic into the use-case.
  4. Remove similar duplication that we do in various places
  5. Update tests.

I will say that we could land this to do this properly now, but that's what we said the last time 😂

Maybe @MatthewTighe & @boek can weight in here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I think this is a larger amount of work so I filed a follow up for this here https://bugzilla.mozilla.org/show_bug.cgi?id=2032600

@fmasalha

Copy link
Copy Markdown
Contributor Author

testing-tag explanation

The follow up work will streamline this approach to make it testable

https://bugzilla.mozilla.org/show_bug.cgi?id=2032600

lando-worker Bot pushed a commit that referenced this pull request Apr 17, 2026
@lando-worker

lando-worker Bot commented Apr 17, 2026

Copy link
Copy Markdown

Pull request closed by commit 5b47c78

@lando-worker lando-worker Bot closed this Apr 17, 2026
akliuxingyuan pushed a commit to fork-maintainers/iceraven-browser that referenced this pull request May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants