fix: prevent library flash on reload
CI / test (push) Successful in 37s

Apply the requested view before first paint via a data-view attribute and CSS, and switch views before loading the library.
This commit is contained in:
strsv committed 2026-11-07 02:35:34 +03:00
1 parent b45b4437b8
commit eb8a9bb57b
4 files changed
+34 -1

No files matched your search

+2
View File
@@ -169,6 +169,8 @@
- Вкладки HLTB и «Сервисы» сохраняются в URL (`?view=hltb`, `?view=services`),
поэтому обновление страницы больше не перебрасывает в «Библиотеку».
- Убрано мигание «Библиотеки» при обновлении: нужная вкладка выбирается до первой
отрисовки (CSS по `data-view`), а библиотека больше не загружается первой.
- Опрос холодного старта можно открыть в любой момент ссылкой «пройти опрос»,
даже если он скрыт или сигналов вкуса уже достаточно.
- Закреплённые фильтры больше не сворачиваются при переходе в «Рекомендации»
+2 -1
View File
@@ -1856,6 +1856,7 @@ function debounce(fn, ms) {
function switchView(view) {
state.view = view;
document.documentElement.dataset.view = view;
if (view !== "library" && !filtersState.pinned) closeFilters();
document.querySelectorAll(".tab").forEach((tab) => {
const active = tab.dataset.view === view;
@@ -2367,7 +2368,6 @@ if ("serviceWorker" in navigator) {
$("#sort").value = state.sort;
await Promise.all([loadMeta(), loadMoods()]);
pollJob(true);
await loadGames(true);
const params = new URLSearchParams(location.search);
if (params.get("view") === "recommend") {
@@ -2391,5 +2391,6 @@ if ("serviceWorker" in navigator) {
} else if (params.get("view") === "services") {
switchView("services");
}
await loadGames(true);
if (params.get("game")) openGame(params.get("game"));
})();
+4
View File
@@ -14,6 +14,10 @@
<script>
try {
if (localStorage.getItem("sb.theme") === "light") document.documentElement.dataset.theme = "light";
const view = new URLSearchParams(location.search).get("view");
if (["recommend", "hltb", "friends", "services"].includes(view)) {
document.documentElement.dataset.view = view;
}
} catch (_) {}
</script>
<link rel="stylesheet" href="/static/styles.css">
+26
View File
@@ -121,6 +121,32 @@ button { cursor: pointer; }
font-weight: 650;
}
/* Paint the requested view before app.js runs (no library flash on reload). */
html[data-view="recommend"] #libraryView,
html[data-view="hltb"] #libraryView,
html[data-view="friends"] #libraryView,
html[data-view="services"] #libraryView { display: none !important; }
html[data-view="recommend"] #recommendView,
html[data-view="hltb"] #hltbView,
html[data-view="friends"] #friendsView,
html[data-view="services"] #servicesView { display: block !important; }
html[data-view="recommend"] #tabRecommend,
html[data-view="hltb"] #tabHltb,
html[data-view="friends"] #tabFriends,
html[data-view="services"] #tabServices {
color: #0a0d13;
background: linear-gradient(135deg, var(--accent), #ffd59a);
font-weight: 650;
}
html[data-view="recommend"] #tabLibrary,
html[data-view="hltb"] #tabLibrary,
html[data-view="friends"] #tabLibrary,
html[data-view="services"] #tabLibrary {
color: var(--muted);
background: transparent;
font-weight: normal;
}
.stats {
margin-left: auto;
display: flex;