File tree Expand file tree Collapse file tree
apps/web/src/components/chat Expand file tree Collapse file tree Original file line number Diff line number Diff 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" ,
Original file line number Diff line number Diff line change 1- import { useLayoutEffect , useState } from "react" ;
1+ import { useState } from "react" ;
22import { observeResize } from "../../lib/observeResize" ;
33
44function 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}
You can’t perform that action at this time.
0 commit comments