From e953bb116846c1f18e661ef677c9dca0de9c3a54 Mon Sep 17 00:00:00 2001 From: fylorn <249551762+fylorn@users.noreply.github.com> Date: Tue, 22 Sep 2026 16:22:22 +0800 Subject: [PATCH] fix(traffic): keep the table header pinned while the list scrolls The header has carried `sticky top-0` since #8, but it stopped sticking in #15, when it moved inside shadcn's `Table`. That component wraps the table in a div with `overflow-x: auto`, and a box that scrolls on one axis is a scroll container on both: the other axis's `visible` computes to `auto`. The header stuck to that div, which never scrolls vertically, so it went up with the rows. 600px down the list it sat 540px above the top of the scroller. `Table` gets a `scroll` prop. The request table turns it off, so the header sticks to the page's scroller instead. The wrapper was doing real work, though. At the minimum window width with the sidebar expanded the table is 808px in a 584px column, and without the wrapper the page's scroller takes the horizontal overflow too, which would slide the filter bar sideways with the table. So the page is split into three blocks. The filter bar (with the no-upstream notice) and the footnote are direct children of the scroller with `sticky left-0`: that makes them exactly as wide as what is visible, and they stay put while the table scrolls sideways. The table sits in a `w-fit min-w-full` block that grows with it, so its right padding still scrolls into view. The horizontal scrollbar now sits at the bottom of the window rather than under the last of two hundred rows. Two things only showed once the header actually stuck: - The table uses collapsed borders, and a collapsed border is painted by the table, not the row, so the line under the header stayed behind and scrolled away with the rows. The header cells draw it as an inset shadow instead, which moves with them. - The header's background was neutral-50/950, which no longer matches the window ground (#f7f8fa / #0c0e11); rows passing under it would show a band. It uses `bg-background` now. Not taken: pinning the filter bar above a table that scrolls on both axes costs 60-96px of list height at every window size, about two rows; `overflow-x: clip` cuts off the cost column at the minimum width. Also points three comments that still sent readers to `Split`, removed in #82, at the scroll layer that exists now. Co-Authored-By: Claude Opus 5 --- src/App.tsx | 26 ++++++++++++++++++++------ src/traffic/RequestTable.tsx | 12 ++++++++++-- src/ui/table.tsx | 17 +++++++++++++++-- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 9a613925..f932e372 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1014,8 +1014,8 @@ export default function App() { 滚动条,而外面那层会把整个分栏一起推走。 */} {/* - 工具栏之下这一层。**滚动不在这儿** —— 请求页交给 `Split` - (分栏时两栏各滚各的),其余页面各自在自己的容器里滚。 + 工具栏之下这一层。**滚动不在这儿** —— 请求页在自己那一层里 + 横竖都滚,其余页面各自在自己的容器里滚。 在这儿再加一层滚动就是两层滚动条。 */}
@@ -1144,12 +1144,12 @@ export default function App() { {/* **每一面自己滚。**工具栏钉在上面不动,这一层只负责给出高度; - 真正滚的是下面这个容器(请求页是 `Split` 里的两栏各滚各的)。 + 真正滚的是下面这个容器(请求页是它自己的那一层,见下面)。 */}
setNudge((n) => n + 1)} /> ) : ( -
+
{/* 详情走**浮层**,不拆栏。 @@ -1274,8 +1274,18 @@ export default function App() { `sticky top-0`,吸顶的位置从滚动容器的内边距以内算起 —— 把上边距加在滚动容器上,往下翻时表头停在离顶 20px 处,行从它上面那条缝里漏出来。 + + **横着滚的也是这一层。**最小窗口、侧栏展开时,表有 + 808px,页面只有 584px。表外面那层自己横着滚的话, + 表头就钉在它身上、不再吸顶(见 `Table` 的 `scroll`)。 + + 所以分成三块。上面的过滤条、下面的脚注钉在左边 + (`sticky left-0`),表横着滚时它们不跟着走。它们 + 必须直接挂在这一层下面:宽度才是看得见的那么宽, + 钉得住的范围也才是整个能滚的宽度。中间那块跟着表 + 变宽(`w-fit`),滚到最右,表的右边距才露得出来。 */} -
+
{/* 过滤条。**一直在,不是「有数据才出现」** —— 一个时有时无的 工具条,用户每次都要重新找它在哪儿。没有请求时它是禁用的。 @@ -1424,6 +1434,8 @@ export default function App() {
)} +
+
{seeded && rows.length === 0 ? ( allRows.length > 0 ? ( /* @@ -1505,6 +1517,8 @@ export default function App() { }} /> )} +
+
{locallyAnswered > 0 && rows.length > 0 && (

{t.probesElsewhere(locallyAnswered)} diff --git a/src/traffic/RequestTable.tsx b/src/traffic/RequestTable.tsx index 1a8b7743..59557dc1 100644 --- a/src/traffic/RequestTable.tsx +++ b/src/traffic/RequestTable.tsx @@ -74,13 +74,21 @@ export function RequestTable({ }) { const t = useText(appText); return ( - +
{/* **表头必须钉住。**这张表滚两屏之后就没有列名了,而并排的 两列毫秒数,不看列名根本分不出哪个是首字节哪个是总耗时 —— 那恰恰是排查时唯一要看的区别。 + + 钉在页面的滚动层上,所以上面的 `scroll={false}` 不能去掉:表外 + 那层一旦能横着滚,表头就钉在它身上,不会吸顶。底色要和窗口底 + 同色,吸顶之后行从它下面滚过,差一档灰就是一条色带。 + + **底线画在格子里,不用行的边框。**表格是合并边框,那条边框归 + 表格画,表头钉住之后它留在原处跟着行滚走,表头和第一行之间就 + 没有线了。格子内侧的阴影跟着格子走。 */} - +
) { +function Table({ + className, + scroll = true, + ...props +}: React.ComponentProps<"table"> & { + /** + * `false`:外面这层不再横着滚,太宽的表交给页面的滚动层去滚。 + * + * **表头要吸顶就得关掉它。**`overflow-x: auto` 会让这层在竖直方向上 + * 也成为滚动容器(另一个方向的 `visible` 被算成 `auto`),于是 + * `sticky` 的表头钉在这层上 —— 而它从来不竖着滚,表头就跟着页面走了。 + */ + scroll?: boolean +}) { return (