Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.0.0rc1 - "Open link in new tab" opening out of position #1102

Closed
DonKatsu opened this issue Jul 12, 2023 · 8 comments
Closed

5.0.0rc1 - "Open link in new tab" opening out of position #1102

DonKatsu opened this issue Jul 12, 2023 · 8 comments

Comments

@DonKatsu
Copy link

Steps to reproduce

  • Open Firefox in new profile
  • Install Sidebery 5.0.0rc1
  • "Open link in new tab" (or middle click URL) with multiple open/collapsed trees

Expected behavior

New child tabs visually appear in their tree.

Actual behavior

New child tabs visually appear out of their tree, but are still properly attached to their parent tab.
Collapsing and expanding any tree corrects their position.

Noticed this today after automatically updating to 5.0.0rc1. The issue is not present if downgraded to 5.0.0b33.
Some visual examples on a new profile: Single trees. Nested trees.

Debug info

Addon data
{
  "addonVersion": "5.0.0rc1",
  "firefoxVersion": "115.0",
  "settings": {
    "nativeScrollbars": true,
    "nativeScrollbarsThin": true,
    "nativeScrollbarsLeft": false,
    "selWinScreenshots": false,
    "updateSidebarTitle": true,
    "markWindow": false,
    "markWindowPreface": "[Sidebery] ",
    "ctxMenuNative": false,
    "ctxMenuRenderInact": true,
    "ctxMenuRenderIcons": true,
    "ctxMenuIgnoreContainers": "",
    "navBarLayout": "horizontal",
    "navBarInline": true,
    "navBarSide": "left",
    "hideAddBtn": false,
    "hideSettingsBtn": false,
    "navBtnCount": true,
    "hideEmptyPanels": true,
    "hideDiscardedTabPanels": false,
    "navActTabsPanelLeftClickAction": "none",
    "navActBookmarksPanelLeftClickAction": "none",
    "navTabsPanelMidClickAction": "discard",
    "navBookmarksPanelMidClickAction": "none",
    "navSwitchPanelsWheel": true,
    "subPanelRecentlyClosedBar": true,
    "subPanelBookmarks": true,
    "subPanelHistory": true,
    "groupLayout": "grid",
    "skipEmptyPanels": false,
    "dndTabAct": true,
    "dndTabActDelay": 750,
    "dndTabActMod": "none",
    "dndExp": "pointer",
    "dndExpDelay": 750,
    "dndExpMod": "none",
    "dndOutside": "win",
    "dndActTabFromLink": true,
    "dndActSearchTab": true,
    "dndMoveTabs": false,
    "dndMoveBookmarks": false,
    "searchBarMode": "dynamic",
    "searchBookmarksShortcut": "",
    "searchHistoryShortcut": "",
    "warnOnMultiTabClose": "collapsed",
    "activateLastTabOnPanelSwitching": true,
    "activateLastTabOnPanelSwitchingLoadedOnly": true,
    "switchPanelAfterSwitchingTab": "always",
    "tabRmBtn": "hover",
    "hideInact": false,
    "activateAfterClosing": "next",
    "activateAfterClosingStayInPanel": false,
    "activateAfterClosingGlobal": false,
    "activateAfterClosingNoFolded": true,
    "activateAfterClosingNoDiscarded": true,
    "askNewBookmarkPlace": true,
    "tabsRmUndoNote": true,
    "nativeHighlight": false,
    "tabsUnreadMark": false,
    "tabsUpdateMark": "all",
    "tabsUpdateMarkFirst": true,
    "tabsReloadLimit": 5,
    "tabsReloadLimitNotif": true,
    "showNewTabBtns": true,
    "newTabBarPosition": "after_tabs",
    "tabsPanelSwitchActMove": false,
    "tabsPanelSwitchActMoveAuto": true,
    "tabsUrlInTooltip": "full",
    "openSubPanelOnMouseHover": false,
    "selectActiveTabFirst": true,
    "newTabCtxReopen": false,
    "moveNewTabPin": "start",
    "moveNewTabParent": "last_child",
    "moveNewTabParentActPanel": false,
    "moveNewTab": "end",
    "moveNewTabActivePin": "start",
    "pinnedTabsPosition": "panel",
    "pinnedTabsList": false,
    "pinnedAutoGroup": false,
    "pinnedNoUnload": false,
    "tabsTree": true,
    "groupOnOpen": true,
    "tabsTreeLimit": "none",
    "hideFoldedTabs": false,
    "hideFoldedParent": "none",
    "autoFoldTabs": false,
    "autoFoldTabsExcept": "none",
    "autoExpandTabs": false,
    "autoExpandTabsOnNew": false,
    "rmChildTabs": "none",
    "tabsChildCount": true,
    "tabsLvlDots": true,
    "discardFolded": false,
    "discardFoldedDelay": 0,
    "discardFoldedDelayUnit": "sec",
    "tabsTreeBookmarks": true,
    "treeRmOutdent": "branch",
    "ignoreFoldedParent": false,
    "colorizeTabs": false,
    "colorizeTabsSrc": "domain",
    "colorizeTabsBranches": false,
    "colorizeTabsBranchesSrc": "url",
    "inheritCustomColor": true,
    "warnOnMultiBookmarkDelete": "collapsed",
    "autoCloseBookmarks": false,
    "autoRemoveOther": false,
    "highlightOpenBookmarks": false,
    "activateOpenBookmarkTab": false,
    "showBookmarkLen": true,
    "bookmarksRmUndoNote": true,
    "loadBookmarksOnDemand": true,
    "pinOpenedBookmarksFolder": true,
    "oldBookmarksAfterSave": "ask",
    "loadHistoryOnDemand": true,
    "fontSize": "m",
    "animations": true,
    "animationSpeed": "norm",
    "theme": "proton",
    "density": "default",
    "colorScheme": "ff",
    "sidebarCSS": false,
    "groupCSS": false,
    "snapNotify": true,
    "snapExcludePrivate": false,
    "snapInterval": 0,
    "snapIntervalUnit": "min",
    "snapLimit": 0,
    "snapLimitUnit": "snap",
    "snapAutoExport": false,
    "snapAutoExportType": "json",
    "snapAutoExportPath": "Sidebery/snapshot-%Y.%M.%D-%h.%m.%s",
    "snapMdFullTree": false,
    "hScrollAction": "none",
    "navSwitchPanelsDelay": 128,
    "scrollThroughTabs": "none",
    "scrollThroughVisibleTabs": true,
    "scrollThroughTabsSkipDiscarded": true,
    "scrollThroughTabsExceptOverflow": true,
    "scrollThroughTabsCyclic": false,
    "scrollThroughTabsScrollArea": 0,
    "autoMenuMultiSel": true,
    "multipleMiddleClose": false,
    "longClickDelay": 500,
    "wheelThreshold": false,
    "wheelThresholdX": 10,
    "wheelThresholdY": 60,
    "tabDoubleClick": "none",
    "tabsSecondClickActPrev": true,
    "tabsSecondClickActPrevPanelOnly": false,
    "shiftSelAct": true,
    "activateOnMouseUp": false,
    "tabLongLeftClick": "none",
    "tabLongRightClick": "none",
    "tabCloseMiddleClick": "close",
    "tabsPanelLeftClickAction": "none",
    "tabsPanelDoubleClickAction": "tab",
    "tabsPanelRightClickAction": "menu",
    "tabsPanelMiddleClickAction": "tab",
    "newTabMiddleClickAction": "new_child",
    "bookmarksLeftClickAction": "open_in_act",
    "bookmarksLeftClickActivate": false,
    "bookmarksLeftClickPos": "default",
    "bookmarksMidClickAction": "open_in_new",
    "bookmarksMidClickActivate": false,
    "bookmarksMidClickRemove": false,
    "bookmarksMidClickPos": "default",
    "syncName": "",
    "syncSaveSettings": false,
    "syncSaveCtxMenu": false,
    "syncSaveStyles": false,
    "syncSaveKeybindings": false
  },
  "permissions": {
    "allUrls": false,
    "webRequest": false,
    "webRequestBlocking": false,
    "proxy": false,
    "tabHide": false,
    "clipboardWrite": false,
    "history": false,
    "bookmarks": false,
    "downloads": false
  },
  "storage": {
    "size": "2.79 kb",
    "props": {
      "containers": "1.07 kb",
      "favDomains": "69 b",
      "favHashes": "10 b",
      "favicons": "502 b",
      "profileID": "14 b",
      "sidebar": "386 b",
      "tabsDataCache": "666 b",
      "ver": "10 b"
    }
  },
  "sidebar": {
    "panels": {
      "dhVevStaph4h": {
        "type": 2,
        "id": "dhVevStaph4h",
        "name": "len: 4",
        "color": "toolbar",
        "iconSVG": "icon_tabs",
        "iconIMGSrc": "",
        "iconIMG": "",
        "lockedPanel": false,
        "skipOnSwitching": false,
        "noEmpty": false,
        "newTabCtx": "none",
        "dropTabCtx": "none",
        "moveRules": [],
        "moveExcludedTo": -1,
        "bookmarksFolderId": -1,
        "newTabBtns": [],
        "srcPanelConfig": null
      }
    },
    "nav": [
      "dhVevStaph4h",
      "add_tp",
      "sp-0",
      "settings"
    ]
  },
  "containers": [
    {
      "id": "firefox-container-1",
      "cookieStoreId": "firefox-container-1",
      "name": "8",
      "icon": "...",
      "color": "blue",
      "colorCode": "#37adff",
      "proxified": false,
      "proxy": null,
      "reopenRulesActive": false,
      "reopenRules": [],
      "userAgentActive": false,
      "userAgent": ""
    },
    {
      "id": "firefox-container-2",
      "cookieStoreId": "firefox-container-2",
      "name": "4",
      "icon": "...",
      "color": "orange",
      "colorCode": "#37adff",
      "proxified": false,
      "proxy": null,
      "reopenRulesActive": false,
      "reopenRules": [],
      "userAgentActive": false,
      "userAgent": ""
    },
    {
      "id": "firefox-container-3",
      "cookieStoreId": "firefox-container-3",
      "name": "7",
      "icon": "...",
      "color": "green",
      "colorCode": "#37adff",
      "proxified": false,
      "proxy": null,
      "reopenRulesActive": false,
      "reopenRules": [],
      "userAgentActive": false,
      "userAgent": ""
    },
    {
      "id": "firefox-container-4",
      "cookieStoreId": "firefox-container-4",
      "name": "8",
      "icon": "...",
      "color": "pink",
      "colorCode": "#37adff",
      "proxified": false,
      "proxy": null,
      "reopenRulesActive": false,
      "reopenRules": [],
      "userAgentActive": false,
      "userAgent": ""
    }
  ],
  "windows": [
    {
      "state": "maximized",
      "incognito": false,
      "tabsCount": 8
    }
  ],
  "bookmarks": "TypeError: browser.bookmarks is undefined"
}
Logs
To get logs: 
- Open DevTools (open this url in new tab: about:devtools-toolbox?id=%7B3c078156-979c-498b-8990-85f7987dd929%7D&type=extension).
- Navigate to "console" tab.
- Click on the trash bin icon (at the top-left) to clear console.
- Then try to reproduce the issue.
- If messages appear, copy and paste them here inside this codeblock, replacing this text.
@zelch
Copy link
Contributor

