Skip to content

fix(web): file-chip first-click jump#67

Merged
SymbolStar merged 2 commits into
mainfrom
judy/fix-file-chip-first-click
Jun 11, 2026
Merged

fix(web): file-chip first-click jump#67
SymbolStar merged 2 commits into
mainfrom
judy/fix-file-chip-first-click

Conversation

@SymbolStar

Copy link
Copy Markdown
Owner

Scott 反馈:thread 里第一次点 file-chip 经常跳转失败,第二次才行。

根因

  1. 同 hash 不重触发:chip 完全靠浏览器 fire hashchange 来触发 routeFromHash。当 location.hash 已经等于 chip 的 href(例如从 viewer 返回 thread 后再点同一个 chip),hashchange 根本不 fire → 路由不跑 → chip 看上去像死的。
  2. missing chip 死窗口:未注册的 [[ref:xxx]] 渲染成 <span class=file-chip-missing>(没有 href),scheduleRefIndexRefresh 大概 150ms 后才重绘成 <a>,第一次点正好命中那个死 span。

修法

document 上挂一个 capture-phase click 委托:

  • 命中 .file-chip-ref / .file-chip / .file-chip-missingpreventDefault
  • 已解析的 chip:hash 不同就设 hash,hash 相同直接调 window.__forgeRouteFromHash() 强制走路由。
  • missing chip:await loadRefIndex(true) 强刷一遍 refs,再 resolveChipFromRefs(target);命中就跳,不命中 toast 提示。
  • 保留 Cmd/Ctrl/Shift-click(新标签页等浏览器默认)和 .file-chip-fav(⭐ 收藏按钮)原有行为。

验证(请 scott 拉一下 main 上 rebase 后试)

  1. 点一个 chip → FILES 打开、viewer 显示对应文件(首次必中)。
  2. 关闭/返回 thread,再点同一个 chip → 仍然能切回 viewer。
  3. 点一个刚发出来还没 resolve 的 [[ref:xxx]](灰色 ⚠️) → 应该自动 refresh + 跳。
  4. Cmd+click chip → 浏览器照常处理(新标签语义保留)。

Scott reported first click on a thread file-chip often does not jump
to the ref viewer; second click works.

Root causes:
1. Chips relied entirely on the browser firing hashchange. When the
   current hash already equals the chip href (e.g. after closing the
   viewer and clicking the same chip again), hashchange does NOT fire,
   so routeFromHash never runs.
2. Unresolved [[ref:xxx]] tokens render as <span class=file-chip-missing>
   with no href; a background refresh repaints them ~150ms later, but
   the very first user click hits the dead span.

Fix: capture-phase document click listener for .file-chip /
.file-chip-ref / .file-chip-missing — preventDefault and either set the
hash or call routeFromHash directly when hash is already on target. For
missing chips, await a forced loadRefIndex(true) and retry resolve before
toasting.

No behavior change for Cmd/Ctrl/Shift-click (preserves new-tab etc.) and
for star (.file-chip-fav) clicks (existing handler still wins).
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

🤖 bot-review (comment-only · phase 1)

Diff: 4 files changed, 132 insertions(+), 1 deletion(-) @ 8d77356

Red-line checks:

  • ✅ A-7.5: no new 'forbidden' code in xiaof

Phase 1: this bot leaves comments only. Auto-approve will be enabled per-path after 1–2 weeks of clean runs. Promotion plan: judy PR #42 follow-up.

Scott 2026-06-09: typo like @name produced a red 'Unknown agent id'
failure chip. Filter unknown ids at the router (forge_employees.is_employee)
so misspelled mentions are dropped silently instead of dispatching a
worker that's guaranteed to fail.

- post_router.enqueue_if_needed: after self-/reserved-mention dedupe,
  drop any key for which is_employee() is False. Defensive try/except
  falls back to dispatch on registry errors.
- tests/conftest.py + test_post_router.py: router fixture now stubs
  is_employee=True so existing synthetic-id tests still cover dispatch;
  added two new tests for the drop path (mixed known+unknown, and all
  unknown -> False).

Test: pytest -q (all green).
@SymbolStar SymbolStar merged commit 394a839 into main Jun 11, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant