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): re-fit auto-size textarea on width changes

[._.]/ Adam Eivy9553f0e94c59
diff --git a/client/src/hooks/useAutoSizeTextarea.js b/client/src/hooks/useAutoSizeTextarea.js
index 5000af18ba..5f1f48e968 100644
--- a/client/src/hooks/useAutoSizeTextarea.js
+++ b/client/src/hooks/useAutoSizeTextarea.js
@@ -1,11 +1,13 @@
-import { useCallback, useLayoutEffect, useRef } from 'react';
+import { useCallback, useEffect, useLayoutEffect, useRef } from 'react';
/**
* Grow a <textarea> to fit its content so the field never scrolls or has to be
* hand-resized. Attach the returned `ref` to the textarea; the height is
- * recomputed before paint whenever `value` changes. `resize` is returned for
- * the rare case the content changes without `value` (e.g. a font/width reflow)
- * — call it from a ResizeObserver or after a programmatic mutation.
+ * recomputed before paint whenever `value` changes, AND whenever the element's
+ * width changes (responsive grid breakpoint, viewport resize) — a narrower box
+ * rewraps the text to more lines without `value` changing, which would
+ * otherwise clip the bottom behind `overflow-hidden`. `resize` is also returned
+ * for any other programmatic mutation the two triggers can't see.
*
* Set a floor with a `min-h-*` class on the textarea (CSS `min-height` floors
* the inline height this hook sets), and pair it with `resize-none` /
@@ -20,5 +22,21 @@ export default function useAutoSizeTextarea(value) {
el.style.height = `${el.scrollHeight}px`;
}, []);
useLayoutEffect(() => { resize(); }, [value, resize]);
+ // Re-fit on width changes only. Gating on width is essential: resize() mutates
+ // the element's height, which would otherwise re-trigger the observer into a
+ // feedback loop.
+ useEffect(() => {
+ const el = ref.current;
+ if (!el || typeof ResizeObserver === 'undefined') return undefined;
+ let lastWidth = el.clientWidth;
+ const ro = new ResizeObserver(() => {
+ if (el.clientWidth !== lastWidth) {
+ lastWidth = el.clientWidth;
+ resize();
+ }
+ });
+ ro.observe(el);
+ return () => ro.disconnect();
+ }, [resize]);
return [ref, resize];
}