The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 15:45 UTC
fix(web): composer body ref stops re-attaching on every render (#25409)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 26, 2026 at 01:42 UTC
e1c750e7bd3eabe85e94a0052100638f77dbedf9
2 files changed
+9
-18
apps/web/src/components/chat/ChatComposer.tsx
+2
-9
@@ -1096,7 +1096,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
1096
null,
1097
);
1098
const [composerMenuAnchor, setComposerMenuAnchor] = useState<HTMLDivElement | null>(null);
1099
- const [hasWrappedPrompt, observeWrappedPrompt] = useComposerMultilinePrompt();
1099
+ const hasWrappedPrompt = useComposerMultilinePrompt(composerMenuAnchor);
1100
const hasMultilinePrompt = prompt.includes("\n") || hasWrappedPrompt;
1101
const [isTasksDrawerOpen, setIsTasksDrawerOpen] = useState(false);
1102
// A pending question stays expanded: its card moves into the banner dock,
@@ -3652,14 +3652,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
3652
) : null}
3653
3654
<div
3655
- ref={(node) => {
3656
- setComposerMenuAnchor(node);
3657
- const stopObserving = observeWrappedPrompt(node);
3658
- return () => {
3659
- setComposerMenuAnchor(null);
3660
- stopObserving?.();
3661
- };
3662
- }}
3655
+ ref={setComposerMenuAnchor}
3656
data-chat-composer-body="true"
3657
className={cn(
3658
"relative px-3 pb-2 sm:px-4",
apps/web/src/components/chat/useComposerMultilinePrompt.ts
+7
-9
@@ -1,4 +1,4 @@
1
-import { useState } from "react";
1
+import { useLayoutEffect, useState } from "react";
2
import { observeResize } from "../../lib/observeResize";
3
4
function measureComposerMultilinePrompt(body: HTMLElement): boolean | null {
@@ -19,13 +19,10 @@ function measureComposerMultilinePrompt(body: HTMLElement): boolean | null {
19
return bounds.height > lineHeight + 1 || bounds.width > expandedWidth + 1;
20
}
21
22
-/** Whether the prompt wraps, and the ref callback that measures it on the composer body. */
23
-export function useComposerMultilinePrompt(): readonly [
24
- boolean,
25
- (body: HTMLElement | null) => (() => void) | undefined,
26
-] {
22
+export function useComposerMultilinePrompt(body: HTMLElement | null): boolean {
23
const [isMultiline, setIsMultiline] = useState(false);
28
- const observeBody = (body: HTMLElement | null) => {
24
+
25
+ useLayoutEffect(() => {
26
if (!body) return;
27
const measure = () => {
28
const next = measureComposerMultilinePrompt(body);
@@ -40,6 +37,7 @@ export function useComposerMultilinePrompt(): readonly [
37
stopObserving();
38
mutationObserver.disconnect();
39
};
43
- };
44
- return [isMultiline, observeBody] as const;
40
+ }, [body]);
41
+
42
+ return isMultiline;
43
}