zelch commented Jul 12, 2023

I'm hitting the exact same issue, also starting today with 5.0.0rc1.

Edit: Closing the side bar and reopening it causes the tab tree to be rendered accurately, until the next time you open new tabs, at which point those are added in incorrect positions.

So Sideberry clearly knows where things are supposed to be,

@zelch
Copy link
Contributor

zelch commented Jul 12, 2023

Alright, looking at the code, I have a strong suspicion that the problem is commit 40d3941.

To paste from the commit:

+function recalcVisibleTabsInPanel(panelId: ID) {
+  const panel = Sidebar.panelsById[panelId]
+  if (!Utils.isTabsPanel(panel)) return
+
+  if (panel.filteredTabs) panel.reactive.visibleTabIds = panel.filteredTabs.map(t => t.id)
+  else {
+    const visibleTabIds = []
+    for (const tab of panel.tabs) {
+      if (!tab.invisible) visibleTabIds.push(tab.id)
+    }
+    panel.reactive.visibleTabIds = visibleTabIds
+  }
+}
+
+export function addToVisibleTabs(panelId: ID, tabId: ID) {
+  const panel = Sidebar.panelsById[panelId]
+  if (!Utils.isTabsPanel(panel)) return
+
+  const index = panel.tabs.findIndex(t => t.id === tabId)
+  if (index === -1) return recalcVisibleTabs(panelId)
+
+  panel.reactive.visibleTabIds.splice(index, 0, tabId)
+}

