@@ -41,7 +41,6 @@ const ReadMoreButton = styled.button`
41
41
export function MessageBubble ( { children } : { children : ReactNode } ) {
42
42
const [ expanded , setExpanded ] = useState ( false ) ;
43
43
const [ showReadMore , setShowReadMore ] = useState ( false ) ;
44
- const hiddenHeight = useRef < number > ( 0 ) ;
45
44
const msgBubbleRef = useRef < HTMLDivElement > ( null ) ;
46
45
47
46
const messagesContainerRef = useMessagesContainerRef ( ) ;
@@ -80,13 +79,11 @@ export function MessageBubble({ children }: { children: ReactNode }) {
80
79
81
80
const msgContainerBefore = messagesContainerRef . current ;
82
81
83
- if ( ! msgContainerBefore ) {
84
- return ;
85
- }
86
-
87
- const { scrollTop : scrollTopBefore , scrollHeight : scrollHeightBefore } = msgContainerBefore ;
82
+ if ( msgContainerBefore ) {
83
+ const { scrollTop : scrollTopBefore , scrollHeight : scrollHeightBefore } = msgContainerBefore ;
88
84
89
- scrollBefore . current = { scrollTop : scrollTopBefore , scrollHeight : scrollHeightBefore } ;
85
+ scrollBefore . current = { scrollTop : scrollTopBefore , scrollHeight : scrollHeightBefore } ;
86
+ }
90
87
91
88
// we cannot "show less", only show more
92
89
setExpanded ( true ) ;
@@ -119,8 +116,6 @@ export function MessageBubble({ children }: { children: ReactNode }) {
119
116
120
117
const overflowsLines = innerHeight > maxHeight ;
121
118
122
- hiddenHeight . current = innerHeight - maxHeight ;
123
-
124
119
setShowReadMore ( overflowsLines ) ;
125
120
} ,
126
121
// Note: no need to provide a dependency here (and if we provide children, this hook reruns every second for every messages).
0 commit comments