Skip to content

Commit 7939732

Browse files
fix(components): a wide table's right seam shadow shows when the table widens after its rows are drawn (#37253)
Fixes #37239 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:管理员在工作室「全部元数据」列表(例如共享规则)里,表格比可视区域宽时,右侧固定列前那道提示「右边还有列」的阴影现在每次都会出现;以前大约一半的打开次数不出现。 - 为什么做:夜间回归测试因此变红(共享规则列表在 1440 宽下的可达性检查),这是让它恢复的产品修复。 - 出错会怎样:最坏只是宽表右侧阴影不显示或多显示一次,不影响数据和操作;改动可直接撤回。 - 要你做什么:无。 ## What changes - `ui/packages/components/src/custom/use-horizontal-overflow.ts` (`useHorizontalOverflow`): the box re-reads its overflow when the box, each child of the box, **or each child's own children** resize. Before, it watched the box and its direct children only. - Why that matters: every table here sits inside the shadcn `Table` wrapper (`relative w-full`, `overflow-visible` inside a box that scrolls). The wrapper keeps the box's width, so when the table element widens past the box with no row added and the box unchanged, no observer fired, `overflowRight` stayed `false`, and `data-table`'s right seam shadow (`data-table-scroll-shadow-right`) was never drawn. - The same hook drives `HorizontalOverflowBox` (`data-overflow-right` and its edge or pinned seam), so a table placed in that box inside a wrapper (the approvals inbox mounts one that way) follows the table's width too. Pinned below; not measured live. - Changeset: `@object-ui/components` patch. ## Why Nightly `nightly-tiers` run 45554381420 (`0a1b69c0b`) failed `ui/e2e/live/declared-sharing-rules-reach-13091.spec.ts`: the seam shadow was not found within 5 s although the table's scroll box was wider than its client box. **Which suspect it is.** #36978 (`c48f06c87`, the metadata list on ObjectGrid) is the change that exposed it, and is not itself wrong. It moved the list onto `data-table` and pointed the spec at `data-table`'s shadow. That shadow carried a latent defect in `useHorizontalOverflow`, and the new list's layout hits it about half the time. #37089 (the permission set full-screen) is ruled out: it does not touch this list's grid or the overflow hook. Nothing else changed the data-table seam shadow between the last green nightly (`d9c799c10`, 2026-11-24) and the red one. The only other `data-table.tsx` edit in that window is #37124 (the footer summary row), which does not touch the overflow read. **Measured DOM** (Chromium 1440x1000, this tree's Console against the workspace showcase backend, a requestAnimationFrame log of the scroll box from first paint): ``` before the fix, a failing open (12 of 20 opens ended like this): +1315ms sw=1134 cw=1134 child=1134 table=1134 rows=3 shadow=false rows drawn, the table fits +1331ms sw=2168 cw=1134 child=1134 table=2168 rows=3 shadow=false the columns widen the table +1384ms sw=1826 cw=1134 child=1134 table=1826 rows=3 shadow=false ...and it stays without a shadow a passing open: the table is already wider than the box when the rows draw (sw=1826 at the first frame) after the fix (20 of 20 opens with a shadow), the same sequence: +1379ms sw=1134 cw=1134 child=1134 table=1134 rows=3 shadow=false +1391ms sw=2168 cw=1134 child=1134 table=2168 rows=3 shadow=false +1427ms sw=1826 cw=1134 child=1134 table=1826 rows=3 shadow=true ``` `child` is the wrapper, the box's only child, and it stays at 1134 throughout. That is why the old read never ran. The scrollbar-at-rest read in `data-table` already observed the table element itself, which is why the bar showed while the shadow did not. So the product regressed, and the spec is unchanged. It still measures that the controls are in reach and that a seam shows while columns remain to the right. ## Tests - `data-table-scroll-shadow-12463.test.tsx`: a new top-level describe. A recording `ResizeObserver` calls back only the observers watching the element that resized, as a browser does. The table element alone grows past the box (no scroll, no row added), and the shadow is drawn. CONTROL: a table that grows but still fits draws none. - `horizontal-overflow-12708.test.tsx`: a new top-level describe, the same reading for `HorizontalOverflowBox` with a wrapped table. CONTROL: a resize of the wrapper itself still re-reads. Read first (by risk): 1. `use-horizontal-overflow.ts`: the nested observe loop. It adds observers on grandchildren and changes no read. 2. `data-table-scroll-shadow-12463.test.tsx`: the recording observer and the new describe. Two-minute check: `pnpm --dir ui exec vitest run packages/components/src/renderers/complex/__tests__/data-table-scroll-shadow-12463.test.tsx`. Expect 8 passed, including "draws the shadow once the table alone grows past the box". <details><summary>Unit and package runs at ddb6f6f: both pin files 15/15; the whole components package 510 files passed, 1 skipped; type-check green</summary> ``` pnpm --dir ui exec vitest run --maxWorkers=2 packages/components/src/renderers/complex/__tests__/data-table-scroll-shadow-12463.test.tsx packages/components/src/__tests__/horizontal-overflow-12708.test.tsx Test Files 2 passed (2) Tests 15 passed (15) pnpm --dir ui exec vitest run --maxWorkers=2 packages/components/ Test Files 510 passed | 1 skipped (511) Tests 4970 passed | 24 skipped (4994) os-verify-lock: VERDICT command-exit 0 pnpm --filter @object-ui/components type-check (tsc --noEmit && tsc -p tsconfig.test.json, the ui/ dependency closure built first) os-verify-lock: VERDICT command-exit 0 ``` </details> <details><summary>Local gate families at ddb6f6f: 38 derived, 38 run, every one exit 0</summary> ``` node scripts/pm/dispatch-gates.mjs --ran FILE Run reconciliation — 38 derived, 38 run, 0 NOT-MEASURED, 0 UNRUN. ✓ dispatch-gates --ran: 38 derived famil(ies) accounted for — 38 run, 0 NOT-MEASURED (a DERIVED zero — all 38 recorded an exit code and none of them is 3). pnpm check:test-source-alias -> exit 0 node scripts/pm/overlap-check.mjs -> VERDICT clean exit 0 (origin/main; and with --pr=37168,37169,37166,37226: every one merges cleanly) ``` </details> ## Acceptance notes - Ablation (one run, both pins, `scripts/ablation-replace.mjs`): deleting the grandchild-observe line, `anchor 1 -> 0, blob 7965aaa -> aae15c0c6be7`, makes both new pins fail. The data-table one fails with "Unable to find an element by: data-testid=data-table-scroll-shadow-right", and both CONTROLs stay green (`Tests 2 failed | 13 passed (15)`). Restored: `blob == HEAD (7965aaa)`, `git diff HEAD` empty. Both test files import the hook from source, so no build is involved. - Size: 4 files, 182 changed lines (176+, 6-). - Deviation: part of the scratchpad logs (the raw Playwright and probe outputs) was deleted mid-session by a process this run does not own. The readings above were copied from those runs as they finished. ## Verification The stack the nightly boots, step for step: `ui/e2e/live/ci/start-backend.sh` (this tree's CLI serving `examples/app-showcase`, a throwaway database), the Console built with `VITE_BASE_PATH=/` and served by `vite preview`, then Playwright from `ui/` with `playwright.live.config.ts`, Chromium. <details><summary>Before the fix (main at d7f299c): the spec fails 5 of 10 repeats, with the nightly's error</summary> ``` playwright test --config=playwright.live.config.ts declared-sharing-rules-reach-13091.spec.ts --repeat-each=10 Error: expect(locator).toBeVisible() failed (Locator: getByTestId('data-table-scroll-shadow-right').first()) 5 failed 5 passed (57.3s) ``` </details> <details><summary>After the fix (Console rebuilt from this branch): 20 of 20, and the whole nightly list 28 of 28</summary> ``` playwright test --config=playwright.live.config.ts declared-sharing-rules-reach-13091.spec.ts --repeat-each=20 20 passed (55.0s) pnpm --dir ui run test:e2e:live:nightly (the 14 spec files console-live-specs.live.test.ts runs) 28 passed (1.7m) ``` </details> The backend and the preview server this run started were stopped by their recorded PIDs. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (not touched) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. (CI) - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: n/a. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYnxVj5xoUcFUWLa5Aw)_ <!-- signed: repo:objectstack#4 · os-justin · session_01QSeKYkkwuF6UuFtu85Yd5H --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9171bed commit 7939732

