Skip to content

Commit cc93cc5

Browse files
revert(web): composer body ref goes back to the #25079 ref callback (#25412)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 91f47a1 commit cc93cc5

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
10961096
null,
10971097
);
10981098
const [composerMenuAnchor, setComposerMenuAnchor] = useState<HTMLDivElement | null>(null);
1099-
const hasWrappedPrompt = useComposerMultilinePrompt(composerMenuAnchor);
1099+
const [hasWrappedPrompt, observeWrappedPrompt] = useComposerMultilinePrompt();
11001100
const hasMultilinePrompt = prompt.includes("\n") || hasWrappedPrompt;
11011101
const [isTasksDrawerOpen, setIsTasksDrawerOpen] = useState(false);
11021102
// A pending question stays expanded: its card moves into the banner dock,
@@ -3652,7 +3652,14 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
36523652
) : null}
36533653

36543654
<div
3655-
ref={setComposerMenuAnchor}
3655+
ref={(node) => {
3656+
setComposerMenuAnchor(node);
3657+
const stopObserving = observeWrappedPrompt(node);
3658+
return () => {
3659+
setComposerMenuAnchor(null);
3660+
stopObserving?.();
3661+
};
3662+
}}
36563663
data-chat-composer-body="true"
36573664
className={cn(
36583665
"relative px-3 pb-2 sm:px-4",

‎apps/web/src/components/chat/useComposerMultilinePrompt.ts‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useLayoutEffect, useState } from "react";
1+
import { useState } from "react";
22
import { observeResize } from "../../lib/observeResize";
33

44
function measureComposerMultilinePrompt(body: HTMLElement): boolean | null {
@@ -19,10 +19,13 @@ function measureComposerMultilinePrompt(body: HTMLElement): boolean | null {
1919
return bounds.height > lineHeight + 1 || bounds.width > expandedWidth + 1;
2020
}
2121

22-
export function useComposerMultilinePrompt(body: HTMLElement | null): boolean {
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+
] {
2327
const [isMultiline, setIsMultiline] = useState(false);
24-
25-
useLayoutEffect(() => {
28+
const observeBody = (body: HTMLElement | null) => {
2629
if (!body) return;
2730
const measure = () => {
2831
const next = measureComposerMultilinePrompt(body);
@@ -37,7 +40,6 @@ export function useComposerMultilinePrompt(body: HTMLElement | null): boolean {
3740
stopObserving();
3841
mutationObserver.disconnect();
3942
};
40-
}, [body]);
41-
42-
return isMultiline;
43+
};
44+
return [isMultiline, observeBody] as const;
4345
}

0 commit comments

Comments
 (0)