fix(nav): reduce request tab flicker on home return

Hide the Request tab instead of removing it off-home, cache the button/panel, and reinject immediately when Jellyfin rebuilds the home tab bar.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Michael SloanandCursor committed 2026-08-02 21:38:28 -04:00
1 parent 7044023d98
commit db166bfc02
7 files changed
+93 -49

No files matched your search

+3 -3
View File
@@ -1,7 +1,7 @@
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<Version>1.0.1.0</Version> <Version>1.0.1.1</Version>
<AssemblyVersion>1.0.1.0</AssemblyVersion> <AssemblyVersion>1.0.1.1</AssemblyVersion>
<FileVersion>1.0.1.0</FileVersion> <FileVersion>1.0.1.1</FileVersion>
</PropertyGroup> </PropertyGroup>
</Project> </Project>
@@ -21,7 +21,7 @@ public sealed class WebNavInjector : IHostedService
/// <summary> /// <summary>
/// Script URL injected into jellyfin-web index.html. /// Script URL injected into jellyfin-web index.html.
/// </summary> /// </summary>
public const string LoaderSrc = "/Requests/Assets/nav-loader.js?v=1.0.1.0"; public const string LoaderSrc = "/Requests/Assets/nav-loader.js?v=1.0.1.1";
private const string MarkerStart = "<!-- jellyfin-plugin-request-nav-start -->"; private const string MarkerStart = "<!-- jellyfin-plugin-request-nav-start -->";
private const string MarkerEnd = "<!-- jellyfin-plugin-request-nav-end -->"; private const string MarkerEnd = "<!-- jellyfin-plugin-request-nav-end -->";
+81 -37
View File
@@ -9,6 +9,9 @@
let ensuring = null; let ensuring = null;
let assetsPromise = null; let assetsPromise = null;
let guardAttached = false; let guardAttached = false;
let cachedButton = null;
let cachedPanel = null;
let headerObserver = null;
function ensureStyle() { function ensureStyle() {
if (document.getElementById(STYLE_ID)) { if (document.getElementById(STYLE_ID)) {
@@ -20,6 +23,7 @@
style.textContent = [ style.textContent = [
".jf-request-tab-panel{padding:1rem 1.25rem 2rem;box-sizing:border-box;min-height:50vh;}", ".jf-request-tab-panel{padding:1rem 1.25rem 2rem;box-sizing:border-box;min-height:50vh;}",
".jf-request-tab-panel .req-embed{max-width:1400px;margin:0 auto;}", ".jf-request-tab-panel .req-embed{max-width:1400px;margin:0 auto;}",
`.headerTabs .emby-tab-button[${TAB_ATTR}].jf-request-tab-away{display:none!important;}`,
".jf-request-menu-item{align-items:center;color:inherit;display:flex!important;gap:1rem;min-height:3rem;padding:.75rem 1.25rem;text-decoration:none;cursor:pointer;background:none;border:0;width:100%;text-align:left;font:inherit;}", ".jf-request-menu-item{align-items:center;color:inherit;display:flex!important;gap:1rem;min-height:3rem;padding:.75rem 1.25rem;text-decoration:none;cursor:pointer;background:none;border:0;width:100%;text-align:left;font:inherit;}",
".jf-request-menu-item:hover,.jf-request-menu-item:focus{color:#00a4dc;}", ".jf-request-menu-item:hover,.jf-request-menu-item:focus{color:#00a4dc;}",
".jf-request-menu-icon{align-items:center;display:inline-flex;font-size:1.45rem;justify-content:center;line-height:1;min-width:1.5rem;}", ".jf-request-menu-icon{align-items:center;display:inline-flex;font-size:1.45rem;justify-content:center;line-height:1;min-width:1.5rem;}",
@@ -103,7 +107,6 @@
function createTabPanel() { function createTabPanel() {
const panel = document.createElement("div"); const panel = document.createElement("div");
// Match SeerrFin: start without .hide; visibility is synced on tab change.
panel.className = "tabContent pageTabContent hide jf-request-tab-panel"; panel.className = "tabContent pageTabContent hide jf-request-tab-panel";
panel.setAttribute(TAB_ATTR, "request"); panel.setAttribute(TAB_ATTR, "request");
panel.id = "jellyfinRequestTab"; panel.id = "jellyfinRequestTab";
@@ -115,6 +118,18 @@
return panel; return panel;
} }
function bindRequestButton(button) {
if (!button || button.dataset.jfRequestClickBound === "1") {
return;
}
button.dataset.jfRequestClickBound = "1";
button.addEventListener("click", () => {
setTimeout(showRequestPanel, 0);
setTimeout(showRequestPanel, 120);
});
}
function findNativeButtons(tabsSlider) { function findNativeButtons(tabsSlider) {
return Array.from(tabsSlider.querySelectorAll(".emby-tab-button")).filter((btn) => { return Array.from(tabsSlider.querySelectorAll(".emby-tab-button")).filter((btn) => {
if (btn.hasAttribute(TAB_ATTR)) { if (btn.hasAttribute(TAB_ATTR)) {
@@ -147,7 +162,8 @@
} }
function syncIndexes(tabsSlider, page) { function syncIndexes(tabsSlider, page) {
const buttons = Array.from(tabsSlider.querySelectorAll(".emby-tab-button")); const buttons = Array.from(tabsSlider.querySelectorAll(".emby-tab-button"))
.filter((button) => !button.classList.contains("jf-request-tab-away"));
buttons.forEach((button, index) => { buttons.forEach((button, index) => {
button.setAttribute("data-index", String(index)); button.setAttribute("data-index", String(index));
const key = button.getAttribute(TAB_ATTR); const key = button.getAttribute(TAB_ATTR);
@@ -215,7 +231,7 @@
function showRequestPanel() { function showRequestPanel() {
const page = document.getElementById("indexPage"); const page = document.getElementById("indexPage");
const button = document.querySelector(`.headerTabs [${TAB_ATTR}="request"]`); const button = document.querySelector(`.headerTabs [${TAB_ATTR}="request"]`);
const panel = page?.querySelector(`.tabContent[${TAB_ATTR}="request"]`); const panel = page?.querySelector(`.tabContent[${TAB_ATTR}="request"]`) || cachedPanel;
if (!button || !panel) { if (!button || !panel) {
return; return;
} }
@@ -235,13 +251,24 @@
return !!(button && button.getAttribute(TAB_ATTR) === "request"); return !!(button && button.getAttribute(TAB_ATTR) === "request");
} }
function hideRequestTabAway() {
// Hide instead of remove so returning to Home can restore without a visible gap.
document.querySelectorAll(`.headerTabs [${TAB_ATTR}]`).forEach((node) => {
node.classList.add("jf-request-tab-away");
node.setAttribute("aria-hidden", "true");
if (!cachedButton && node.matches(".emby-tab-button")) {
cachedButton = node;
}
});
}
function attachPluginTabGuard(tabsEl) { function attachPluginTabGuard(tabsEl) {
if (!tabsEl || guardAttached || tabsEl.dataset.jfRequestTabGuard === "true") { if (!tabsEl || tabsEl.dataset.jfRequestTabGuard === "true") {
return; return;
} }
guardAttached = true;
tabsEl.dataset.jfRequestTabGuard = "true"; tabsEl.dataset.jfRequestTabGuard = "true";
guardAttached = true;
tabsEl.addEventListener("beforetabchange", (event) => { tabsEl.addEventListener("beforetabchange", (event) => {
if (!isHomeTabContext()) { if (!isHomeTabContext()) {
@@ -253,17 +280,15 @@
return; return;
} }
// Jellyfin activates panels by NodeList order; keep data-index panels in sync.
syncPanelVisibility(index); syncPanelVisibility(index);
const selectedButton = tabsEl.querySelector(`.emby-tab-button[data-index="${index}"]`); const selectedButton = tabsEl.querySelector(`.emby-tab-button[data-index="${index}"]`);
if (isRequestTabButton(selectedButton)) { if (isRequestTabButton(selectedButton)) {
const panel = document.querySelector(`.tabContent[${TAB_ATTR}="request"]`); const panel = document.querySelector(`.tabContent[${TAB_ATTR}="request"]`) || cachedPanel;
mountRequestUi(panel, false); mountRequestUi(panel, false);
} }
}, true); }, true);
// HomeView only knows Home/Favorites. Stop its handler for our tab so content is not cleared.
tabsEl.addEventListener("tabchange", (event) => { tabsEl.addEventListener("tabchange", (event) => {
if (!isHomeTabContext()) { if (!isHomeTabContext()) {
return; return;
@@ -281,7 +306,7 @@
event.stopImmediatePropagation(); event.stopImmediatePropagation();
syncPanelVisibility(index); syncPanelVisibility(index);
const panel = document.querySelector(`.tabContent[${TAB_ATTR}="request"]`); const panel = document.querySelector(`.tabContent[${TAB_ATTR}="request"]`) || cachedPanel;
mountRequestUi(panel, true); mountRequestUi(panel, true);
}, true); }, true);
} }
@@ -360,7 +385,7 @@
insertSideMenuItem(); insertSideMenuItem();
if (!isHomeTabContext()) { if (!isHomeTabContext()) {
document.querySelectorAll(`.headerTabs [${TAB_ATTR}]`).forEach((node) => node.remove()); hideRequestTabAway();
return; return;
} }
@@ -379,24 +404,28 @@
attachPluginTabGuard(tabsEl); attachPluginTabGuard(tabsEl);
let button = tabsSlider.querySelector(`[${TAB_ATTR}="request"]`); let button = tabsSlider.querySelector(`[${TAB_ATTR}="request"]`)
if (!button) { || (cachedButton && cachedButton.isConnected ? cachedButton : null)
|| cachedButton;
if (!button || !button.isConnected) {
button = createTabButton(); button = createTabButton();
} }
if (button.dataset.jfRequestClickBound !== "1") { cachedButton = button;
button.dataset.jfRequestClickBound = "1"; button.classList.remove("jf-request-tab-away", "hide");
button.addEventListener("click", () => { button.removeAttribute("aria-hidden");
setTimeout(showRequestPanel, 0); bindRequestButton(button);
setTimeout(showRequestPanel, 120);
});
}
let panel = page.querySelector(`.tabContent[${TAB_ATTR}="request"]`); let panel = page.querySelector(`.tabContent[${TAB_ATTR}="request"]`)
if (!panel) { || (cachedPanel && cachedPanel.isConnected ? cachedPanel : null)
|| cachedPanel;
if (!panel || !panel.isConnected) {
panel = createTabPanel(); panel = createTabPanel();
} }
cachedPanel = panel;
// Insert the tab button before any async work so Home return does not flash without it.
const nativeButtons = findNativeButtons(tabsSlider); const nativeButtons = findNativeButtons(tabsSlider);
const homeButton = nativeButtons[0]; const homeButton = nativeButtons[0];
const favoritesButton = nativeButtons[1] || nativeButtons[0]; const favoritesButton = nativeButtons[1] || nativeButtons[0];
@@ -404,7 +433,6 @@
const uniqueButtons = [...new Set(orderedButtons)]; const uniqueButtons = [...new Set(orderedButtons)];
placeInOrder(tabsSlider, uniqueButtons); placeInOrder(tabsSlider, uniqueButtons);
// Keep native panels first, then Request, without detaching home rows incorrectly.
const orderedPanels = [homeTab, favoritesTab, panel]; const orderedPanels = [homeTab, favoritesTab, panel];
placeInOrder(page, orderedPanels); placeInOrder(page, orderedPanels);
@@ -418,8 +446,7 @@
} }
} }
// Preload assets so the first click is instant; do not force-show the panel. loadAssets().catch(() => { /* surfaced on mount */ });
await loadAssets().catch(() => { /* surfaced on mount */ });
})().finally(() => { })().finally(() => {
ensuring = null; ensuring = null;
}); });
@@ -427,28 +454,45 @@
return ensuring; return ensuring;
} }
function observeHeaderTabs() {
const headerTabs = document.querySelector(".headerTabs");
if (!headerTabs || headerObserver) {
return;
}
let timer = null;
headerObserver = new MutationObserver(() => {
const onHome = isHomeTabContext();
const missing = onHome && !document.querySelector(`.headerTabs [${TAB_ATTR}="request"]:not(.jf-request-tab-away)`);
if (missing) {
// Jellyfin rebuilt the home tab bar — reinject immediately to avoid flicker.
ensureRequestTab();
return;
}
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => ensureRequestTab(), 80);
});
headerObserver.observe(headerTabs, { childList: true, subtree: true });
}
function boot() { function boot() {
console.info("[Jellyfin.Plugin.Request] nav-loader active"); console.info("[Jellyfin.Plugin.Request] nav-loader active");
ensureRequestTab(); ensureRequestTab();
observeHeaderTabs();
document.addEventListener("viewshow", (event) => { document.addEventListener("viewshow", (event) => {
if (event.target && event.target.id === "indexPage") { if (event.target && event.target.id === "indexPage") {
ensureRequestTab(); ensureRequestTab();
} else {
hideRequestTabAway();
} }
}); });
window.addEventListener("hashchange", () => ensureRequestTab()); window.addEventListener("hashchange", () => ensureRequestTab());
setInterval(() => ensureRequestTab(), 2000); setInterval(() => ensureRequestTab(), 2500);
const headerTabs = document.querySelector(".headerTabs");
if (headerTabs) {
let timer = null;
new MutationObserver(() => {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => ensureRequestTab(), 250);
}).observe(headerTabs, { childList: true, subtree: true });
}
} }
if (document.readyState === "loading") { if (document.readyState === "loading") {
+1 -1
View File
@@ -1,7 +1,7 @@
--- ---
name: "Request" name: "Request"
guid: "11c08950-c4bb-484d-89ff-205b3724416b" guid: "11c08950-c4bb-484d-89ff-205b3724416b"
version: "1.0.1.0" version: "1.0.1.1"
targetAbi: "10.11.11.0" targetAbi: "10.11.11.0"
framework: "net9.0" framework: "net9.0"
overview: "Request movies and TV shows from a local admin review queue" overview: "Request movies and TV shows from a local admin review queue"
+5 -5
View File
@@ -9,12 +9,12 @@
"repositoryUrl": "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies", "repositoryUrl": "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies",
"versions": [ "versions": [
{ {
"version": "1.0.1.0", "version": "1.0.1.1",
"changelog": "Custom non-TMDB requests; fix blank Request tab needing hard refresh", "changelog": "Reduce Request tab flicker when returning home from collections",
"targetAbi": "10.11.11.0", "targetAbi": "10.11.11.0",
"sourceUrl": "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies/raw/branch/main/release/Jellyfin.Plugin.Request_1.0.1.0.zip", "sourceUrl": "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies/raw/branch/main/release/Jellyfin.Plugin.Request_1.0.1.1.zip",
"checksum": "1DBFBFD428DCBD011C4154147C42EA1F", "checksum": "EADA70C2BC7AAD32623E37FDBD85DF44",
"timestamp": "2026-08-02T21:46:53.5809145Z", "timestamp": "2026-08-03T01:38:28.4011758Z",
"dependencies": [] "dependencies": []
} }
] ]
Binary file not shown.
+2 -2
View File
@@ -1,5 +1,5 @@
param( param(
[string]$Version = "1.0.1.0", [string]$Version = "1.0.1.1",
[string]$TargetAbi = "10.11.11.0", [string]$TargetAbi = "10.11.11.0",
[string]$RepoRawBase = "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies/raw/branch/main" [string]$RepoRawBase = "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies/raw/branch/main"
) )
@@ -17,7 +17,7 @@ $dllPath = Join-Path $root "Jellyfin.Plugin.Request\bin\Release\net9.0\Jellyfin.
$zipPath = Join-Path $releaseDir $zipFileName $zipPath = Join-Path $releaseDir $zipFileName
$manifestPath = Join-Path $root "manifest.json" $manifestPath = Join-Path $root "manifest.json"
$timestamp = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ") $timestamp = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ")
$changelog = "Custom non-TMDB requests; fix blank Request tab needing hard refresh" $changelog = "Reduce Request tab flicker when returning home from collections"
Write-Host "Building plugin..." Write-Host "Building plugin..."
dotnet build (Join-Path $root "Jellyfin.Plugin.Request.sln") -c Release dotnet build (Join-Path $root "Jellyfin.Plugin.Request.sln") -c Release