4 files changed

Lines changed: 176 additions & 6 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/components': patch
3+
---
4+
5+
fix(components): a wide table's right seam shadow shows when the table widens after its rows are drawn
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
- A table wider than its box draws a shadow at its right seam while columns remain to the right. The box only re-read its overflow when the box itself or the element directly inside it changed size. A table sits inside a full-width wrapper that keeps the box's width, so when the columns widened the table after the rows were drawn (no row added, the box unchanged), the shadow never appeared, about half the time on the Studio metadata list at 1440 px. The box now also watches what sits inside that wrapper, so the shadow follows the table's own width. The same fix applies to every page that puts a table in the shared overflow box (for example the approvals inbox).

‎ui/packages/components/src/__tests__/horizontal-overflow-12708.test.tsx‎

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* `data-table-scroll-shadow-12463` stubs it.
1414
*/
1515

16-
import { describe, it, expect } from 'vitest';
16+
import { describe, it, expect, beforeAll, afterAll, afterEach, vi } from 'vitest';
1717
import { render, fireEvent, act } from '@testing-library/react';
1818
import '@testing-library/jest-dom';
1919
import React from 'react';
@@ -85,3 +85,77 @@ describe('HorizontalOverflowBox (objectui#12708)', () => {
8585
expect(hasOverflowRight({ scrollLeft: 0, clientWidth: 700, scrollWidth: 702 })).toBe(true);
8686
});
8787
});
88+
89+
/**
90+
* objectstack#37239 — a `<table>` inside a full-width wrapper (the shadcn
91+
* `Table`'s container, `overflow-visible`, as the approvals inbox mounts it)
92+
* widens past the box while the wrapper and the box keep their size. The box
93+
* re-reads its overflow when that table resizes. jsdom's `ResizeObserver` is an
94+
* inert polyfill, so a recording one stands in: `resize(el)` calls back only
95+
* the observers watching `el`, as a browser does when only `el` changed size.
96+
*/
97+
describe('HorizontalOverflowBox follows a table that widens inside a wrapper (objectstack#37239)', () => {
98+
const observed = new Map<Element, Set<ResizeObserverCallback>>();
99+
class RecordingResizeObserver {
100+
private readonly targets = new Set<Element>();
101+
constructor(private readonly callback: ResizeObserverCallback) {}
102+
observe(el: Element) {
103+
this.targets.add(el);
104+
if (!observed.has(el)) observed.set(el, new Set());
105+
observed.get(el)!.add(this.callback);
106+
}
107+
unobserve(el: Element) {
108+
this.targets.delete(el);
109+
observed.get(el)?.delete(this.callback);
110+
}
111+
disconnect() {
112+
for (const el of this.targets) observed.get(el)?.delete(this.callback);
113+
this.targets.clear();
114+
}
115+
}
116+
function resize(el: Element) {
117+
act(() => {
118+
for (const callback of Array.from(observed.get(el) ?? [])) callback([], {} as ResizeObserver);
119+
});
120+
}
121+
function setWidths(box: HTMLElement, scrollWidth: number, clientWidth: number) {
122+
Object.defineProperty(box, 'scrollWidth', { configurable: true, value: scrollWidth });
123+
Object.defineProperty(box, 'clientWidth', { configurable: true, value: clientWidth });
124+
}
125+
function renderWrapped() {
126+
return render(
127+
<HorizontalOverflowBox data-testid="box">
128+
<div className="relative w-full overflow-visible" data-testid="wrapper">
129+
<table><tbody><tr><td>wide</td></tr></tbody></table>
130+
</div>
131+
</HorizontalOverflowBox>,
132+
);
133+
}
134+
135+
beforeAll(() => { vi.stubGlobal('ResizeObserver', RecordingResizeObserver); });
136+
afterEach(() => { observed.clear(); });
137+
afterAll(() => { vi.unstubAllGlobals(); });
138+
139+
it('shows the shadow once the wrapped table alone grows past the box', () => {
140+
const { getByTestId, queryByTestId, container } = renderWrapped();
141+
const box = getByTestId('box');
142+
const table = container.querySelector('table')!;
143+
setWidths(box, 718, 718);
144+
resize(table);
145+
expect(queryByTestId('horizontal-overflow-shadow')).toBeNull();
146+
147+
setWidths(box, 1071, 718);
148+
resize(table);
149+
expect(getByTestId('horizontal-overflow-shadow')).toBeInTheDocument();
150+
expect(box).toHaveAttribute('data-overflow-right', 'true');
151+
});
152+
153+
it('CONTROL: a resize of the wrapper itself still re-reads, as it did before', () => {
154+
const { getByTestId, queryByTestId } = renderWrapped();
155+
const box = getByTestId('box');
156+
setWidths(box, 1071, 718);
157+
// The wrapper was watched before this fix; the pin above is about the table.
158+
resize(getByTestId('wrapper'));
159+
expect(queryByTestId('horizontal-overflow-shadow')).not.toBeNull();
160+
});
161+
});

