Skip to content

Commit 92397c1

Browse files
authored
Merge pull request #1536 from session-foundation/fix/ses-4242/message_read_more_with_changing_screen_size
fix: re-trigger message read more calculation on size change
2 parents fd295e0 + 386dd4d commit 92397c1

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

ts/components/conversation/message/message-content/MessageBubble.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ export function MessageBubble({ children }: { children: ReactNode }) {
8989
setExpanded(true);
9090
};
9191

92+
/**
93+
* Used to re-trigger the "Read More" layout effect when the message content changes scroll height.
94+
* This is required to handle window resizing, zooming, and font size changes.
95+
*/
96+
const scrollHeight = msgBubbleRef.current?.firstElementChild?.scrollHeight;
97+
9298
useLayoutEffect(
9399
() => {
94100
const el = msgBubbleRef?.current?.firstElementChild;
@@ -118,9 +124,12 @@ export function MessageBubble({ children }: { children: ReactNode }) {
118124

119125
setShowReadMore(overflowsLines);
120126
},
121-
// Note: no need to provide a dependency here (and if we provide children, this hook reruns every second for every messages).
122-
// The only dependency is msgBubbleRef, but as it's a ref it's unneeded
123-
[]
127+
/**
128+
* Note: Don't provide children as a dependency, if you do this hook reruns every second for every
129+
* message. The only dependencies are the scrollHeight (to handle window resizing) and msgBubbleRef,
130+
* but it's a ref so is not needed.
131+
*/
132+
[scrollHeight]
124133
);
125134

126135
return (

0 commit comments

Comments
 (0)