fix(author): keep the follow sub-tab state out of the other panels
uhSub(粉丝/关注)只属于粉丝面板,loadPanelBody 却把它写在每一个面板上, 翻页时又从被点面板自身读回,于是分组状态跨面板串味:先点粉丝 tab 切到 「关注」,再点文章 tab 翻页,#panel-posts 会被永久打上 data-uh-sub= "following",之后粉丝面板的翻页读到的是文章面板残留的分组。 翻页改为只读**当前面板内**的 .is-active 子页签,读不到就回落默认分组; uhPage / uhSub 也只在粉丝面板写入,文章 / 收藏 / 评论面板一次都不碰。 目标面板本身仍由被点面板的 id 反解,跨面板跳转这条路径不存在,本次不动。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+15
-4
@@ -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);
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user