Skip to content

Commit d9336bb

Browse files
authored
Update chat-message-content.tsx trial-debug v4
1 parent db24213 commit d9336bb

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed
Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
1-
import React, { ForwardRefRenderFunction, useEffect } from "react";
2-
1+
import React, { useEffect, useRef, forwardRef } from "react";
2+
33
interface ChatMessageContentAreaProps {
44
children?: React.ReactNode;
55
}
6-
7-
const ChatMessageContentArea: ForwardRefRenderFunction<
6+
7+
const ChatMessageContentArea: React.ForwardRefRenderFunction<
88
HTMLDivElement,
99
ChatMessageContentAreaProps
1010
> = (props, ref) => {
11+
const internalRef = useRef<HTMLDivElement>(null);
12+
const combinedRef = ref || internalRef;
13+
1114
useEffect(() => {
12-
// Check if ref.current is not null
13-
if (ref.current) {
14-
const links = ref.current.querySelectorAll('a'); // Select all anchor tags in the current ref
15+
if (combinedRef && combinedRef.current) {
16+
const links = combinedRef.current.querySelectorAll("a");
1517
links.forEach(link => {
16-
link.setAttribute('target', '_blank'); // Open in new tab
17-
link.setAttribute('rel', 'noopener noreferrer'); // Security measure
18+
link.setAttribute("target", "_blank");
19+
link.setAttribute("rel", "noopener noreferrer");
1820
});
1921
}
20-
}, [props.children]); // Run effect when children change
21-
22+
}, [props.children]);
23+
2224
return (
23-
<div
24-
ref={ref}
25+
<div
26+
ref={combinedRef}
2527
className="container max-w-3xl relative min-h-screen pb-[240px] pt-16 flex flex-col gap-16"
26-
>
28+
>
2729
{props.children}
28-
</div>
30+
</div>
2931
);
3032
};
31-
32-
export default React.forwardRef(ChatMessageContentArea);
33+
34+
export default forwardRef(ChatMessageContentArea);

0 commit comments

Comments
 (0)