fix(导航): 关闭聊天/信息面板改为真实返回,不再新增历史记录

用户反馈:从会话列表打开聊天A,点页面自己的"返回"关掉聊天,再打开聊天B,这时候点
浏览器的返回键,会先回到列表,再点一次返回又跳回了聊天A——因为"关闭"这个动作和"打开"
一样都在往浏览器历史里push新记录,而不是弹出(pop)"打开"时push的那条,导致聊天A那条
记录一直遗留在历史栈里,多按一次返回就会被重新翻出来。

两处受影响、同一根因:
- tinode-web.jsx 的 handleHideMessagesView(移动端聊天页左上角"←",messages-view.jsx
  的#hide-message-view)——打开聊天(handleTopicSelected)是真实push,关闭时原来无条件
  再push一条"没有话题"的状态,现在改成先尝试HashNavigation.goBack(),找不到可回退的
  历史才退回原来的push方式。
- info-view.jsx 的 handleBackNavigate(旧版InfoView自己的返回/关闭按钮,目前只有"已
  保存的消息"这一个话题还在用它,好友/群的资料页已经在更早的章节改用真正修过返回逻辑
  的friend-settings/group-settings)——同样的问题,同样的修法。

已在浏览器验证:连续"开聊天A→点返回关闭→开聊天B"后,浏览器返回键能一次性回到聊天A
从未存在过一样,不会再被重新翻出来;InfoView的关闭按钮点击后hash是异步变化的(真实
history.back()的特征),不再是原来同步的push。
This commit is contained in:
Your Name
2026-09-06 12:29:56 +08:00
parent 4fc65b0f40
commit 693265658f
6 changed files with 140 additions and 111 deletions
+12 -2
View File
@@ -1432,12 +1432,22 @@ class TinodeWeb extends React.Component {
}
}
// In mobile view user requested to show sidepanel
// In mobile view user requested to show sidepanel (this is the chat's own "<-" back arrow,
// #hide-message-view in messages-view.jsx). Opening a topic (handleTopicSelected) is a real
// navigateTo() push, so closing it should be the matching pop -- goBack() first, same pattern as
// content-library-view.jsx's Header back button. Before this fix it unconditionally pushed a new
// "no topic" hash entry instead of popping the "topic open" one: open chat A (push) -> tap back
// (push again, but the "chat A open" entry from a moment ago is left sitting right underneath,
// never consumed) -> open chat B (push) -> the system back button then has to be pressed twice to
// leave the chat area at all, and the second press lands back on chat A, not wherever the user
// actually came from before opening any chat.
handleHideMessagesView() {
this.setState({
mobilePanel: 'sidepanel'
});
HashNavigation.navigateTo(HashNavigation.setUrlTopic(window.location.hash, null));
if (!HashNavigation.goBack()) {
HashNavigation.navigateTo(HashNavigation.setUrlTopic(window.location.hash, null));
}
}
// User is sending a message, either plain text or a drafty object, possibly