fix: Fixed fetching browser history entries from cache, b=no-bug, c=no-component

This commit is contained in:
mr. m
2026-01-17 15:50:46 +01:00
parent a993f40532
commit a36acadd04

View File

@@ -658,12 +658,12 @@ class nsZenWindowSync {
// we would start receiving invalid history changes from the the incorrect
// browser view that was just swapped out.
this.#maybeFlushTabState(aOurTab).finally(() => {
if (!tabStateEntries?.length) {
if (!tabStateEntries?.entries.length) {
this.log(`Error: No tab state entries found for tab ${aOtherTab.id} during swap`);
return;
}
lazy.TabStateCache.update(aOurTab.linkedBrowser.permanentKey, {
entries: tabStateEntries,
history: tabStateEntries,
});
});
return true;
@@ -853,14 +853,14 @@ class nsZenWindowSync {
* Retrieves the tab state entries from the cache for a given tab.
*
* @param {object} aTab - The tab to retrieve the state for.
* @returns {Array} The tab state entries.
* @returns {object} The tab state entries.
*/
#getTabEntriesFromCache(aTab) {
if (!aTab.linkedBrowser) {
return [];
let cachedState;
if (aTab.linkedBrowser) {
cachedState = lazy.TabStateCache.get(aTab.linkedBrowser.permanentKey);
}
let cachedState = lazy.TabStateCache.get(aTab.linkedBrowser.permanentKey) || {};
return cachedState.history?.entries || [];
return cachedState?.history?.entries ? cachedState.history : { entries: [] };
}
/**
@@ -887,13 +887,16 @@ class nsZenWindowSync {
setPinnedTabState(aTab) {
return this.#maybeFlushTabState(aTab).finally(() => {
this.log(`Setting pinned initial state for tab ${aTab.id}`);
const entries = this.#getTabEntriesFromCache(aTab);
let activeIndex = "index" in entries ? entries.index : entries.entries.length - 1;
activeIndex = Math.min(activeIndex, entries.entries.length - 1);
let { entries, index } = this.#getTabEntriesFromCache(aTab);
let image = aTab.getAttribute("image") || aTab.ownerGlobal.gBrowser.getIcon(aTab);
let activeIndex = typeof index === "number" ? index : entries.length;
// Tab state cache gives us the index starting from 1 instead of 0.
activeIndex--;
activeIndex = Math.min(activeIndex, entries.length - 1);
activeIndex = Math.max(activeIndex, 0);
const initialState = {
entry: entries.entries[activeIndex],
image: entries.image,
entry: (entries[activeIndex] || entries[0]) ?? null,
image,
};
this.#runOnAllWindows(null, (win) => {
const targetTab = this.getItemFromWindow(win, aTab.id);