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
+95 -51

No files matched your search

+3 -3
View File
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<Version>1.0.1.0</Version>
<AssemblyVersion>1.0.1.0</AssemblyVersion>
<FileVersion>1.0.1.0</FileVersion>
<Version>1.0.1.1</Version>
<AssemblyVersion>1.0.1.1</AssemblyVersion>
<FileVersion>1.0.1.1</FileVersion>
</PropertyGroup>
</Project>
@@ -21,7 +21,7 @@ public sealed class WebNavInjector : IHostedService
/// <summary>
/// Script URL injected into jellyfin-web index.html.
/// </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 MarkerEnd = "<!-- jellyfin-plugin-request-nav-end -->";
+83 -39
View File
@@ -9,6 +9,9 @@
let ensuring = null;
let assetsPromise = null;
let guardAttached = false;
let cachedButton = null;
let cachedPanel = null;
let headerObserver = null;
function ensureStyle() {
if (document.getElementById(STYLE_ID)) {
@@ -20,6 +23,7 @@
style.textContent = [
".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;}",
`.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: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;}",
@@ -103,7 +107,6 @@
function createTabPanel() {
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.setAttribute(TAB_ATTR, "request");
panel.id = "jellyfinRequestTab";
@@ -115,6 +118,18 @@
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) {
return Array.from(tabsSlider.querySelectorAll(".emby-tab-button")).filter((btn) => {
if (btn.hasAttribute(TAB_ATTR)) {
@@ -147,7 +162,8 @@
}
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) => {
button.setAttribute("data-index", String(index));
const key = button.getAttribute(TAB_ATTR);
@@ -215,7 +231,7 @@
function showRequestPanel() {
const page = document.getElementById("indexPage");
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) {
return;
}
@@ -235,13 +251,24 @@
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) {
if (!tabsEl || guardAttached || tabsEl.dataset.jfRequestTabGuard === "true") {
if (!tabsEl || tabsEl.dataset.jfRequestTabGuard === "true") {
return;
}
guardAttached = true;
tabsEl.dataset.jfRequestTabGuard = "true";
guardAttached = true;
tabsEl.addEventListener("beforetabchange", (event) => {
if (!isHomeTabContext()) {
@@ -253,17 +280,15 @@
return;
}
// Jellyfin activates panels by NodeList order; keep data-index panels in sync.
syncPanelVisibility(index);
const selectedButton = tabsEl.querySelector(`.emby-tab-button[data-index="${index}"]`);
if (isRequestTabButton(selectedButton)) {
const panel = document.querySelector(`.tabContent[${TAB_ATTR}="request"]`);
const panel = document.querySelector(`.tabContent[${TAB_ATTR}="request"]`) || cachedPanel;
mountRequestUi(panel, false);
}
}, true);
// HomeView only knows Home/Favorites. Stop its handler for our tab so content is not cleared.
tabsEl.addEventListener("tabchange", (event) => {
if (!isHomeTabContext()) {
return;
@@ -281,7 +306,7 @@
event.stopImmediatePropagation();
syncPanelVisibility(index);
const panel = document.querySelector(`.tabContent[${TAB_ATTR}="request"]`);
const panel = document.querySelector(`.tabContent[${TAB_ATTR}="request"]`) || cachedPanel;
mountRequestUi(panel, true);
}, true);
}
@@ -360,7 +385,7 @@
insertSideMenuItem();
if (!isHomeTabContext()) {
document.querySelectorAll(`.headerTabs [${TAB_ATTR}]`).forEach((node) => node.remove());
hideRequestTabAway();
return;
}
@@ -379,24 +404,28 @@
attachPluginTabGuard(tabsEl);
let button = tabsSlider.querySelector(`[${TAB_ATTR}="request"]`);
if (!button) {
let button = tabsSlider.querySelector(`[${TAB_ATTR}="request"]`)
|| (cachedButton && cachedButton.isConnected ? cachedButton : null)
|| cachedButton;
if (!button || !button.isConnected) {
button = createTabButton();
}
if (button.dataset.jfRequestClickBound !== "1") {
button.dataset.jfRequestClickBound = "1";
button.addEventListener("click", () => {
setTimeout(showRequestPanel, 0);
setTimeout(showRequestPanel, 120);
});
}
cachedButton = button;
button.classList.remove("jf-request-tab-away", "hide");
button.removeAttribute("aria-hidden");
bindRequestButton(button);
let panel = page.querySelector(`.tabContent[${TAB_ATTR}="request"]`);
if (!panel) {
let panel = page.querySelector(`.tabContent[${TAB_ATTR}="request"]`)
|| (cachedPanel && cachedPanel.isConnected ? cachedPanel : null)
|| cachedPanel;
if (!panel || !panel.isConnected) {
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 homeButton = nativeButtons[0];
const favoritesButton = nativeButtons[1] || nativeButtons[0];
@@ -404,7 +433,6 @@
const uniqueButtons = [...new Set(orderedButtons)];
placeInOrder(tabsSlider, uniqueButtons);
// Keep native panels first, then Request, without detaching home rows incorrectly.
const orderedPanels = [homeTab, favoritesTab, panel];
placeInOrder(page, orderedPanels);
@@ -418,8 +446,7 @@
}
}
// Preload assets so the first click is instant; do not force-show the panel.
await loadAssets().catch(() => { /* surfaced on mount */ });
loadAssets().catch(() => { /* surfaced on mount */ });
})().finally(() => {
ensuring = null;
});
@@ -427,28 +454,45 @@
return ensuring;
}
function boot() {
console.info("[Jellyfin.Plugin.Request] nav-loader active");
ensureRequestTab();
document.addEventListener("viewshow", (event) => {
if (event.target && event.target.id === "indexPage") {
ensureRequestTab();
}
});
window.addEventListener("hashchange", () => ensureRequestTab());
setInterval(() => ensureRequestTab(), 2000);
function observeHeaderTabs() {
const headerTabs = document.querySelector(".headerTabs");
if (headerTabs) {
if (!headerTabs || headerObserver) {
return;
}
let timer = null;
new MutationObserver(() => {
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(), 250);
}).observe(headerTabs, { childList: true, subtree: true });
timer = setTimeout(() => ensureRequestTab(), 80);
});
headerObserver.observe(headerTabs, { childList: true, subtree: true });
}
function boot() {
console.info("[Jellyfin.Plugin.Request] nav-loader active");
ensureRequestTab();
observeHeaderTabs();
document.addEventListener("viewshow", (event) => {
if (event.target && event.target.id === "indexPage") {
ensureRequestTab();
} else {
hideRequestTabAway();
}
});
window.addEventListener("hashchange", () => ensureRequestTab());
setInterval(() => ensureRequestTab(), 2500);
}
if (document.readyState === "loading") {
+1 -1
View File
@@ -1,7 +1,7 @@
---
name: "Request"
guid: "11c08950-c4bb-484d-89ff-205b3724416b"
version: "1.0.1.0"
version: "1.0.1.1"
targetAbi: "10.11.11.0"
framework: "net9.0"
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",
"versions": [
{
"version": "1.0.1.0",
"changelog": "Custom non-TMDB requests; fix blank Request tab needing hard refresh",
"version": "1.0.1.1",
"changelog": "Reduce Request tab flicker when returning home from collections",
"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",
"checksum": "1DBFBFD428DCBD011C4154147C42EA1F",
"timestamp": "2026-08-02T21:46:53.5809145Z",
"sourceUrl": "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies/raw/branch/main/release/Jellyfin.Plugin.Request_1.0.1.1.zip",
"checksum": "EADA70C2BC7AAD32623E37FDBD85DF44",
"timestamp": "2026-08-03T01:38:28.4011758Z",
"dependencies": []
}
]
Binary file not shown.
+2 -2
View File
@@ -1,5 +1,5 @@
param(
[string]$Version = "1.0.1.0",
[string]$Version = "1.0.1.1",
[string]$TargetAbi = "10.11.11.0",
[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
$manifestPath = Join-Path $root "manifest.json"
$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..."
dotnet build (Join-Path $root "Jellyfin.Plugin.Request.sln") -c Release