Grid: Link 字段需要移动鼠标才能点击关联记录 chip
Bug 描述
在 Grid 视图中,点击 link 字段进入编辑模式后,如果不移动鼠标直接点击关联记录的 chip(标签),会打开"选择关联记录"面板,而不是展开关联记录详情。需要先移动一下鼠标(哪怕 1px),cursor 变成小手后再点击才能正确打开。
复现步骤
- 打开包含 link 字段的 Grid 视图,link 字段中已有关联记录
- 点击某个 link 单元格,使其进入编辑模式(cell 放大,chip 可见)
- 不移动鼠标,直接点击某个关联记录 chip
期望行为:打开该关联记录的详情(expand record) 实际行为:打开"选择关联记录"面板,和点击空白区域效果一样
- 现在移动鼠标(哪怕 1px),cursor 变成小手 pointer
- 再点击 chip → 这次正确打开了关联记录详情
视频对比
Teable(bug — 必须先动鼠标才能点击 chip):
https://github.com/user-attachments/assets/10464d20-de7c-4a27-a5cf-3c4980f2db3c
NocoDB(正确 — 进入编辑模式后可直接点击 chip):
https://github.com/user-attachments/assets/cc3f1f3e-d88d-42ae-9409-94b5d907b7b1
原因分析
问题在 InteractionLayer.tsx 的 onClick handler 中,调用 cellRenderer.onClick 前检查了 hoverCellPosition:
if (onCellClick && hoverCellPosition) {
onCellClick(cell, { ..., hoverCellPosition, ... }, callback);
}
hoverCellPosition 只在 onMouseMove 中通过 useRafState 更新。用户点击时如果没有移动鼠标,hoverCellPosition 仍然是上一次 render 的旧值(null),导致整个 onCellClick 分支被跳过。
useRafState(来自 react-use)通过 requestAnimationFrame 延迟 setState,即使程序化触发 mousemove 事件也无法在同一个事件循环内更新到最新值。
建议修复
在 onClick 中,当 hoverCellPosition 为 null 时重新计算:
case RegionType.ActiveCell: {
const cell = getCellContent([columnIndex, rowIndex]);
const cellRenderer = getCellRenderer(cell.type);
const onCellClick = cellRenderer.onClick;
const isActive = /* ... */;
// 当 hoverCellPosition 为 null 时用当前 mouseState 重新计算
const effectiveHoverCellPosition = hoverCellPosition ?? getHoverCellPosition(getMouseState());
if (onCellClick && effectiveHoverCellPosition) {
onCellClick(cell, { ..., hoverCellPosition: effectiveHoverCellPosition, ... }, callback);
}
}
环境
- Teable 版本:latest Docker (
ghcr.io/teableio/teable:latest) - 浏览器:Chrome 136
- 系统:macOS
整体体验上的差距就是在nocodb里面,当我想点击单元格里的小卡片,我只要鼠标瞄准那儿,哪怕我点得很快,就可以直接点开那个卡片的具体内容. 但是在teable里面,我需要点开那个单元格,然后再动一下鼠标,再继续瞄准一次我想点开那个卡片,才能打开我想要那个内容 需要瞄准2次
@androidfans thanks for the detailed report.
This has been addressed in the current version. Please update to the latest version and try again.
Closing this as completed. If the problem still happens on the current version, please reopen this issue with updated reproduction details.
After further investigation, we found this change may cause other field editing issues. We will revert this change for now and continue working on a better solution.
Thanks for the report.