fix: 修复返回按钮双重绑定导致的重复请求
从帖子详情点返回时,posts / stats / links 三个接口各发出两次请求。
nginx 访问日志确认了这一点(13:40:12 同一秒内两组完整请求)。
根因是返回按钮被绑定了两次:
index.html: <button class="back-btn" onclick="switchPage('feed')">
app.js: btn.addEventListener('click', () => navigateBackToFeed());
一次点击同时触发内联 onclick 与监听器,于是整组渲染各跑一遍。
已移除 4 处内联 onclick,统一由 app.js 的监听器调用
navigateBackToFeed()——它额外处理了转场方向与 URL 同步。
同时清理了两处多余的渲染调用:
- post.js 删除帖子成功后先调 switchPage('feed'),又调 renderFeed 与
renderStats。switchPage('feed') 内部本就会调用这三个函数。
- app.js 发布帖子成功后同样重复调用。
顺带说明:auth.js 中登录与注册后的写法是 if / else if 互斥分支
(switchPage('feed') 与 renderFeed 二选一),不存在重复,未作改动。
实测(Puppeteer 走完整用户路径:首屏 → 点进帖子 → 点返回):
- 首屏:posts / stats / links 各 1 次
- 进入详情:0 次(数据已缓存)
- 点返回:posts / stats / links 各 1 次,无重复
完整测试套件 25/25 通过。
This commit is contained in:
1 parent
d16ed6c1e8
commit
9844988cf2
3 files changed
+8
-9
No files matched your search
+4
-4
@@ -158,7 +158,7 @@
|
||||
<!-- 设置页面 -->
|
||||
<div id="pageSettings" class="page-slide">
|
||||
<div class="page-header" style="max-width:1200px;margin:0 auto;width:100%;">
|
||||
<button class="back-btn" onclick="switchPage('feed')">
|
||||
<button class="back-btn">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg>
|
||||
返回
|
||||
</button>
|
||||
@@ -206,7 +206,7 @@
|
||||
<!-- 管理后台 -->
|
||||
<div id="pageAdmin" class="page-slide">
|
||||
<div class="page-header" style="max-width:1200px;margin:0 auto;width:100%;">
|
||||
<button class="back-btn" onclick="switchPage('feed')">
|
||||
<button class="back-btn">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg>
|
||||
返回
|
||||
</button>
|
||||
@@ -307,7 +307,7 @@
|
||||
<!-- 帖子详情页 -->
|
||||
<div id="pagePost" class="page-slide">
|
||||
<div class="page-header" style="max-width:1200px;margin:0 auto;width:100%;">
|
||||
<button class="back-btn" onclick="switchPage('feed')">
|
||||
<button class="back-btn">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg>
|
||||
返回
|
||||
</button>
|
||||
@@ -359,7 +359,7 @@
|
||||
<!-- 用户主页 -->
|
||||
<div id="pageUser" class="page-slide">
|
||||
<div class="page-header" style="max-width:700px;margin:0 auto;width:100%;">
|
||||
<button class="back-btn" onclick="switchPage('feed')">
|
||||
<button class="back-btn">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg>
|
||||
返回
|
||||
</button>
|
||||
|
||||
Reference in new issue
Block a user