From 00817766a6628c5d90504dfed3f75364a7e55b44 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 4 Oct 2026 14:28:43 +0800 Subject: [PATCH] fix(author): keep the follow sub-tab state out of the other panels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit uhSub(粉丝/关注)只属于粉丝面板,loadPanelBody 却把它写在每一个面板上, 翻页时又从被点面板自身读回,于是分组状态跨面板串味:先点粉丝 tab 切到 「关注」,再点文章 tab 翻页,#panel-posts 会被永久打上 data-uh-sub= "following",之后粉丝面板的翻页读到的是文章面板残留的分组。 翻页改为只读**当前面板内**的 .is-active 子页签,读不到就回落默认分组; uhPage / uhSub 也只在粉丝面板写入,文章 / 收藏 / 评论面板一次都不碰。 目标面板本身仍由被点面板的 id 反解,跨面板跳转这条路径不存在,本次不动。 Co-Authored-By: Claude Fable 5 --- assets/js/author.js | 19 +++++++++++++++---- .../post-visual-contract.test.cjs | 9 +++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/assets/js/author.js b/assets/js/author.js index eca5b430..450031bd 100644 --- a/assets/js/author.js +++ b/assets/js/author.js @@ -66,9 +66,14 @@ if (!userId || !restBase) return Promise.reject(new Error('rest-unavailable')); if (panel._aksrtUhRequest) return panel._aksrtUhRequest; - var followSub = sub || panel.dataset.uhSub || 'followers'; - panel.dataset.uhPage = String(page); - panel.dataset.uhSub = followSub; + var followSub = sub || 'followers'; + // uhPage / uhSub 是**粉丝面板**的私有状态(其它面板没有子页签)。 + // 写满所有面板会互相污染:文章面板上的 uhSub 残留会让粉丝翻页读到 + // 别人的分组,uhPage 也会让旧页码假活跃。非粉丝面板一次都不写。 + if (name === 'follow') { + panel.dataset.uhPage = String(page); + panel.dataset.uhSub = followSub; + } panel.classList.add('is-loading'); var url = restBase.replace(/\/$/, '') + '/user-home/panel/' + userId + '/' + encodeURIComponent(name) @@ -130,7 +135,13 @@ var name = panelNameOf(panel); if (!name) return; var page = Math.max(1, parseInt(pageBtn.getAttribute('data-uh-page') || '1', 10) || 1); - loadPanelBody(panel, name, page, panel.dataset.uhSub || 'followers').catch(notifyLoadError); + // 只认**本面板内**的子页签状态:uhSub 是粉丝面板私有的(panel-follow.php + // 的 data-uh-sub),一旦落到别的面板上就会互相串味 —— 先点过粉丝子页签, + // panel.dataset.uhSub 会残留在文章面板上,之后粉丝面板的翻页读到的是 + // 文章面板留下的值。只看当前面板,读不到就回落默认分组。 + var pageSub = panel.querySelector('[data-uh-sub].is-active'); + var sub = pageSub && pageSub.getAttribute('data-uh-sub') === 'following' ? 'following' : 'followers'; + loadPanelBody(panel, name, page, sub).catch(notifyLoadError); }); switchTo(defaultTab); diff --git a/tests/widget-system/post-visual-contract.test.cjs b/tests/widget-system/post-visual-contract.test.cjs index 9cd3c69d..f10e6d06 100644 --- a/tests/widget-system/post-visual-contract.test.cjs +++ b/tests/widget-system/post-visual-contract.test.cjs @@ -593,6 +593,15 @@ test('public user home stays param-free and swaps panels via REST fragments', () assert.match(authorJs, /data-uh-sub/); assert.match(authorJs, /post_ajax\.ed/); assert.match(authorJs, /window\.auto_fun\(\)/); + + // 翻页拿子分组只读**当前面板内**的 is-active 子页签,不读 panel.dataset: + // uhSub 是粉丝面板私有状态,写满所有面板会互相串味 —— 先点过粉丝子页签, + // 残留值会长在文章面板上,之后粉丝面板翻页读到的是别人的分组。 + assert.match(authorJs, /panel\.querySelector\('\[data-uh-sub\]\.is-active'\)/); + assert.doesNotMatch(authorJs, /loadPanelBody\(panel, name, page, panel\.dataset\.uhSub/); + // uhPage / uhSub 只写粉丝面板;文章 / 收藏 / 评论面板没有子页签。 + assert.match(authorJs, /if \(name === 'follow'\) \{[\s\S]{0,120}panel\.dataset\.uhSub = followSub;/); + assert.doesNotMatch(authorJs, /var followSub = sub \|\| panel\.dataset\.uhSub \|\| 'followers';/); }); test('single articles enqueue only content and settings driven assets', () => {