Skip to content

bug(frontend): 非首页页面点击展开公告按钮无法看到公告 — AnnouncementBar 仅在 isHome 时渲染 #163

Description

@yzxoi

用户反馈

web端公告逻辑混乱,在非首页页面,点击展开公告按钮无法看到公告。

在非首页页面(如 /about, /faq, /course/:id 等),导航栏会显示一个铃铛按钮(展开公告),点击后会将 announcementCollapsed 状态设为 false,但由于 AnnouncementBar 组件仅在 {isHome && (...)} 条件下渲染(App.tsx 第 715 行),非首页页面上没有对应的公告栏组件存在于 DOM 中,因此按钮点击后无任何视觉效果。

意图判断

  • 类型: bug_report
  • 相关仓库: Serverless
  • 相关模块: frontend

去重检查

未发现语义重复的 open/closed issue。

代码静态扫描结果

相关文件:

  • frontend/src/App.tsx(第 715 行):{isHome && (<AnnouncementBar ... />)} — 公告栏仅在首页渲染
  • frontend/src/App.tsx(第 438-444 行):announcementCollapsed 状态在 localStorage 中持久化,全局生效
  • frontend/src/App.tsx(第 711 行):Navbar 接收 announcementCollapsed 和 onToggleAnnouncementCollapsed
  • frontend/src/components/Navbar.tsx(第 124 行):showAnnouncementBell = Boolean(announcementCollapsed && onToggleAnnouncementCollapsed) — 铃铛按钮在 collapsed 为 true 时显示
  • frontend/src/components/Navbar.tsx(第 218-225 行):铃铛按钮的 onClick 调用 onToggleAnnouncementCollapsed,即 () => setAnnouncementCollapsedPersist(false)

问题根因:
announcementCollapsed 状态被 Navbar 和 AnnouncementBar 共享,但 AnnouncementBar 通过 isHome && 条件限定仅在首页渲染。非首页无论 collapsed 状态如何,DOM 中都没有 AnnouncementBar 组件。Navbar 铃铛按钮操作了状态但 UI 端没有消费方,导致点击无反应。

Proposed Fix

移除 isHome && 条件,让 AnnouncementBar 在所有页面均可渲染。由于 AnnouncementBar 本身已有 collapsed 属性控制展开/收起(collapsed 为 true 时返回 null),且布局不会因此破坏,建议将:

{isHome && (
<AnnouncementBar ... />
)}

改为:

<AnnouncementBar ... />

Reporter: 七爷 (QQ: 1798106406)
来源: QQ 反馈群

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:frontendFrontend / React appbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions