Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (codex): measure overflow live on focus instead of reading lagging state (#4170)

Adam Eivyc5e2bb865e82
diff --git a/client/src/components/ui/CollapsibleText.jsx b/client/src/components/ui/CollapsibleText.jsx
index 0655cd6b65..84d54eed62 100644
--- a/client/src/components/ui/CollapsibleText.jsx
+++ b/client/src/components/ui/CollapsibleText.jsx
@@ -73,6 +73,11 @@ const CLAMP_CLASS = {
*
* `id` is required: it wires the toggle's `aria-controls` to the content it expands.
*/
+
+// The 1px slack absorbs sub-pixel line-height rounding, which otherwise reports
+// a phantom overflow on content that fits exactly.
+const overflows = el => el.scrollHeight > el.clientHeight + 1;
+
export default function CollapsibleText({
id,
text,
@@ -105,7 +110,7 @@ export default function CollapsibleText({
if (expanded) return;
const el = ref.current;
if (!el) return;
- const measure = () => setIsOverflowing(el.scrollHeight > el.clientHeight + 1);
+ const measure = () => setIsOverflowing(overflows(el));
measure();
if (typeof ResizeObserver === 'undefined') return;
const observer = new ResizeObserver(measure);
@@ -132,7 +137,10 @@ export default function CollapsibleText({
// Expanding on focus keeps the claim honest and the target on screen.
// Gated on real overflow: content that fits is never clipped, so
// expanding it would only mint a no-op "Show less" into the tab order.
- onFocus={() => { if (isOverflowing) setExpanded(true); }}
+ // Measured live rather than read off `isOverflowing`: a descendant with
+ // `autoFocus` takes focus during commit, before the passive measure
+ // effect has run, so the state flag is still false on that first focus.
+ onFocus={() => { if (ref.current && overflows(ref.current)) setExpanded(true); }}
>
<div ref={innerRef}>{children}</div>
</div>
diff --git a/client/src/components/ui/CollapsibleText.test.jsx b/client/src/components/ui/CollapsibleText.test.jsx
index b2fa107c79..89597ff742 100644
--- a/client/src/components/ui/CollapsibleText.test.jsx
+++ b/client/src/components/ui/CollapsibleText.test.jsx
@@ -300,6 +300,29 @@ describe('CollapsibleText children (max-height) variant', () => {
expect(document.getElementById('c10')).not.toHaveClass('overflow-hidden');
});
+ it('measures overflow live on focus rather than trusting the state flag', () => {
+ // The focus handler must not read `isOverflowing`, which a passive effect
+ // populates after commit. A descendant with `autoFocus` takes focus during
+ // the commit phase — before that effect has ever run — so the flag is still
+ // a stale `false` and the focused control is stranded inside the clipped,
+ // scrolled region. Simulated here by letting the element start out fitting
+ // and become overflowing with no re-measure in between.
+ const spy = forceOverflow();
+ spy.mockReturnValue(0);
+ render(
+ <CollapsibleText id="c12">
+ <a href="/r">buried link</a>
+ </CollapsibleText>
+ );
+ expect(screen.queryByRole('button')).not.toBeInTheDocument();
+
+ spy.mockReturnValue(500);
+ fireEvent.focus(screen.getByRole('link', { name: 'buried link' }));
+
+ expect(screen.getByRole('button', { name: /Show less/ })).toHaveAttribute('aria-expanded', 'true');
+ expect(document.getElementById('c12')).not.toHaveClass('overflow-hidden');
+ });
+
it('leaves fitting children alone when focus lands inside them', () => {
// Nothing is clipped, so there is nothing to reveal — expanding here would
// only mint a no-op "Show less" button into the tab order.