The problem is that addToVisibleTabs is finding in panel.tabs, and then using that index in panel.reactive.visibleTabIds.

But based on recalcVisibleTabsInPanel, if there are any filtered tabs or if there are any invisible tabs, that index won't match what's in panel.reactive.visibleTabIds at all.

I would suggest that in addToVisibleTabs we search on panel.reactive.visibleTabIds instead, because that gives us the correct index to splice into.

If that fails, then the same call to recalcVisibleTabs is the right option.

@zelch
Copy link
Contributor

zelch commented Jul 12, 2023

Indeed, that fixes it! I can do a quick PR if need be. :)

zelch pushed a commit to zelch/sidebery that referenced this issue Jul 12, 2023
This fixes mbnuqw#1102, "Open link in new tab" opening out of position.
@mbnuqw
Copy link
Owner

mbnuqw commented Jul 12, 2023

@zelch Thank you, no need, a few minutes and I'll release rc2

@zelch
Copy link
Contributor

zelch commented Jul 12, 2023

@mbnuqw ... I actually opened a PR just before you commented. :)

(And an unrelated PR that has been on my todo list for a few months now.)

@mbnuqw
Copy link
Owner

mbnuqw commented Jul 12, 2023

Fixed in v5.0.0rc2

@mbnuqw mbnuqw closed this as completed Jul 12, 2023
@zelch
Copy link
Contributor

zelch commented Jul 12, 2023

@mbnuqw Looking at your change, what happens if we open a new tab while we have filtered tabs?

Not that my newer function (below) solves that problem either, as it assumes that the new tab will always be visible, which may not be accurate when in a filtered tab view.

Perhaps a check for panel.filteredTabs which calls recalcVisibleTabs? That seems like the least painful way to handle such a rare corner case.

export function addToVisibleTabs(panelId: ID, tabId: ID) {
  const panel = Sidebar.panelsById[panelId]
  if (!Utils.isTabsPanel(panel)) return
      
  var index = -1
  const index1 = panel.tabs.findIndex(t => t.id === tabId)
  if (index1 === 0) index = 0
  else if (index1 > 0) {
    const prevId = panel.tabs[index1 - 1].id
    
    index = panel.reactive.visibleTabIds.indexOf(prevId) + 1
  }

  if (index === -1) return recalcVisibleTabs(panelId)

  panel.reactive.visibleTabIds.splice(index, 0, tabId)
}

@mbnuqw
Copy link
Owner

mbnuqw commented Jul 12, 2023

what happens if we open a new tab while we have filtered tabs?
Hm, you're right...

The panel.filteredTabs doesn't have the new tab at this point, so we need to trigger search in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants