Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { VideoAttachmentProps } from '@rocket.chat/core-typings';
import { Box, MessageGenericPreview } from '@rocket.chat/fuselage';
import { useMediaUrl } from '@rocket.chat/ui-contexts';
import { useMemo } from 'react';
import { useMemo, useState } from 'react';

import { useReloadOnError } from './hooks/useReloadOnError';
import { userAgentMIMETypeFallback } from '../../../../../lib/utils/userAgentMIMETypeFallback';
Expand All @@ -23,13 +23,24 @@ const VideoAttachment = ({
const getURL = useMediaUrl();
const src = useMemo(() => getURL(url), [getURL, url]);
const { mediaRef } = useReloadOnError(src, 'video');
const [lockedHeight, setLockedHeight] = useState<number | undefined>();

return (
<>
{descriptionMd ? <MessageContentBody md={descriptionMd} /> : <MarkdownText parseEmoji content={description} />}
<MessageCollapsible title={title} hasDownload={hasDownload} link={getURL(link || url)} size={size} isCollapsed={collapsed}>
<MessageGenericPreview style={{ maxWidth: 368, width: '100%' }}>
<Box is='video' controls preload='metadata' ref={mediaRef}>
<MessageGenericPreview style={{ maxWidth: 368, width: '100%', minHeight: lockedHeight }}>
<Box
is='video'
minHeight={80}
controls
preload='metadata'
ref={mediaRef}
onLoadedMetadata={(event) => {
const video = event.currentTarget as HTMLVideoElement;
setLockedHeight(video.parentElement?.offsetHeight);

@juliajforesti juliajforesti Jun 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this too weak? if this structure changes, the locator no longer points to where we are expecting...
maybe add ref to the element we want to track the size and change its height directly through the ref?

}}
>
Comment on lines +32 to +43

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for useState this way:

Suggested change
<MessageGenericPreview style={{ maxWidth: 368, width: '100%', minHeight: lockedHeight }}>
<Box
is='video'
minHeight={80}
controls
preload='metadata'
ref={mediaRef}
onLoadedMetadata={(event) => {
const video = event.currentTarget as HTMLVideoElement;
setLockedHeight(video.parentElement?.offsetHeight);
}}
>
<MessageGenericPreview ref={previewRef} style={{ maxWidth: 368, width: '100%' }}>
<Box
is='video'
minHeight={80}
controls
preload='metadata'
ref={mediaRef}
onLoadedMetadata={() => {
if (previewRef.current) {
previewRef.current.style.minHeight = `${previewRef.current.offsetHeight}px`;
}
}}
>

<source src={getURL(url)} type={userAgentMIMETypeFallback(type)} />
</Box>
</MessageGenericPreview>
Expand Down
Loading