Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
After tab close, set next active tab immediately, and only if differe…
Browse files Browse the repository at this point in the history
…nt from the tab muon will set.

Avoids race condition that can occur after will-destroy, before appState has been fully updated with any tab details that change from muon as a result of a tab closing.

Fix #11981
Fix #11526
  • Loading branch information
petemill authored and bsclifton committed Dec 20, 2017
1 parent 519a8dd commit 30dc2f1
Show file tree
Hide file tree
Showing 8 changed files with 434 additions and 250 deletions.
57 changes: 57 additions & 0 deletions app/browser/activeTabHistory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// static
const activeTabsByWindow = new Map()

const api = {
/**
* Inform this store that a tab is active for a window.
* This information will be added to index 0 in the
* active-tab history for the window.
*/
setActiveTabForWindow: function (windowId, tabId) {
const existing = activeTabsByWindow.get(windowId)
if (existing) {
existing.unshift(tabId)
} else {
activeTabsByWindow.set(windowId, [ tabId ])
}
},

/**
* Retrieve the tabId that was active at the specified history index,
* 0 for most recent (default)
*/
getActiveTabForWindow: function (windowId, historyIndex = 0) {
// get history of active tabs for specified window
const windowActiveTabs = activeTabsByWindow.get(windowId)
// handle no history for specified window
if (!windowActiveTabs || !windowActiveTabs.length) {
return null
}
// verify specified index in active-tab history exists
const lastIndex = windowActiveTabs.length - 1
if (lastIndex < historyIndex) {
return null
}
// get tabId at specified index in active-tab history
return windowActiveTabs[historyIndex]
},

/**
* Removes specified tab from active-tab history in specified window
*/
clearTabFromWindow: function (windowId, tabId) {
const windowActiveTabs = activeTabsByWindow.get(windowId)
if (windowActiveTabs && windowActiveTabs.length) {
activeTabsByWindow.set(windowId, windowActiveTabs.filter(previousTabId => previousTabId !== tabId))
}
},

/**
* Forget history of active tabs for specified window
*/
clearTabbedWindow: function (windowId) {
activeTabsByWindow.delete(windowId)
}
}

module.exports = api
7 changes: 0 additions & 7 deletions app/browser/reducers/tabsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,6 @@ const tabsReducer = (state, action, immutableAction) => {
if (tabId === tabState.TAB_ID_NONE) {
break
}
const nextActiveTabId = tabs.getNextActiveTab(state, tabId)

// Must be called before tab is removed
// But still check for no tabId because on tab detach there's a dummy tabId
const tabValue = tabState.getByTabId(state, tabId)
Expand All @@ -211,11 +209,6 @@ const tabsReducer = (state, action, immutableAction) => {
state = tabs.updateTabsStateForWindow(state, windowIdOfTabBeingRemoved)
}
state = tabState.removeTabByTabId(state, tabId)
setImmediate(() => {
if (nextActiveTabId !== tabState.TAB_ID_NONE) {
tabs.setActive(nextActiveTabId)
}
})
tabs.forgetTab(tabId)
}
break
Expand Down
Loading

0 comments on commit 30dc2f1

Please sign in to comment.