regression for filter setting possible fix

This commit is contained in:
2026-05-29 19:05:44 +02:00
parent f79e4d6f32
commit 37460ba224
2 changed files with 16 additions and 2 deletions

View File

@@ -3429,13 +3429,27 @@ window.cancelAnimFrame = (function () {
randomUrl += '?' + params.toString(); randomUrl += '?' + params.toString();
} }
// Capture favs user context before fetch so it's accessible in .then()
// Without this, random in /user/foo/favs would navigate to /:id (losing context),
// causing mode mismatches between the AJAX pick and any subsequent full-page reload.
let wFavsUser = null;
if (!wUserHall) {
const wUserM = window.location.href.match(/\/user\/([^/]+)/);
if (wUserM && window.location.href.match(/\/favs(\/|$|\?)/)) {
wFavsUser = decodeURIComponent(wUserM[1]);
}
}
fetch(randomUrl) fetch(randomUrl)
.then(r => r.json()) .then(r => r.json())
.then(data => { .then(data => {
if (data.success && data.items && data.items.id) { if (data.success && data.items && data.items.id) {
// Navigate in the same context (user hall, tag, etc.) // Navigate in the same context (user hall, favs, tag, etc.)
if (wUserHall && wUserHallOwner) { if (wUserHall && wUserHallOwner) {
loadItemAjax(`/user/${encodeURIComponent(wUserHallOwner)}/hall/${encodeURIComponent(wUserHall)}/${data.items.id}`, true); loadItemAjax(`/user/${encodeURIComponent(wUserHallOwner)}/hall/${encodeURIComponent(wUserHall)}/${data.items.id}`, true);
} else if (wFavsUser) {
// Preserve /user/:name/favs/:id context so next/prev arrows stay within favs
loadItemAjax(`/user/${encodeURIComponent(wFavsUser)}/favs/${data.items.id}`, true);
} else { } else {
loadItemAjax(`/${data.items.id}`, true); loadItemAjax(`/${data.items.id}`, true);
} }

View File

@@ -496,7 +496,7 @@ export default router => {
const userHallOwner = req.url.qs.userHallOwner || null; const userHallOwner = req.url.qs.userHallOwner || null;
const isFav = req.url.qs.fav === 'true'; const isFav = req.url.qs.fav === 'true';
const isStrict = req.url.qs.strict === '1'; const isStrict = req.url.qs.strict === '1';
const mode = req.session?.mode ?? 0; const mode = req.mode ?? 0; // Use req.mode (set by middleware) for consistency with all other routes
const ratingsRaw = req.cookies.ratings; const ratingsRaw = req.cookies.ratings;
const ratingsArr = ratingsRaw ? decodeURIComponent(ratingsRaw).split(/[|,]/).filter(r => ['sfw','nsfw','nsfl','untagged'].includes(r)) : null; const ratingsArr = ratingsRaw ? decodeURIComponent(ratingsRaw).split(/[|,]/).filter(r => ['sfw','nsfw','nsfl','untagged'].includes(r)) : null;