‎ui/packages/components/src/custom/use-horizontal-overflow.ts‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ export function hasOverflowRight(box: Pick<HTMLElement, 'scrollLeft' | 'clientWi
1616
/**
1717
* Track {@link hasOverflowRight} for the box `ref` points at: read in a layout
1818
* effect, so the first painted frame is already right, and again on every
19-
* scroll and whenever the box or its content changes size. `false` while
20-
* `disabled` (the box does not scroll on its own).
19+
* scroll and whenever the box or its content (the box's children and their
20+
* children) changes size. `false` while `disabled` (the box does not scroll
21+
* on its own).
2122
*/
2223
export function useHorizontalOverflow(
2324
ref: React.RefObject<HTMLElement | null>,
@@ -38,8 +39,18 @@ export function useHorizontalOverflow(
3839
observer = new ResizeObserver(read);
3940
observer.observe(box);
4041
// The content's own size moves `scrollWidth` without resizing the box
41-
// (rows arrive, a column is resized).
42-
for (const child of Array.from(box.children)) observer.observe(child);
42+
// (rows arrive, a column is resized). The content is each child of the
43+
// box AND each child's own children: a table usually sits in a wrapper
44+
// that keeps the box's width (the shadcn `Table`'s `w-full` container,
45+
// `overflow-visible` inside a box that scrolls), so the wrapper never
46+
// resizes while the `<table>` in it widens past the box. Measured on
47+
// the Studio metadata list (objectstack#37239): the rows drew at the
48+
// box's width, then the columns widened the table from 1134 to 1826 px
49+
// with no row added, and a read keyed on the wrapper alone never ran.
50+
for (const child of Array.from(box.children)) {
51+
observer.observe(child);
52+
for (const grandchild of Array.from(child.children)) observer.observe(grandchild);
53+
}
4354
}
4455
return () => {
4556
box.removeEventListener('scroll', read);

‎ui/packages/components/src/renderers/complex/__tests__/data-table-scroll-shadow-12463.test.tsx‎

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* The layout itself (rows scrolling under a sticky header, the footer in
2121
* view) was read in a real browser and is reported on the pull request.
2222
*/
23-
import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
23+
import { describe, it, expect, beforeAll, afterAll, afterEach, vi } from 'vitest';
2424
import { render, fireEvent, act } from '@testing-library/react';
2525
import '@testing-library/jest-dom';
2626
import React from 'react';
@@ -187,3 +187,78 @@ describe('data-table scrollbar at rest while the table scrolls sideways (objects
187187
}
188188
});
189189
});
190+
191+
/**
192+
* objectstack#37239 — the shadow follows the TABLE's own width, not only the
193+
* box's and the rows'. The Studio metadata list draws its rows while the table
194+
* still fits its box, then its columns widen the `<table>` past the box with no
195+
* row added and no change to the box (measured in a real browser: 1134 → 1826
196+
* px inside a 1134 px box). The `<table>` sits in the shadcn `Table` wrapper,
197+
* which keeps the box's width, so only an observer on the `<table>` itself sees
198+
* that change.
199+
*
200+
* jsdom has no layout and its `ResizeObserver` is an inert polyfill, so this
201+
* stands in a recording one: `resize(el)` calls back every observer watching
202+
* `el`, and no other, which is what a browser does when only `el` changed size.
203+
*/
204+
describe('data-table shadow when the table widens inside an unchanged box (objectstack#37239)', () => {
205+
const observed = new Map<Element, Set<ResizeObserverCallback>>();
206+
class RecordingResizeObserver {
207+
private readonly targets = new Set<Element>();
208+
constructor(private readonly callback: ResizeObserverCallback) {}
209+
observe(el: Element) {
210+
this.targets.add(el);
211+
if (!observed.has(el)) observed.set(el, new Set());
212+
observed.get(el)!.add(this.callback);
213+
}
214+
unobserve(el: Element) {
215+
this.targets.delete(el);
216+
observed.get(el)?.delete(this.callback);
217+
}
218+
disconnect() {
219+
for (const el of this.targets) observed.get(el)?.delete(this.callback);
220+
this.targets.clear();
221+
}
222+
}
223+
function resize(el: Element) {
224+
act(() => {
225+
for (const callback of Array.from(observed.get(el) ?? [])) callback([], {} as ResizeObserver);
226+
});
227+
}
228+
function setWidths(box: HTMLElement, scrollWidth: number, clientWidth: number) {
229+
Object.defineProperty(box, 'scrollWidth', { configurable: true, value: scrollWidth });
230+
Object.defineProperty(box, 'clientWidth', { configurable: true, value: clientWidth });
231+
}
232+
233+
beforeAll(() => { vi.stubGlobal('ResizeObserver', RecordingResizeObserver); });
234+
afterEach(() => { observed.clear(); });
235+
afterAll(() => { vi.unstubAllGlobals(); });
236+
237+
it('draws the shadow once the <table> alone grows past the box, with no scroll and no row added', () => {
238+
const { getByTestId, queryByTestId, container } = renderTable(baseSchema);
239+
const box = getByTestId('data-table-scroll-box');
240+
const table = container.querySelector('table')!;
241+
// The wrapper between the box and the table: the element a read keyed on
242+
// the box's children alone would watch. It is not the table.
243+
expect(table.parentElement).not.toBe(box);
244+
expect(table.parentElement!.parentElement).toBe(box);
245+
246+
// The rows are drawn and the table fits its box: no shadow.
247+
setWidths(box, 1134, 1134);
248+
resize(table);
249+
expect(queryByTestId('data-table-scroll-shadow-right')).toBeNull();
250+
251+
// The columns widen the table; the box, its wrapper and the rows do not change.
252+
setWidths(box, 1826, 1134);
253+
resize(table);
254+
expect(getByTestId('data-table-scroll-shadow-right')).toBeInTheDocument();
255+
});
256+
257+
it('CONTROL: a table that grows yet still fits its box draws no shadow', () => {
258+
const { getByTestId, queryByTestId, container } = renderTable(baseSchema);
259+
const box = getByTestId('data-table-scroll-box');
260+
setWidths(box, 900, 1134);
261+
resize(container.querySelector('table')!);
262+
expect(queryByTestId('data-table-scroll-shadow-right')).toBeNull();
263+
});
264+
});

0 commit comments

Comments
 (0)